Skip to content

Commit

Permalink
chore(deps): upgrade nikic/php-parser@^5
Browse files Browse the repository at this point in the history
  • Loading branch information
qkdreyer committed Jan 8, 2024
1 parent da38bd0 commit 03f79c1
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
{
$fileRealPath = __DIR__ . '/Fixture/' . $file;
if (! is_file($fileRealPath)) {
throw new RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath));
throw new \RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath));
}

if ($extractor === null) {
Expand All @@ -48,7 +48,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
$lexer = new Lexer();
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
$parser = $factory->createForNewestSupportedVersion();
} else {
$parser = new Parser($lexer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyAuthException extends AuthenticationException
{
private $foo;

public function getMessageKey()
public function getMessageKey(): string
{
if (! empty($this->foo)) {
/** @Desc("%foo% is invalid.") */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null
$lexer = new Lexer();
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
$parser = $factory->createForNewestSupportedVersion();
} else {
$parser = new Parser($lexer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function extract($file, ?ValidationExtractor $extractor = null)
$lexer = new Lexer();
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
$parser = $factory->createForNewestSupportedVersion();
} else {
$parser = new Parser($lexer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
if (isset($node->name)) {
$this->namespace = implode('\\', $node->name->parts);
$this->namespace = $node->name->name;
}

return;
Expand Down
13 changes: 9 additions & 4 deletions Translation/Extractor/File/FormExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use JMS\TranslationBundle\Logger\LoggerAwareInterface;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Model\SourceInterface;
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
use JMS\TranslationBundle\Translation\FileSourceFactory;
use PhpParser\Comment\Doc;
Expand Down Expand Up @@ -76,7 +77,7 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV
private $defaultDomain;

/**
* @var string
* @var array
*/
private $defaultDomainMessages;

Expand Down Expand Up @@ -203,7 +204,7 @@ public function getDomain(Node $node)
protected function parseEmptyValueNode(Node $item, $domain)
{
// Skip empty_value when false
if ($item->value instanceof Node\Expr\ConstFetch && $item->value->name instanceof Node\Name && 'false' === $item->value->name->parts[0]) {
if ($item->value instanceof Node\Expr\ConstFetch && $item->value->name instanceof Node\Name && 'false' === $item->value->name->getFirst()) {
return true;
}

Expand Down Expand Up @@ -407,6 +408,10 @@ private function parseItem($item, $domain = null)
$docComment = $item->value->getDocComment();
}

if (!$docComment) {
$docComment = $item->getDocComment();
}

$docComment = is_object($docComment) ? $docComment->getText() : null;

if ($docComment) {
Expand All @@ -427,7 +432,7 @@ private function parseItem($item, $domain = null)
// check if the value is explicitly set to false => e.g. for FormField that should be rendered without label
$ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value === false;

if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber) {
if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\Int_) {
if ($ignore) {
return;
}
Expand Down Expand Up @@ -459,7 +464,7 @@ private function parseItem($item, $domain = null)

/**
* @param string $id
* @param string $source
* @param SourceInterface $source
* @param string|null $domain
* @param string|null $desc
* @param string|null $meaning
Expand Down
6 changes: 3 additions & 3 deletions Translation/Extractor/File/TranslationContainerExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
if (isset($node->name)) {
$this->namespace = implode('\\', $node->name->parts);
$this->namespace = $node->name->name;
}
$this->useStatements = [];

Expand All @@ -83,7 +83,7 @@ public function enterNode(Node $node)

if ($node instanceof Node\Stmt\UseUse) {
$nodeAliasName = is_string($node->alias) ? $node->alias : $node->getAlias()->name;
$this->useStatements[$nodeAliasName] = implode('\\', $node->name->parts);
$this->useStatements[$nodeAliasName] = $node->name->name;

return;
}
Expand All @@ -94,7 +94,7 @@ public function enterNode(Node $node)

$isContainer = false;
foreach ($node->implements as $interface) {
$name = implode('\\', $interface->parts);
$name = $interface->name;
if (isset($this->useStatements[$name])) {
$name = $this->useStatements[$name];
}
Expand Down
2 changes: 1 addition & 1 deletion Translation/Extractor/File/ValidationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
if (isset($node->name)) {
$this->namespace = implode('\\', $node->name->parts);
$this->namespace = $node->name->name;
}

return;
Expand Down
2 changes: 1 addition & 1 deletion Translation/Extractor/FileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
$lexer = new Lexer();
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
$this->phpParser = $factory->createForNewestSupportedVersion();
} else {
$this->phpParser = new Parser($lexer);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"require": {
"php": "^7.4 || ^8.0",
"nikic/php-parser": "^4.9",
"nikic/php-parser": "^5",
"symfony/console": "^4.3 || ^5.4 || ^6.0",
"symfony/expression-language": "^4.3 || ^5.4 || ^6.0",
"symfony/framework-bundle": "^4.3 || ^5.4 || ^6.0",
Expand Down

0 comments on commit 03f79c1

Please sign in to comment.