@@ -26,28 +26,24 @@ public function readFile(string $filename, bool $isArray = null): ?array
2626 $ fileFormat = end ($ fileNameParts );
2727 if ($ fileFormat === 'json ' ) {
2828 $ handle = fopen ($ filename , "r " );
29- $ result = json_decode (fread ($ handle , self ::MAX_FILE_SIZE ), $ isArray );
29+ $ jsonVariables = json_decode (fread ($ handle , self ::MAX_FILE_SIZE ), $ isArray );
3030 fclose ($ handle );
31- $ type = gettype ($ result );
31+ $ type = gettype ($ jsonVariables );
3232 if ($ type === 'object ' ) {
33- return get_object_vars ($ result );
33+ $ fileContentArray = get_object_vars ($ jsonVariables );
3434 } elseif ($ type === 'array ' ) {
35- return $ result ;
35+ $ fileContentArray = $ jsonVariables ;
3636 }
3737 } elseif ($ fileFormat === 'yaml ' || $ fileFormat === 'yml ' ) {
3838 $ handle = fopen ($ filename , "r " );
39- $ result = Yaml::parse (fread ($ handle , self ::MAX_FILE_SIZE ), Yaml::PARSE_OBJECT_FOR_MAP );
39+ $ yamlVariables = Yaml::parse (fread ($ handle , self ::MAX_FILE_SIZE ), Yaml::PARSE_OBJECT_FOR_MAP );
4040 fclose ($ handle );
41- $ type = gettype ($ result );
42- if ($ type === 'object ' ) {
43- return get_object_vars ($ result );
44- } elseif ($ type === 'array ' ) {
45- return $ result ;
46- }
41+ $ fileContentArray = get_object_vars ($ yamlVariables );
4742 } else {
48- throw new \Exception ("Unknown files format: \n" .
49- "use .json, .yaml (.yml) enstead \n" );
43+ throw new DifferException ("unknown files format: use json, yaml (yml) enstead \n" );
5044 }
45+
46+ return $ fileContentArray ;
5147 } else {
5248 return null ;
5349 }
0 commit comments