StringNodePrefixer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prefixStringValue() 0 13 3
A __construct() 0 3 1
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;
16
17
use Humbug\PhpScoper\Scoper\PhpScoper;
18
use PhpParser\Error as PhpParserError;
19
use PhpParser\Node\Scalar\String_;
20
use function Safe\substr;
21
22
/**
23
 * @private
24
 */
25
final class StringNodePrefixer
26
{
27
    private PhpScoper $scoper;
28
29
    public function __construct(PhpScoper $scoper)
30
    {
31
        $this->scoper = $scoper;
32
    }
33
34
    public function prefixStringValue(String_ $node): void
35
    {
36
        try {
37
            $lastChar = substr($node->value, -1);
0 ignored issues
show
Deprecated Code introduced by
The function Safe\substr() has been deprecated: The Safe version of this function is no longer needed in PHP 8.0+ ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

37
            $lastChar = /** @scrutinizer ignore-deprecated */ substr($node->value, -1);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
38
39
            $newValue = $this->scoper->scopePhp($node->value);
40
41
            if ("\n" !== $lastChar) {
42
                $newValue = substr($newValue, 0, -1);
0 ignored issues
show
Deprecated Code introduced by
The function Safe\substr() has been deprecated: The Safe version of this function is no longer needed in PHP 8.0+ ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

42
                $newValue = /** @scrutinizer ignore-deprecated */ substr($newValue, 0, -1);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
43
            }
44
45
            $node->value = $newValue;
46
        } catch (PhpParserError $error) {
47
            // Continue without scoping the heredoc which for some reasons contains invalid PHP code
48
        }
49
    }
50
}
51