Skip to content
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

chore(deps): upgrade nikic/php-parser@^5 #584

Merged
merged 1 commit into from
Feb 6, 2024
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
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 = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $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 = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $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 = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $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 = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $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' === (property_exists($item->value->name, 'parts') ? $item->value->name->parts[0] : $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\LNumber && !$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 = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $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] = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $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 = property_exists($interface, 'parts') ? implode('\\', $interface->parts) : $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 = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $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 = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $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",
qkdreyer marked this conversation as resolved.
Show resolved Hide resolved
"nikic/php-parser": "^4.9 || ^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
Loading