Skip to content

Commit

Permalink
Update to work on latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
artursvonda committed Apr 11, 2021
1 parent 09bdf52 commit 7d3898d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
7 changes: 3 additions & 4 deletions Tests/Translation/Extractor/File/Fixture/MyEntity.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

declare(strict_types=1);

namespace JMS\TranslationBundle\Tests\Translation\Extractor\File\Fixture;

use Symfony\Component\Validator\Context\ExecutionContext;

/**
* Class MyEntity
*/
class MyEntity
{
public function validateConstraintWithDefaultDomain(ExecutionContext $context)
Expand All @@ -16,7 +15,7 @@ public function validateConstraintWithDefaultDomain(ExecutionContext $context)
->addViolation();
}

public function validateFullyQualifiedConstraintWithDefaultDomain(\Symfony\Component\Validator\Context\ExecutionContext $context)
public function validateFullyQualifiedConstraintWithDefaultDomain(ExecutionContext $context)
{
$context
->buildViolation('entity.fully-qualified')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace JMS\TranslationBundle\Tests\Translation\Extractor\File;

use JMS\TranslationBundle\Model\Message;
Expand All @@ -11,21 +13,20 @@ class ValidationContextExtractorTest extends BasePhpFileExtractorTest
public function testExtractValidationMessages()
{
$fileSourceFactory = $this->getFileSourceFactory();
$fixtureSplInfo = new \SplFileInfo(__DIR__.'/Fixture/MyEntity.php');

$fixtureSplInfo = new \SplFileInfo(__DIR__ . '/Fixture/MyEntity.php');

$expected = new MessageCatalogue();

$message = new Message('entity.default');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 15));
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 14));
$expected->add($message);

$message = new Message('entity.fully-qualified');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 22));
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 21));
$expected->add($message);

$message = new Message('entity.custom-domain', 'custom-domain');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 29));
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 28));
$expected->add($message);

$this->assertEquals($expected, $this->extract('MyEntity.php'));
Expand Down
28 changes: 10 additions & 18 deletions Translation/Extractor/File/ValidationContextExtractor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Arturs Vonda <[email protected]>
*
Expand Down Expand Up @@ -30,8 +32,6 @@
use SplFileInfo;

/**
* Class ValidationContextExtractor
*
* Extracts
*/
class ValidationContextExtractor implements FileVisitorInterface, NodeVisitor
Expand All @@ -43,7 +43,7 @@ class ValidationContextExtractor implements FileVisitorInterface, NodeVisitor
/**
* @var array
*/
private $messages = array();
private $messages = [];
/**
* @var MessageCatalogue
*/
Expand All @@ -55,7 +55,7 @@ class ValidationContextExtractor implements FileVisitorInterface, NodeVisitor
/**
* @var array
*/
private $aliases = array();
private $aliases = [];
/**
* @var string
*/
Expand All @@ -74,11 +74,6 @@ class ValidationContextExtractor implements FileVisitorInterface, NodeVisitor
private $source;
private $fileSourceFactory;

/**
* ValidationContextExtractor constructor.
*
* @param FileSourceFactory $fileSourceFactory
*/
public function __construct(FileSourceFactory $fileSourceFactory)
{
$this->fileSourceFactory = $fileSourceFactory;
Expand All @@ -100,7 +95,7 @@ public function visitPhpFile(SplFileInfo $file, MessageCatalogue $catalogue, arr
{
$this->file = $file;
$this->catalogue = $catalogue;
$this->messages = array();
$this->messages = [];
$this->traverser->traverse($ast);

foreach ($this->messages as $message) {
Expand All @@ -111,7 +106,7 @@ public function visitPhpFile(SplFileInfo $file, MessageCatalogue $catalogue, arr
/**
* {@inheritdoc}
*/
public function visitTwigFile(SplFileInfo $file, MessageCatalogue $catalogue, \Twig_Node $ast)
public function visitTwigFile(SplFileInfo $file, MessageCatalogue $catalogue, \Twig\Node\Node $ast)
{
}

Expand All @@ -128,7 +123,7 @@ public function beforeTraverse(array $nodes)
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
$this->aliases = array();
$this->aliases = [];

return;
}
Expand Down Expand Up @@ -163,9 +158,6 @@ public function enterNode(Node $node)
}
}

/**
* @param Node\Expr\MethodCall $node
*/
private function parseMethodCall(Node\Expr\MethodCall $node)
{
if (!$this->contextVariable) {
Expand Down Expand Up @@ -199,11 +191,11 @@ private function parseMethodCall(Node\Expr\MethodCall $node)
}
} elseif ($name === 'addViolation') {
if ($this->id and $this->source) {
$this->messages[] = array(
$this->messages[] = [
'id' => $this->id,
'source' => $this->source,
'domain' => $this->domain,
);
];
}

$this->id = null;
Expand Down Expand Up @@ -257,6 +249,6 @@ private function addToCatalogue($id, SourceInterface $source, $domain = null)
*/
private function resolveAlias($class)
{
return isset($this->aliases[$class]) ? $this->aliases[$class] : $class;
return $this->aliases[$class] ?? $class;
}
}

0 comments on commit 7d3898d

Please sign in to comment.