Skip to content

Commit 9e8fbf2

Browse files
committed
Removed legacy code
1 parent 2f170a1 commit 9e8fbf2

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/Visitor/Php/Symfony/ValidationAnnotation.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
use PhpParser\Node;
1515
use PhpParser\NodeVisitor;
16+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1617
use Translation\Extractor\Model\SourceLocation;
1718
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
1819
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
19-
use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface;
2020

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

@@ -36,16 +36,10 @@ final class ValidationAnnotation extends BasePHPVisitor implements NodeVisitor
3636
/**
3737
* ValidationExtractor constructor.
3838
*
39-
* @param MetadataFactoryInterface|LegacyMetadataFactoryInterface $metadataFactory
39+
* @param MetadataFactoryInterface $metadataFactory
4040
*/
41-
public function __construct($metadataFactory)
41+
public function __construct(MetadataFactoryInterface $metadataFactory)
4242
{
43-
if (!(
44-
$metadataFactory instanceof MetadataFactoryInterface
45-
|| $metadataFactory instanceof LegacyMetadataFactoryInterface
46-
)) {
47-
throw new \InvalidArgumentException(sprintf('%s expects an instance of MetadataFactoryInterface', get_class($this)));
48-
}
4943
$this->metadataFactory = $metadataFactory;
5044
}
5145

@@ -75,6 +69,7 @@ public function enterNode(Node $node)
7569
return;
7670
}
7771

72+
/** @var ClassMetadata $metadata */
7873
$metadata = $this->metadataFactory->getMetadataFor($name);
7974
if (!$metadata->hasConstraints() && !count($metadata->getConstrainedProperties())) {
8075
return;

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Extractor\Tests\Functional\Visitor\Php\Symfony;
1313

14+
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
1415
use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest;
1516
use Translation\Extractor\Tests\Resources;
1617
use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation;
@@ -24,14 +25,7 @@ final class ValidationAnnotationTest extends BasePHPVisitorTest
2425
{
2526
public function testExtractAnnotation()
2627
{
27-
//use correct factory class depending on whether using Symfony 2 or 3
28-
if (class_exists('Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory')) {
29-
$metadataFactoryClass = 'Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory';
30-
} else {
31-
$metadataFactoryClass = 'Symfony\Component\Validator\Mapping\ClassMetadataFactory';
32-
}
33-
34-
$factory = new $metadataFactoryClass(new AnnotationLoader(new AnnotationReader()));
28+
$factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader()));
3529
$extractor = new ValidationAnnotation($factory);
3630
$collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotation::class);
3731

0 commit comments

Comments
 (0)