refactor: update BaseConstraint.php to PHP 7.2 language level#826
Merged
DannyvdSluijs merged 1 commit intomasterfrom May 7, 2025
Merged
refactor: update BaseConstraint.php to PHP 7.2 language level#826DannyvdSluijs merged 1 commit intomasterfrom
DannyvdSluijs merged 1 commit intomasterfrom
Conversation
846cbf8 to
2b6058b
Compare
DannyvdSluijs
added a commit
that referenced
this pull request
May 7, 2025
This pull request refactors the `BaseConstraint` class in the `JsonSchema` package to improve code readability, enforce immutability, and align with modern PHP practices. The changes include replacing anonymous functions with static closures, updating type casting, and removing outdated comments. ### Code modernization and immutability: * Replaced anonymous functions with `static` closures in methods like `addError`, `addErrors`, and `convertJsonPointerIntoPropertyPath` to enforce immutability and improve performance. [[1]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L53-R48) [[2]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L81-R75) [[3]](diffhunk://#diff-05cd63f6b003f185a215e10402525e33d94466ec4d83a685c5a6ccd1befcf921L167-R162) * Updated type casting for better readability and adherence to modern PHP conventions, e.g., `(string)` instead of `strval`. ### Code readability and cleanup: * Removed outdated docblock comments and unnecessary annotations, such as the `@return` tag in `convertJsonPointerIntoPropertyPath`. * Replaced `\JSON_ERROR_NONE` with the `JSON_ERROR_NONE` constant for consistency with the `use` statement. ### Other improvements: * Adjusted the `json_decode` call to explicitly set the `associative` parameter to `false` for clarity.
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.
This pull request refactors the
BaseConstraintclass in theJsonSchemapackage to improve code readability, enforce immutability, and align with modern PHP practices. The changes include replacing anonymous functions with static closures, updating type casting, and removing outdated comments.Code modernization and immutability:
staticclosures in methods likeaddError,addErrors, andconvertJsonPointerIntoPropertyPathto enforce immutability and improve performance. [1] [2] [3](string)instead ofstrval.Code readability and cleanup:
@returntag inconvertJsonPointerIntoPropertyPath.\JSON_ERROR_NONEwith theJSON_ERROR_NONEconstant for consistency with theusestatement.Other improvements:
json_decodecall to explicitly set theassociativeparameter tofalsefor clarity.