Commit b209eb8
committed
refactor: update BaseConstraint.php to PHP 7.2 language level (#826)
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.1 parent 95e5d61 commit b209eb8
2 files changed
+11
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 5 | | |
13 | 6 | | |
| 7 | + | |
14 | 8 | | |
15 | 9 | | |
16 | 10 | | |
| |||
50 | 44 | | |
51 | 45 | | |
52 | 46 | | |
53 | | - | |
54 | | - | |
| 47 | + | |
| 48 | + | |
55 | 49 | | |
56 | 50 | | |
57 | 51 | | |
| |||
78 | 72 | | |
79 | 73 | | |
80 | 74 | | |
81 | | - | |
| 75 | + | |
82 | 76 | | |
83 | 77 | | |
84 | 78 | | |
| |||
95 | 89 | | |
96 | 90 | | |
97 | 91 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 92 | + | |
| 93 | + | |
102 | 94 | | |
103 | 95 | | |
104 | 96 | | |
| |||
120 | 112 | | |
121 | 113 | | |
122 | 114 | | |
123 | | - | |
| 115 | + | |
124 | 116 | | |
125 | 117 | | |
126 | 118 | | |
| |||
145 | 137 | | |
146 | 138 | | |
147 | 139 | | |
148 | | - | |
| 140 | + | |
149 | 141 | | |
150 | 142 | | |
151 | 143 | | |
152 | 144 | | |
153 | 145 | | |
154 | 146 | | |
155 | 147 | | |
156 | | - | |
| 148 | + | |
157 | 149 | | |
158 | 150 | | |
159 | 151 | | |
| |||
164 | 156 | | |
165 | 157 | | |
166 | 158 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | 159 | | |
171 | 160 | | |
172 | 161 | | |
173 | | - | |
| 162 | + | |
174 | 163 | | |
175 | 164 | | |
176 | 165 | | |
| |||
0 commit comments