2
2
3
3
declare (strict_types=1 );
4
4
5
- /*
6
- * This file is part of the JsonSchema package.
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
5
namespace JsonSchema \Constraints ;
13
6
7
+ use const JSON_ERROR_NONE ;
14
8
use JsonSchema \ConstraintError ;
15
9
use JsonSchema \Entity \JsonPointer ;
16
10
use JsonSchema \Exception \InvalidArgumentException ;
@@ -50,8 +44,8 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null,
50
44
$ name = $ constraint ->getValue ();
51
45
$ error = [
52
46
'property ' => $ this ->convertJsonPointerIntoPropertyPath ($ path ?: new JsonPointer ('' )),
53
- 'pointer ' => ltrim (strval ($ path ?: new JsonPointer ('' )), '# ' ),
54
- 'message ' => ucfirst (vsprintf ($ message , array_map (function ($ val ) {
47
+ 'pointer ' => ltrim (( string ) ($ path ?: new JsonPointer ('' )), '# ' ),
48
+ 'message ' => ucfirst (vsprintf ($ message , array_map (static function ($ val ) {
55
49
if (is_scalar ($ val )) {
56
50
return is_bool ($ val ) ? var_export ($ val , true ) : $ val ;
57
51
}
@@ -78,7 +72,7 @@ public function addErrors(array $errors): void
78
72
if ($ errors ) {
79
73
$ this ->errors = array_merge ($ this ->errors , $ errors );
80
74
$ errorMask = &$ this ->errorMask ;
81
- array_walk ($ errors , function ($ error ) use (&$ errorMask ) {
75
+ array_walk ($ errors , static function ($ error ) use (&$ errorMask ) {
82
76
if (isset ($ error ['context ' ])) {
83
77
$ errorMask |= $ error ['context ' ];
84
78
}
@@ -95,10 +89,8 @@ public function getErrors(int $errorContext = Validator::ERROR_ALL): array
95
89
return $ this ->errors ;
96
90
}
97
91
98
- return array_filter ($ this ->errors , function ($ error ) use ($ errorContext ) {
99
- if ($ errorContext & $ error ['context ' ]) {
100
- return true ;
101
- }
92
+ return array_filter ($ this ->errors , static function ($ error ) use ($ errorContext ) {
93
+ return (bool ) ($ errorContext & $ error ['context ' ]);
102
94
});
103
95
}
104
96
@@ -120,7 +112,7 @@ public function isValid(): bool
120
112
}
121
113
122
114
/**
123
- * Clears any reported errors. Should be used between
115
+ * Clears any reported errors. Should be used between
124
116
* multiple validation checks.
125
117
*/
126
118
public function reset (): void
@@ -145,15 +137,15 @@ public function getErrorMask(): int
145
137
public static function arrayToObjectRecursive (array $ array ): object
146
138
{
147
139
$ json = json_encode ($ array );
148
- if (json_last_error () !== \ JSON_ERROR_NONE ) {
140
+ if (json_last_error () !== JSON_ERROR_NONE ) {
149
141
$ message = 'Unable to encode schema array as JSON ' ;
150
142
if (function_exists ('json_last_error_msg ' )) {
151
143
$ message .= ': ' . json_last_error_msg ();
152
144
}
153
145
throw new InvalidArgumentException ($ message );
154
146
}
155
147
156
- return (object ) json_decode ($ json );
148
+ return (object ) json_decode ($ json, false );
157
149
}
158
150
159
151
/**
@@ -164,13 +156,10 @@ public static function jsonPatternToPhpRegex(string $pattern): string
164
156
return '~ ' . str_replace ('~ ' , '\\~ ' , $ pattern ) . '~u ' ;
165
157
}
166
158
167
- /**
168
- * @return string property path
169
- */
170
159
protected function convertJsonPointerIntoPropertyPath (JsonPointer $ pointer ): string
171
160
{
172
161
$ result = array_map (
173
- function ($ path ) {
162
+ static function ($ path ) {
174
163
return sprintf (is_numeric ($ path ) ? '[%d] ' : '.%s ' , $ path );
175
164
},
176
165
$ pointer ->getPropertyPaths ()
0 commit comments