Skip to content

Commit 2c24250

Browse files
authored
Merge pull request #603 from deguif/php-parser-dead-code
Remove php parser dead code
2 parents 14ad9ef + ecf53a6 commit 2c24250

File tree

4 files changed

+8
-54
lines changed

4 files changed

+8
-54
lines changed

Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
use JMS\TranslationBundle\Model\MessageCatalogue;
2828
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
2929
use JMS\TranslationBundle\Translation\FileSourceFactory;
30-
use PhpParser\Lexer;
31-
use PhpParser\Parser;
3230
use PhpParser\ParserFactory;
3331
use PHPUnit\Framework\TestCase;
3432

@@ -45,14 +43,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
4543
$extractor = $this->getDefaultExtractor();
4644
}
4745

48-
$lexer = new Lexer();
49-
if (class_exists(ParserFactory::class)) {
50-
$factory = new ParserFactory();
51-
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
52-
} else {
53-
$parser = new Parser($lexer);
54-
}
55-
46+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
5647
$ast = $parser->parse(file_get_contents($fileRealPath));
5748

5849
$catalogue = new MessageCatalogue();

Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
use JMS\TranslationBundle\Model\Message;
2626
use JMS\TranslationBundle\Model\MessageCatalogue;
2727
use JMS\TranslationBundle\Translation\Extractor\File\TranslationContainerExtractor;
28-
use PhpParser\Lexer;
29-
use PhpParser\Parser;
3028
use PhpParser\ParserFactory;
3129
use PHPUnit\Framework\TestCase;
3230

@@ -59,14 +57,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null
5957
$extractor = new TranslationContainerExtractor();
6058
}
6159

62-
$lexer = new Lexer();
63-
if (class_exists(ParserFactory::class)) {
64-
$factory = new ParserFactory();
65-
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
66-
} else {
67-
$parser = new Parser($lexer);
68-
}
69-
60+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
7061
$ast = $parser->parse(file_get_contents($fileRealPath));
7162

7263
$catalogue = new MessageCatalogue();

Tests/Translation/Extractor/File/ValidationExtractorTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
use JMS\TranslationBundle\Model\Message;
2626
use JMS\TranslationBundle\Model\MessageCatalogue;
2727
use JMS\TranslationBundle\Translation\Extractor\File\ValidationExtractor;
28-
use PhpParser\Lexer;
29-
use PhpParser\Parser;
3028
use PhpParser\ParserFactory;
3129
use PHPUnit\Framework\TestCase;
3230
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
@@ -59,14 +57,7 @@ private function extract($file, ?ValidationExtractor $extractor = null)
5957
$extractor = new ValidationExtractor($factory);
6058
}
6159

62-
$lexer = new Lexer();
63-
if (class_exists(ParserFactory::class)) {
64-
$factory = new ParserFactory();
65-
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
66-
} else {
67-
$parser = new Parser($lexer);
68-
}
69-
60+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
7061
$ast = $parser->parse(file_get_contents($fileRealPath));
7162

7263
$catalogue = new MessageCatalogue();

Translation/Extractor/FileExtractor.php

+5-24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use JMS\TranslationBundle\Twig\DefaultApplyingNodeVisitor;
2828
use JMS\TranslationBundle\Twig\RemovingNodeVisitor;
2929
use PhpParser\Error;
30-
use PhpParser\Lexer;
3130
use PhpParser\Parser;
3231
use PhpParser\ParserFactory;
3332
use Psr\Log\LoggerInterface;
@@ -44,20 +43,11 @@
4443
*/
4544
class FileExtractor implements ExtractorInterface, LoggerAwareInterface
4645
{
47-
/**
48-
* @var Environment
49-
*/
50-
private $twig;
46+
private Environment $twig;
5147

52-
/**
53-
* @var array
54-
*/
55-
private $visitors;
48+
private array $visitors;
5649

57-
/**
58-
* @var Parser
59-
*/
60-
private $phpParser;
50+
private Parser $phpParser;
6151

6252
/**
6353
* @var array
@@ -89,10 +79,7 @@ class FileExtractor implements ExtractorInterface, LoggerAwareInterface
8979
*/
9080
private $excludedDirs = [];
9181

92-
/**
93-
* @var LoggerInterface
94-
*/
95-
private $logger;
82+
private LoggerInterface $logger;
9683

9784
/**
9885
* @param Environment $twig
@@ -104,13 +91,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
10491
$this->twig = $twig;
10592
$this->visitors = $visitors;
10693
$this->setLogger($logger);
107-
$lexer = new Lexer();
108-
if (class_exists(ParserFactory::class)) {
109-
$factory = new ParserFactory();
110-
$this->phpParser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
111-
} else {
112-
$this->phpParser = new Parser($lexer);
113-
}
94+
$this->phpParser = (new ParserFactory())->createForNewestSupportedVersion();
11495

11596
foreach ($this->twig->getNodeVisitors() as $visitor) {
11697
if ($visitor instanceof RemovingNodeVisitor) {

0 commit comments

Comments
 (0)