minor #16005 The 'config' variable is already used as an array expression less... (tecnocat)

This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16005).

Discussion
----------

The 'config' variable is already used as an array expression less...

| Q             | A
| ------------- | ---
| Fixed tickets | None
| License       | MIT

The 'config' variable is already used as an array expression less...

Using a variable both as an 'array expression' and as a 'key' or 'value' most often is a typing error.

Commits
-------

f15d179 The 'config' variable is already used as an array expression less...
This commit is contained in:
Fabien Potencier 2015-10-01 15:23:51 +02:00
commit 38888af7ce

View File

@ -58,7 +58,7 @@ class YamlFileLoader extends FileLoader
}
try {
$config = $this->yamlParser->parse(file_get_contents($path));
$parsedConfig = $this->yamlParser->parse(file_get_contents($path));
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
}
@ -67,16 +67,16 @@ class YamlFileLoader extends FileLoader
$collection->addResource(new FileResource($path));
// empty file
if (null === $config) {
if (null === $parsedConfig) {
return $collection;
}
// not an array
if (!is_array($config)) {
if (!is_array($parsedConfig)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
}
foreach ($config as $name => $config) {
foreach ($parsedConfig as $name => $config) {
if (isset($config['pattern'])) {
if (isset($config['path'])) {
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));