Skip to content

Conversation

@kaladay
Copy link
Contributor

@kaladay kaladay commented Jul 28, 2025

Provide PHP enumerations that can perform the appropriate checks themselves.

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.

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 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:

  • isArray().
  • isString().

Update all code in CoreLoader class to utilize these methods.

This approach was changed to the enum functions approach based on this comment:

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.
@kaladay kaladay requested a review from jsavell July 28, 2025 19:01
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.
@kaladay kaladay requested a review from a team August 4, 2025 14:24
Copy link
Member

@jsavell jsavell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants