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); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Mark the comment as referenced. |
92
|
|
|
*/ |
93
|
|
|
public function markReferenced() |
94
|
|
|
{ |
95
|
|
|
$this->isReferenced = true; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.