@@ -40,11 +40,23 @@ public function testDirectory($dir) {
4040 $ jsonData = file_get_contents ($ dir . "/info.json " );
4141 $ data = json_decode ($ jsonData , true );
4242
43- if ($ data ["name " ] == "" ) {
43+ if ($ data === null && json_last_error () !== JSON_ERROR_NONE ) {
44+ $ errors [] = "Failed to parse info.json: " . json_last_error_msg ();
45+ $ this ->errors [$ dir ] = $ errors ;
46+ return ;
47+ }
48+
49+ if (!is_array ($ data )) {
50+ $ errors [] = "info.json does not contain a valid object! " ;
51+ $ this ->errors [$ dir ] = $ errors ;
52+ return ;
53+ }
54+
55+ if (!isset ($ data ["name " ]) || $ data ["name " ] == "" ) {
4456 $ errors [] = "No name was entered! " ;
4557 }
4658
47- $ identifier = $ data ["identifier " ];
59+ $ identifier = $ data ["identifier " ] ?? "" ;
4860 if ($ identifier == "" ) {
4961 $ errors [] = "No identifier was entered! " ;
5062 } elseif (preg_match ('/[^a-z0-9\-]/ ' , $ identifier )) {
@@ -55,18 +67,18 @@ public function testDirectory($dir) {
5567 $ errors [] = "Identifier and directory name do not match! " ;
5668 }
5769
58- if ($ data ["description " ] == "" ) {
70+ if (! isset ( $ data [ " description " ]) || $ data ["description " ] == "" ) {
5971 $ errors [] = "No description was entered! " ;
6072 }
6173
62- $ script = $ data ["script " ];
74+ $ script = $ data ["script " ] ?? "" ;
6375 if ($ script == "" ) {
6476 $ errors [] = "No script was entered! " ;
6577 } elseif (!file_exists ($ dir . "/ " . $ script )) {
6678 $ errors [] = "Script ' $ script' doesn't exist! " ;
6779 }
6880
69- if ($ data ["version " ] == "" ) {
81+ if (! isset ( $ data [ " version " ]) || $ data ["version " ] == "" ) {
7082 $ errors [] = "No version was entered! " ;
7183 }
7284
0 commit comments