Completed
Push — master ( 550011...0647fd )
by Théo
16:20 queued 07:57
created

NewdocPrefixer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A enterNode() 0 8 3
A isPhpNowdoc() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\PhpParser\NodeVisitor;
16
17
use Humbug\PhpScoper\PhpParser\StringScoperPrefixer;
18
use PhpParser\Node;
19
use PhpParser\Node\Scalar\String_;
20
use PhpParser\NodeVisitorAbstract;
21
use function ltrim;
22
use function strpos;
23
use function substr;
24
25
final class NewdocPrefixer extends NodeVisitorAbstract
26
{
27
    use StringScoperPrefixer;
28
29
    /**
30
     * @inheritdoc
31
     */
32 10
    public function enterNode(Node $node): Node
33
    {
34 10
        if ($node instanceof String_ && $this->isPhpNowdoc($node)) {
35
            $this->scopeStringValue($node);
36
        }
37
38 10
        return $node;
39
    }
40
41 9
    private function isPhpNowdoc(String_ $node): bool
42
    {
43 9
        if (String_::KIND_NOWDOC !== $node->getAttribute('kind')) {
44 9
            return false;
45
        }
46
47
        return 0 === strpos(
48
            substr(ltrim($node->value), 0, 5),
49
            '<?php'
50
        );
51
    }
52
}
53