Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Extractor/Visitor/TransMethodVisitor.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Translation\Extractor\Visitor;
13
14 use PhpParser\Node;
15 use PhpParser\NodeVisitor;
16
17 /**
18 * @author Mathieu Santostefano <[email protected]>
19 */
20 final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
21 {
22 public function beforeTraverse(array $nodes): ?Node
23 {
24 return null;
25 }
26
27 public function enterNode(Node $node): ?Node
28 {
29 return null;
30 }
31
32 public function leaveNode(Node $node): ?Node
33 {
34 if (!$node instanceof Node\Expr\MethodCall && !$node instanceof Node\Expr\FuncCall) {
35 return null;
36 }
37
38 if (!\is_string($node->name) && !$node->name instanceof Node\Identifier && !$node->name instanceof Node\Name) {
39 return null;
40 }
41
42 $name = $node->name instanceof Node\Name ? $node->name->getLast() : (string) $node->name;
43
44 if ('trans' === $name || 't' === $name) {
45 $firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node);
46
47 if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'id')) {
48 return null;
49 }
50
51 $domain = $this->getStringArguments($node, 2 < $firstNamedArgumentIndex ? 2 : 'domain')[0] ?? null;
52
53 foreach ($messages as $message) {
54 $this->addMessageToCatalogue($message, $domain, $node->getStartLine());
55 }
56 }
57
58 return null;
59 }
60
61 public function afterTraverse(array $nodes): ?Node
62 {
63 return null;
64 }
65 }