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
|
|
|
* Anonymous node. |
19
|
|
|
*/ |
20
|
|
|
class AnonymousNode extends Node implements ComparableInterface, |
21
|
|
|
MarkableAsReferencedInterface, ReferencedInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Node type. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $type = 'Anonymous'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Current index. |
32
|
|
|
* |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
public $index = 0; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Map lines flag. |
39
|
|
|
* |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
public $mapLines; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
private $rulesetLike = false; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Is referenced? |
51
|
|
|
* |
52
|
|
|
* @var bool |
53
|
|
|
*/ |
54
|
|
|
public $isReferenced = false; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructor. |
58
|
|
|
* |
59
|
|
|
* @param string|ValueNode|null $value |
60
|
|
|
* @param int $index |
61
|
|
|
* @param FileInfo $currentFileInfo |
62
|
|
|
* @param bool $mapLines |
63
|
|
|
* @param bool $rulesetLike |
64
|
|
|
* @param bool $referenced |
65
|
|
|
*/ |
66
|
|
|
public function __construct( |
67
|
|
|
$value, |
68
|
|
|
$index = 0, |
69
|
|
|
FileInfo $currentFileInfo = null, |
70
|
|
|
$mapLines = false, |
71
|
|
|
$rulesetLike = false, |
72
|
|
|
$referenced = false |
73
|
|
|
) { |
74
|
|
|
parent::__construct($value); |
75
|
|
|
|
76
|
|
|
$this->index = $index; |
77
|
|
|
$this->currentFileInfo = $currentFileInfo; |
78
|
|
|
$this->mapLines = $mapLines; |
79
|
|
|
$this->rulesetLike = (boolean) $rulesetLike; |
80
|
|
|
$this->isReferenced = $referenced; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function generateCSS(Context $context, OutputInterface $output) |
87
|
|
|
{ |
88
|
|
|
$output->add($this->value, $this->currentFileInfo, $this->index, $this->mapLines); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Converts to CSS. |
93
|
|
|
* |
94
|
|
|
* @param Context $context |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function toCSS(Context $context) |
99
|
|
|
{ |
100
|
|
|
return $this->value; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Compiles the node. |
105
|
|
|
* |
106
|
|
|
* @param Context $context The context |
107
|
|
|
* @param array|null $arguments Array of arguments |
108
|
|
|
* @param bool|null $important Important flag |
109
|
|
|
* |
110
|
|
|
* @return AnonymousNode |
111
|
|
|
*/ |
112
|
|
|
public function compile(Context $context, $arguments = null, $important = null) |
113
|
|
|
{ |
114
|
|
|
return new self($this->value, $this->index, $this->currentFileInfo, $this->mapLines, |
|
|
|
|
115
|
|
|
$this->rulesetLike, $this->isReferenced); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function compare(Node $other) |
122
|
|
|
{ |
123
|
|
|
// we need to provide The context for those |
124
|
|
|
$context = new Context(); |
125
|
|
|
if ($this->toCSS($context) === $other->toCSS($context)) { |
126
|
|
|
return 0; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return bool |
132
|
|
|
*/ |
133
|
|
|
public function isRulesetLike() |
134
|
|
|
{ |
135
|
|
|
return $this->rulesetLike; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function getIsReferenced() |
142
|
|
|
{ |
143
|
|
|
return !$this->currentFileInfo || !$this->currentFileInfo->reference || $this->isReferenced; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Marks as referenced. |
148
|
|
|
*/ |
149
|
|
|
public function markReferenced() |
150
|
|
|
{ |
151
|
|
|
$this->isReferenced = true; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
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.