Add and use isArray() and isString() methods to Core Loader.#98
Open
kaladay wants to merge 3 commits intodevelopmentfrom
Open
Add and use isArray() and isString() methods to Core Loader.#98kaladay wants to merge 3 commits intodevelopmentfrom
kaladay wants to merge 3 commits intodevelopmentfrom
Conversation
These allow for cleaner existence checks on arrays without PHP warnings or problems. An `isset()` must be called to safely perform something like `is_string()` on a value at some array index. Adding an `isset()` inline can make the code messier so move this logic out into two methods: 1. `isArray()`. 2. `isString()`. Update all code in `CoreLoader` class to utilize these methods.
I am either using it incorrectly or I am misunderstanding something about it. Avoid using it until I can identify how to use it correctly.
qtamu
approved these changes
Aug 4, 2025
rmathew1011
approved these changes
Aug 4, 2025
jsavell
reviewed
Aug 14, 2025
Member
jsavell
left a comment
There was a problem hiding this comment.
I think it makes sense to add a hasConfiguration($property, $type=string(default)|array|bool|integer|etc) or similarly named method to the CoreFunctions:
https://github.com/TAMULib/Pipit/blob/master/src/Pipit/Lib/CoreFunctions.php
And provide a wrapper method via CoreObject:
https://github.com/TAMULib/Pipit/blob/master/src/Pipit/Classes/CoreObject.php
That will provide a standardized means of checking the config values to both the library and clients.
…selves. I considered implementing the logic within the `CoreFunctions` but opted to keep all of the verification logic self-contained within the enumerations themselves. This allows for the reduction of the extra type parameter. The enumeration knows its own type and can perform the appropriate check. This is designed to ensure that all appropriate checks are performed in order to guarantee that a boolean is returned. The caller need only perform the `is()` or the `in()` check using the appropriate configuration type. Only the most simplistic types are chosen. If additional php `is_*()` types are needed, then enumerations may be added. The special `NULL` supporting types are done to reduce the needed checks should something care to check if the type is either NULL or a given type. This doesn't increase the code complexity much at all and the use should reduce code complexity. The `NULL` checks need to be performed anyway. A specific type `ANY` can be used to test if a configuration type exists as is NULL. The `in()` method allows for array key existence checks and then a type check on some child property. This should allow for shallow array value type checks. The non-`$config` based `isset()` and `is_string()` checks are reverted to previous behavior. This should allow for the configuration checks to be performed anywhere without warnings or problems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Provide PHP enumerations that can perform the appropriate checks themselves.
I considered implementing the logic within the
CoreFunctionsbut opted to keep all of the verification logic self-contained within the enumerations themselves.This allows for the reduction of the extra type parameter.
The enumeration knows its own type and can perform the appropriate check.
This is designed to ensure that all appropriate checks are performed in order to guarantee that a boolean is returned.
The caller need only perform the
is()or thein()check using the appropriate configuration type.Only the most simplistic types are chosen.
If additional php
is_*()types are needed, then enumerations may be added.The special
NULLsupporting types are done to reduce the needed checks should something care to check if the type is either NULL or a given type.This doesn't increase the code complexity much at all and the use should reduce code complexity.
The
NULLchecks need to be performed anyway.A specific type
ANYcan be used to test if a configuration type exists as is NULL.The
in()method allows for array key existence checks and then a type check on some child property.This should allow for shallow array value type checks.
The non-
$configbasedisset()andis_string()checks are reverted to previous behavior.This should allow for the configuration checks to be performed anywhere without warnings or problems.
Original Description and Design
These allow for cleaner existence checks on arrays without PHP warnings or problems.
An
isset()must be called to safely perform something likeis_string()on a value at some array index.Adding an
isset()inline can make the code messier so move this logic out into two methods:isArray().isString().Update all code in
CoreLoaderclass to utilize these methods.This approach was changed to the enum functions approach based on this comment: