Skip to content

Commit

Permalink
Fixed CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Sep 13, 2024
1 parent d49a836 commit 0144604
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/Translation/Extractor/JavaScriptFileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class JavaScriptFileVisitor implements FileVisitorInterface, LoggerAwareInterfac
public const TRANSLATOR_TRANS_CHOICE_METHOD = 'transChoice';

public const ID_ARG = 0;
public const TRANS_DOMAIN_ARG = 2;
public const TRANS_CHOICE_DOMAIN_ARG = 3;

/** @var \Doctrine\Common\Annotations\DocParser */
private $docParser;
Expand Down Expand Up @@ -87,10 +89,12 @@ public function visitFile(SplFileInfo $file, MessageCatalogue $catalogue)
$ast->traverse(function ($node) use ($catalogue, $file) {
if ($this->isMethodCall($node, self::TRANSLATOR_OBJECT, self::TRANSLATOR_TRANS_METHOD) || $this->isMethodCall($node, self::TRANSLATOR_OBJECT, self::TRANSLATOR_TRANS_CHOICE_METHOD)) {
$arguments = $node->getArguments();

$id = $this->extractId($file, $arguments);
if ($id !== null) {
$message = new Message($id, $this->extractDomain($file, $arguments) ?? $this->defaultDomain);
$callee = $node->getCallee();
$property = $callee->getProperty();

$message = new Message($id, $this->extractDomain($file, $arguments, $property->getName()) ?? $this->defaultDomain);
$message->setDesc($this->extractDesc($arguments));
$message->addSource(new FileSource((string)$file));

Expand Down Expand Up @@ -171,12 +175,15 @@ private function extractId(SplFileInfo $file, array $arguments): ?string
*
* @param \SplFileInfo $file
* @param \Peast\Syntax\Node\Expression[] $arguments
* @param string $methodName
*
* @return string|null
*/
private function extractDomain(SplFileInfo $file, array $arguments): ?string
private function extractDomain(SplFileInfo $file, array $arguments, string $methodName): ?string
{
$domainArgIndex = count($arguments) - 1;
$domainArgIndex = $methodName === self::TRANSLATOR_TRANS_METHOD
? self::TRANS_DOMAIN_ARG
: self::TRANS_CHOICE_DOMAIN_ARG;

if (isset($arguments[$domainArgIndex])) {
$domainNode = $arguments[$domainArgIndex];
Expand Down

0 comments on commit 0144604

Please sign in to comment.