InternalTag   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 17 3
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\Transformer\Behaviour\Tag;
17
18
/**
19
 * Behaviour that adds support for @internal inline tag.
20
 */
21
class InternalTag
22
{
23
    /** @var boolean $internalAllowed true if the `@internal` tags should be rendered */
24
    protected $internalAllowed;
25
26
    /**
27
     * Initializes this tag and describes whether it should be rendered in the output.
28
     *
29
     * @param boolean $internalAllowed
30
     */
31
    public function __construct($internalAllowed)
32
    {
33
        $this->internalAllowed = $internalAllowed;
34
    }
35
36
    /**
37
     * Converts the 'internal' tags in Long Descriptions.
38
     *
39
     * @param \DOMDocument $xml Structure source to apply behaviour onto.
40
     *
41
     * @todo This behaviours actions should be moved to the parser / Reflector builder so that it can be cached
42
     *     and is available to all writers.
43
     *
44
     * @return \DOMDocument
45
     */
46
    public function process(\DOMDocument $xml)
47
    {
48
        $ignoreQry = '//long-description[contains(., "{@internal")]';
49
50
        $xpath = new \DOMXPath($xml);
51
        $nodes = $xpath->query($ignoreQry);
52
53
        // either replace it with nothing or with the 'stored' value
54
        $replacement = $this->internalAllowed ? '$1' : '';
55
56
        /** @var \DOMElement $node */
57
        foreach ($nodes as $node) {
58
            $node->nodeValue = preg_replace('/\{@internal\s(.+?)\}\}/', $replacement, $node->nodeValue);
59
        }
60
61
        return $xml;
62
    }
63
}
64