Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Extractor/Visitor/TranslatableMessageVisitor.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 TranslatableMessageVisitor 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\New_) {
35 return null;
36 }
37
38 if (!($className = $node->class) instanceof Node\Name) {
39 return null;
40 }
41
42 if (!\in_array('TranslatableMessage', $className->getParts(), true)) {
43 return null;
44 }
45
46 $firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node);
47
48 if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'message')) {
49 return null;
50 }
51
52 $domain = $this->getStringArguments($node, 2 < $firstNamedArgumentIndex ? 2 : 'domain')[0] ?? null;
53
54 foreach ($messages as $message) {
55 $this->addMessageToCatalogue($message, $domain, $node->getStartLine());
56 }
57
58 return null;
59 }
60
61 public function afterTraverse(array $nodes): ?Node
62 {
63 return null;
64 }
65 }