This repository was archived by the owner on Feb 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed
Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ private function __construct() {}
2323 * @throws \InvalidArgumentException
2424 */
2525 static function normalizePath ($ path ) {
26- if (empty ($ path )) {
27- throw new \InvalidArgumentException ('Empty JSON path! ' );
26+ if (empty ($ path ) || ! is_string ( $ path ) ) {
27+ throw new \InvalidArgumentException ('JSON path must be a non-empty string ! ' );
2828 }
2929 if ($ path === '$ ' ) {
3030 return $ path ;
Original file line number Diff line number Diff line change 33
44class StringUtils {
55
6- public static function startsWith ($ haystack , $ needle ) {
7- return empty ($ needle ) || strrpos ($ haystack , $ needle , -strlen ($ haystack )) !== false ;
6+ public static function startsWith ($ string , $ prefix ) {
7+ return empty ($ prefix ) || strrpos ($ string , $ prefix , -strlen ($ string )) !== false ;
88 }
99
10- public static function endsWith ($ haystack , $ needle ) {
11- if (empty ($ needle )) {
10+ public static function endsWith ($ string , $ suffix ) {
11+ if (empty ($ suffix )) {
1212 return true ;
1313 }
14- $ diff = strlen ($ haystack ) - strlen ($ needle );
15- return $ diff >= 0 && strpos ($ haystack , $ needle , $ diff ) !== false ;
14+ $ diff = strlen ($ string ) - strlen ($ suffix );
15+ return $ diff >= 0 && strpos ($ string , $ suffix , $ diff ) !== false ;
1616 }
1717}
Original file line number Diff line number Diff line change @@ -39,7 +39,20 @@ public function testNormalizePath_ShouldThrowInvalidArgumentException_WhenJsonPa
3939
4040 // THEN
4141 $ this ->expectException (\InvalidArgumentException::class);
42- $ this ->expectExceptionMessage ('Empty JSON path! ' );
42+ $ this ->expectExceptionMessage ('JSON path must be a non-empty string! ' );
43+
44+ // WHEN
45+ JsonPath::normalizePath ($ jsonPath );
46+ }
47+
48+ public function testNormalizePath_ShouldThrowInvalidArgumentException_WhenJsonPathIsNotAString () {
49+
50+ // GIVEN
51+ $ jsonPath = [];
52+
53+ // THEN
54+ $ this ->expectException (\InvalidArgumentException::class);
55+ $ this ->expectExceptionMessage ('JSON path must be a non-empty string! ' );
4356
4457 // WHEN
4558 JsonPath::normalizePath ($ jsonPath );
@@ -187,7 +200,7 @@ public function testGetParentPath_ShouldThrowInvalidArgumentException_WhenJsonPa
187200
188201 // THEN
189202 $ this ->expectException (\InvalidArgumentException::class);
190- $ this ->expectExceptionMessage ('Empty JSON path! ' );
203+ $ this ->expectExceptionMessage ('JSON path must be a non-empty string ! ' );
191204
192205 // WHEN
193206 JsonPath::getParentPath ($ jsonPath );
@@ -200,7 +213,7 @@ public function testGetElementKey_ShouldThrowInvalidArgumentException_WhenJsonPa
200213
201214 // THEN
202215 $ this ->expectException (\InvalidArgumentException::class);
203- $ this ->expectExceptionMessage ('Empty JSON path! ' );
216+ $ this ->expectExceptionMessage ('JSON path must be a non-empty string ! ' );
204217
205218 // WHEN
206219 JsonPath::getElementKey ($ jsonPath );
You can’t perform that action at this time.
0 commit comments