From e828133fc7eb92773544a0f74974caeed39a875c Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Tue, 16 Sep 2014 22:51:35 -0300 Subject: [PATCH] Replaced array_walk() with foreach(). Add a more detailed exception message when a top-level key is missing. Fixed style in README.md. --- Processor.php | 8 ++++---- README.md | 2 +- Tests/ProcessorTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Processor.php b/Processor.php index 4276894..7c0b66c 100644 --- a/Processor.php +++ b/Processor.php @@ -33,7 +33,7 @@ public function processFile(array $config) // Find the expected params $expectedValues = $yamlParser->parse(file_get_contents($config['dist-file'])); if (!isset($expectedValues[$parameterKey])) { - throw new \InvalidArgumentException('The dist file seems invalid.'); + throw new \InvalidArgumentException(sprintf('The top-level key %s is missing.', $parameterKey)); } $expectedParams = (array) $expectedValues[$parameterKey]; @@ -104,9 +104,9 @@ private function processParams(array $config, array $expectedParams, array $actu if (!empty($config['env-map'])) { // Hydrate env-map from dist file if ('auto' === $config['env-map']) { - array_walk($expectedParams, function($v, $k) use (&$envMap) { - $envMap[$k] = strtoupper($k); - }); + foreach ($expectedParams as $key => $value) { + $envMap[$key] = strtoupper($key); + } } else { $envMap = (array) $config['env-map']; } diff --git a/README.md b/README.md index 1bd28de..953f728 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ As environment variables can only be strings, they are also parsed as inline Yaml values to allows specifying ``null``, ``false``, ``true`` or numbers easily. -## Using same names for parameters and environment variables +#### Using same names for parameters and environment variables As an alternative, you can set environment variables with the same uppercased name of your dist parameters and use ``"env-map": "auto"`` to get an auto mapping. diff --git a/Tests/ProcessorTest.php b/Tests/ProcessorTest.php index 59d54b3..30082ba 100644 --- a/Tests/ProcessorTest.php +++ b/Tests/ProcessorTest.php @@ -74,7 +74,7 @@ public function provideInvalidConfiguration() array( 'file' => 'fixtures/invalid/missing_top_level.yml', ), - 'The dist file seems invalid.', + 'The top-level key parameters is missing.', ), 'invalid values in the existing file' => array( array(