PrettyPrinter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
wmc 2
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A pScalar_String() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Reflection;
17
18
use PhpParser\Lexer;
19
use PhpParser\Node\Scalar\String_;
20
use PhpParser\PrettyPrinter\Standard;
21
22
/**
23
 * Custom PrettyPrinter for phpDocumentor.
24
 *
25
 * phpDocumentor has a custom PrettyPrinter for PHP-Parser because it needs the
26
 * unmodified value for Scalar variables instead of an interpreted version.
27
 *
28
 * If the interpreted version was to be used then the XML interpretation would
29
 * fail because of special characters.
30
 *
31
 * @author  Mike van Riel <[email protected]>
32
 * @license http://www.opensource.org/licenses/mit-license.php MIT
33
 * @link    http://phpdoc.org
34
 */
35
class PrettyPrinter extends Standard
36
{
37
    /**
38
     * Converts the string into it's original representation without converting
39
     * the special character combinations.
40
     *
41
     * This method is overridden from the original Zend Pretty Printer because
42
     * the original returns the strings as interpreted by PHP-Parser.
43
     * Since we do not want such conversions we take the original that is
44
     * injected by our own custom Lexer.
45
     *
46
     * @param String_ $node The node to return a string representation of.
47
     *
48
     * @see Lexer where the originalValue is injected.
49
     *
50
     * @return string
51
     */
52
    // @codingStandardsIgnoreStart
53 1
    public function pScalar_String(String_ $node): string
54
    {
55
        // @codingStandardsIgnoreStart
56 1
        if (!$node->getAttribute('originalValue')) {
57
            return $node->value;
58
        }
59
60 1
        return (string) $node->getAttribute('originalValue');
61
    }
62
}
63