Skip to content

Commit 2749f86

Browse files
authored
Merge branch 'master' into issue-51
2 parents 1674fad + b11a4b1 commit 2749f86

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/Visitor/Php/Symfony/ValidationAnnotation.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
use Doctrine\Common\Annotations\AnnotationException;
1515
use PhpParser\Node;
1616
use PhpParser\NodeVisitor;
17+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1718
use Translation\Extractor\Model\SourceLocation;
1819
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
1920
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
20-
use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface;
2121

2222
/**
2323
* @author Tobias Nyholm <[email protected]>
2424
*/
2525
final class ValidationAnnotation extends BasePHPVisitor implements NodeVisitor
2626
{
2727
/**
28-
* @var MetadataFactoryInterface|LegacyMetadataFactoryInterface
28+
* @var MetadataFactoryInterface
2929
*/
3030
private $metadataFactory;
3131

@@ -37,16 +37,10 @@ final class ValidationAnnotation extends BasePHPVisitor implements NodeVisitor
3737
/**
3838
* ValidationExtractor constructor.
3939
*
40-
* @param MetadataFactoryInterface|LegacyMetadataFactoryInterface $metadataFactory
40+
* @param MetadataFactoryInterface $metadataFactory
4141
*/
42-
public function __construct($metadataFactory)
42+
public function __construct(MetadataFactoryInterface $metadataFactory)
4343
{
44-
if (!(
45-
$metadataFactory instanceof MetadataFactoryInterface
46-
|| $metadataFactory instanceof LegacyMetadataFactoryInterface
47-
)) {
48-
throw new \InvalidArgumentException(sprintf('%s expects an instance of MetadataFactoryInterface', get_class($this)));
49-
}
5044
$this->metadataFactory = $metadataFactory;
5145
}
5246

@@ -77,6 +71,7 @@ public function enterNode(Node $node)
7771
}
7872

7973
try {
74+
/** @var ClassMetadata $metadata */
8075
$metadata = $this->metadataFactory->getMetadataFor($name);
8176
} catch (AnnotationException $e) {
8277
$this->addError($node, 'Could not parse class "%s" for annotations. %s', $this->namespace, $e->getMessage());

tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ final class ValidationAnnotationTest extends BasePHPVisitorTest
2525
{
2626
public function testExtractAnnotation()
2727
{
28-
//use correct factory class depending on whether using Symfony 2 or 3
29-
if (class_exists('Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory')) {
30-
$metadataFactoryClass = 'Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory';
31-
} else {
32-
$metadataFactoryClass = 'Symfony\Component\Validator\Mapping\ClassMetadataFactory';
33-
}
34-
35-
$factory = new $metadataFactoryClass(new AnnotationLoader(new AnnotationReader()));
28+
$factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()));
3629
$extractor = new ValidationAnnotation($factory);
3730
$collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotation::class);
3831

0 commit comments

Comments
 (0)