CommentNode   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
cbo 4
dl 0
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B isSilent() 0 7 6
A generateCSS() 0 7 2
A markReferenced() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ILess
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace ILess\Node;
11
12
use ILess\Context;
13
use ILess\FileInfo;
14
use ILess\Node;
15
use ILess\Output\OutputInterface;
16
17
/**
18
 * Comment.
19
 */
20
class CommentNode extends Node implements MarkableAsReferencedInterface
21
{
22
    /**
23
     * Node type.
24
     *
25
     * @var string
26
     */
27
    protected $type = 'Comment';
28
29
    /**
30
     * Current index.
31
     *
32
     * @var int
33
     */
34
    public $index = 0;
35
36
    /**
37
     * Is line comment?
38
     *
39
     * @var bool
40
     */
41
    protected $isLineComment = false;
42
43
    /**
44
     * Reference flag.
45
     *
46
     * @var bool
47
     */
48
    protected $isReferenced = false;
49
50
    /**
51
     * Constructor.
52
     *
53
     * @param string $value The comment value
54
     * @param bool $isLineComment
55
     */
56
    public function __construct($value, $isLineComment = false, $index = 0, FileInfo $currentFileInfo = null)
57
    {
58
        parent::__construct($value);
59
        $this->isLineComment = (boolean) $isLineComment;
60
        $this->index = $index;
61
        $this->currentFileInfo = $currentFileInfo;
62
    }
63
64
    /**
65
     * Is the comment silent?
66
     *
67
     * @param Context $context
68
     *
69
     * @return bool
70
     */
71
    public function isSilent(Context $context)
72
    {
73
        $isReference = $this->currentFileInfo && $this->currentFileInfo->reference && !$this->isReferenced;
74
        $isCompressed = $context->compress && !preg_match('/^\/\*!/', $this->value);
75
76
        return $this->isLineComment || $isReference || $isCompressed;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function generateCSS(Context $context, OutputInterface $output)
83
    {
84
        if ($this->debugInfo) {
85
            $output->add(self::getDebugInfo($context, $this), $this->currentFileInfo, $this->index);
86
        }
87
        $output->add($this->value);
0 ignored issues
show
Bug introduced by
It seems like $this->value can also be of type object<ILess\Node>; however, ILess\Output\OutputInterface::add() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
88
    }
89
90
    /**
91
     * Mark the comment as referenced.
92
     */
93
    public function markReferenced()
94
    {
95
        $this->isReferenced = true;
96
    }
97
}
98