Skip to content

Commit

Permalink
Replaced array_walk() with foreach().
Browse files Browse the repository at this point in the history
Add a more detailed exception message when a top-level key is missing.

Fixed style in README.md.
  • Loading branch information
phansys committed Sep 17, 2014
1 parent 9f1e09a commit e828133
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e828133

Please sign in to comment.