8000 [Validator] Fix init of YamlFileLoader::$classes for empty files by nicolas-grekas · Pull Request #20828 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Fix init of YamlFileLoader::$classes for empty files #20828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Validator] Fix init of YamlFileLoader::$classes for empty files
  • Loading branch information
nicolas-grekas committed Dec 8, 2016
commit 073a1dae1318519066ca9fb0d2dc53392ac5fbca
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ public function loadClassMetadata(ClassMetadata $metadata)
$this->yamlParser = new YamlParser();
}

// This method may throw an exception. Do not modify the class'
// state before it completes
if (false === ($classes = $this->parseFile($this->file))) {
return false;
}

$this->classes = $classes;
$this->classes = $this->parseFile($this->file);

if (isset($this->classes['namespaces'])) {
foreach ($this->classes['namespaces'] as $alias => $namespace) {
Expand Down Expand Up @@ -111,7 +105,7 @@ protected function parseNodes(array $nodes)
*
* @param string $path The path of the YAML file
*
* @return array|null The class descriptions or null, if the file was empty
* @return array The class descriptions
*
* @throws \InvalidArgumentException If the file could not be loaded or did
* not contain a YAML array
Expand All @@ -126,7 +120,7 @@ private function parseFile($path)

// empty file
if (null === $classes) {
return;
return array();
}

// not an array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function testLoadClassMetadataReturnsFalseIfEmpty()
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');

$this->assertFalse($loader->loadClassMetadata($metadata));

$r = new \ReflectionProperty($loader, 'classes');
$r->setAccessible(true);
$this->assertSame(array(), $r->getValue($loader));
}

/**
Expand Down
0