AnonymousNode::markReferenced()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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);
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...
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,
0 ignored issues
show
Bug introduced by
It seems like $this->value can also be of type object<ILess\Node>; however, ILess\Node\AnonymousNode::__construct() does only seem to accept string|object<ILess\Node\ValueNode>|null, 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...
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