Git viewing holonet/common / 9c10f66f5431a98fad62626427c0fef23acd1765


Filter

9c10f66f5431a98fad62626427c0fef23acd1765

Matthias Lantsch(4 years, 5 months ago)

Update ConfigReader to not attempt to read nonexisting files

Browse Files
  • Changed file .php_cs.dist
    diff --git a/600a29fc56b2217d5855bbc8566855361b4b02bb b/713f7fe79daefea1e51303689296aea51f0b7e88
    index 600a29f..713f7fe 100644
    --- a/600a29fc56b2217d5855bbc8566855361b4b02bb
    +++ b/713f7fe79daefea1e51303689296aea51f0b7e88
    @@ -144,7 +144,7 @@ return PhpCsFixer\Config::create()
             'phpdoc_types' => true,
             'phpdoc_types_order' => ['null_adjustment'=>'always_last'],
             'phpdoc_var_annotation_correct_order' => true,
    -        'phpdoc_var_without_name' => true,
    +        'phpdoc_var_without_name' => false,
             'pow_to_exponentiation' => true,
             'random_api_migration' => true,
             'return_assignment' => true,
  • Removed file composer.lock
  • Changed file ConfigReader.php
    diff --git a/b94178af83cf794faa6de238380d9a6453644f4b b/b93ac542470be5939ecae56729981e85a4bd713a
    index b94178a..b93ac54 100644
    --- a/b94178af83cf794faa6de238380d9a6453644f4b
    +++ b/b93ac542470be5939ecae56729981e85a4bd713a
    @@ -23,7 +23,7 @@ use holonet\common\config\exception\ConfigReaderException;
      */
     class ConfigReader {
     	/**
    -	 * @var array An array with parser classes / active cached parsers
    +	 * @var array $parsers An array with parser classes / active cached parsers
     	 */
     	public $parsers = array(
     		'ini' => IniConfigParser::class,
    @@ -32,12 +32,13 @@ class ConfigReader {
     	);
    
     	/**
    -	 * @var Registry Collection keeping the data while parsing
    +	 * @var Registry $registry Collection keeping the data while parsing
     	 */
     	public $registry;
    
     	/**
     	 * Initialises the internal Registry collection for the data or uses the given one.
    +	 * @param Registry|null $registry Registry collection to write to
     	 */
     	public function __construct(Registry $registry = null) {
     		if ($registry !== null) {
    @@ -62,10 +63,16 @@ class ConfigReader {
     			foreach ($input as $file) {
     				$this->read($file, $type);
     			}
    -		} elseif (is_dir($input)) {
    -			$this->readDir($input, $type);
     		} else {
    -			$this->readFile($input, $type);
    +			if (!file_exists($input)) {
    +				throw new ConfigReaderException("File path '{$input}' does not exist");
    +			}
    +
    +			if (is_dir($input)) {
    +				$this->readDir($input, $type);
    +			} else {
    +				$this->readFile($input, $type);
    +			}
     		}
     	}
    
    @@ -75,7 +82,6 @@ class ConfigReader {
     	 */
     	private function readDir(string $filename, string $type = null): void {
     		if ($dh = opendir($filename)) {
    -			$ret = array();
     			while (($file = readdir($dh)) !== false) {
     				$this->readFile($filename, $type);
     			}
  • Changed file ConfigReaderTest.php
    diff --git a/86c21d7c6f162553a4640e9be6224e391d4f8b47 b/aa8548fc1e86ca46372288fa69327649099edac1
    index 86c21d7..aa8548f 100644
    --- a/86c21d7c6f162553a4640e9be6224e391d4f8b47
    +++ b/aa8548fc1e86ca46372288fa69327649099edac1
    @@ -46,7 +46,7 @@ class ConfigReaderTest extends TestCase {
     		} catch (\Exception $e) {
     			$msg = $e->getMessage();
     		}
    -		static::assertSame("File 'iSurelyDon'tExist.ini' cannot be found/read", $msg);
    +		static::assertSame("File path 'iSurelyDon'tExist.ini' does not exist", $msg);
     	}
    
     	/**
    @@ -66,7 +66,7 @@ class ConfigReaderTest extends TestCase {
    
     	public function testUnknownType(): void {
     		$configreader = new ConfigReader();
    -		$filename = 'config.blablabla';
    +		$filename = __DIR__.'/data/configfile.blablabla';
    
     		try {
     			$configreader->read($filename);
  • Created new file configfile.blablabla