BasePHPVisitor::getStringArgument()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4.0218
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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 Translation\Extractor\Visitor\Php;
13
14
use PhpParser\Node;
15
use Translation\Extractor\Visitor\BaseVisitor;
16
17
/**
18
 * Base class for PHP visitors.
19
 *
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
abstract class BasePHPVisitor extends BaseVisitor
23
{
24 9
    protected function getStringArgument(Node\Expr\MethodCall $node, int $index): ?string
25
    {
26 9
        if (!isset($node->args[$index])) {
27 6
            return null;
28
        }
29
30 9
        if (!$node->args[$index]->value instanceof Node\Scalar\String_) {
31 6
            return null;
32
        }
33
34 9
        $label = $node->args[$index]->value->value;
35 9
        if (empty($label)) {
36
            return null;
37
        }
38
39 9
        return $label;
40
    }
41
}
42