File tree 2 files changed +14
-12
lines changed
2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -84,27 +84,21 @@ public function getJsonData()
84
84
public function getImageSetHeader ()
85
85
{
86
86
$ arr = $ this ->getJsonData ();
87
- if (array_key_exists ('image-set-header ' , $ arr ))
88
- {
87
+ if (is_array ($ arr ) && array_key_exists ('image-set-header ' , $ arr )) {
89
88
return $ arr ['image-set-header ' ];
90
89
}
91
- else
92
- {
93
- return [];
94
- }
90
+
91
+ return [];
95
92
}
96
93
97
94
public function getImageSetItems ()
98
95
{
99
96
$ arr = $ this ->getJsonData ();
100
- if (array_key_exists ('image-set-items ' , $ arr ))
101
- {
97
+ if (is_array ($ arr ) && array_key_exists ('image-set-items ' , $ arr )) {
102
98
return $ arr ['image-set-items ' ];
103
99
}
104
- else
105
- {
106
- return [];
107
- }
100
+
101
+ return [];
108
102
}
109
103
110
104
public function getIfdoVersion (): String
Original file line number Diff line number Diff line change @@ -35,4 +35,12 @@ public function testStrictMode()
35
35
$ this ->expectException (\Exception::class);
36
36
Ifdo::fromString ('{"some": "json"} ' , true );
37
37
}
38
+
39
+ public function testInvalidJson ()
40
+ {
41
+ $ obj = Ifdo::fromString ('{"some": "json",} ' );
42
+ $ this ->assertSame (null , $ obj ->getJsonData ());
43
+ $ this ->assertSame ([], $ obj ->getImageSetHeader ());
44
+ $ this ->assertSame ([], $ obj ->getImageSetItems ());
45
+ }
38
46
}
You can’t perform that action at this time.
0 commit comments