• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PrestaShop / TranslationToolsBundle / 28931207646

08 Jul 2026 09:10AM UTC coverage: 78.067% (-0.2%) from 78.288%
28931207646

Pull #117

github

web-flow
Merge 2da9ee2b9 into b939f9833
Pull Request #117: Prevent error from PhpParser\Node\VariadicPlaceholder

4 of 5 new or added lines in 1 file covered. (80.0%)

2 existing lines in 1 file now uncovered.

751 of 962 relevant lines covered (78.07%)

4.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/Translation/Extractor/Visitor/Translation/ExplicitTranslationCall.php
1
<?php
2
/**
3
 * This file is authored by PrestaShop SA and Contributors <contact@prestashop.com>
4
 *
5
 * It is distributed under MIT license.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10

11
namespace PrestaShop\TranslationToolsBundle\Translation\Extractor\Visitor\Translation;
12

13
use PhpParser\Node;
14

15
/**
16
 * Looks up for a translation call using l(), trans() or t()
17
 */
18
class ExplicitTranslationCall extends AbstractTranslationNodeVisitor
19
{
20
    public const SUPPORTED_METHODS = ['l', 'trans', 't'];
21

22
    public function leaveNode(Node $node)
23
    {
24
        $this->translations->add($this->extractFrom($node));
14✔
25
    }
26

27
    public function extractFrom(Node $node)
28
    {
29
        if (!$this->appliesFor($node)) {
14✔
30
            return [];
14✔
31
        }
32

33
        /** @var Node\Expr\MethodCall|Node\Expr\FuncCall $node */
34
        $nodeName = $this->getNodeName($node);
14✔
35
        if (!in_array($nodeName, self::SUPPORTED_METHODS)) {
14✔
36
            return [];
2✔
37
        }
38

39
        // Sometimes the arg is a PhpParser\Node\VariadicPlaceholder, we ignore such cases
40
        if (!$node->args[0] instanceof Node\Arg) {
13✔
NEW
41
            return [];
×
42
        }
43

44
        $key = $this->getValue($node->args[0]);
13✔
45
        if (empty($key)) {
13✔
UNCOV
46
            return [];
×
47
        }
48

49
        $translation = [
13✔
50
            'source' => $key,
13✔
51
            'line' => $node->args[0]->getLine(),
13✔
52
        ];
13✔
53

54
        if ($nodeName == 'trans') {
13✔
55
            // First line is Symfony Style, second is Prestashop FrameworkBundle Style
56
            if (count($node->args) > 2 && $node->args[2]->value instanceof Node\Scalar\String_) {
12✔
57
                $translation['domain'] = $node->args[2]->value->value;
11✔
58
            } elseif (count($node->args) > 1 && $node->args[1]->value instanceof Node\Scalar\String_) {
8✔
59
                $translation['domain'] = $node->args[1]->value->value;
12✔
60
            }
61
        } elseif ($nodeName == 't') {
12✔
62
            $translation['domain'] = 'Emails.Body';
1✔
63
        }
64

65
        return [$translation];
13✔
66
    }
67

68
    /**
69
     * @return bool
70
     */
71
    private function appliesFor(Node $node)
72
    {
73
        if (empty($node->args)) {
14✔
74
            return false;
14✔
75
        }
76

77
        return
14✔
78
            ($node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\FuncCall)
14✔
79
            && ($node->name instanceof Node\Identifier || $node->name instanceof Node\Name)
14✔
80
        ;
14✔
81
    }
82

83
    /**
84
     * @return string|null
85
     */
86
    private function getValue(Node\Arg $arg)
87
    {
88
        if ($arg->value instanceof Node\Scalar\String_) {
13✔
89
            return $arg->value->value;
13✔
UNCOV
90
        } elseif (gettype($arg) === 'string') {
×
91
            return $arg->value;
×
92
        }
93
    }
94

95
    /**
96
     * @param Node|Node\Expr\MethodCall|Node\Expr\FuncCall $node
97
     */
98
    private function getNodeName(Node $node)
99
    {
100
        if ($node->name instanceof Node\Name) {
14✔
101
            // $node->name is an instance of Identifier
102
            return $node->name->parts[0];
1✔
103
        }
104

105
        return $node->name->name;
13✔
106
    }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc