Issues (191)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/ILess/Node/UnitNode.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Node;
14
use ILess\Output\OutputInterface;
15
use ILess\Util\UnitConversion;
16
17
/**
18
 * Dimension unit.
19
 */
20
class UnitNode extends Node implements ComparableInterface
21
{
22
    /**
23
     * Length regular expression.
24
     */
25
    const LENGTH_REGEXP = '/px|em|%|in|cm|mm|pc|pt|ex/';
26
27
    /**
28
     * Numerator.
29
     *
30
     * @var array
31
     */
32
    public $numerator = [];
33
34
    /**
35
     * Denominator.
36
     *
37
     * @var array
38
     */
39
    public $denominator = [];
40
41
    /**
42
     * The backup unit to use when unit is empty.
43
     *
44
     * @var string
45
     */
46
    public $backupUnit;
47
48
    /**
49
     * Constructor.
50
     *
51
     * @param array $numerator
52
     * @param array $denominator
53
     * @param string $backupUnit
54
     */
55
    public function __construct(array $numerator = [], array $denominator = [], $backupUnit = null)
56
    {
57
        $this->numerator = $numerator;
58
        $this->denominator = $denominator;
59
60
        sort($this->numerator);
61
        sort($this->denominator);
62
63
        if ($backupUnit) {
64
            $this->backupUnit = $backupUnit;
65
        } elseif ($numerator) {
66
            $this->backupUnit = $numerator[0];
67
        }
68
    }
69
70
    /**
71
     * Converts to string.
72
     *
73
     * @return string
74
     */
75
    public function toString()
76
    {
77
        $returnStr = implode('*', $this->numerator);
78
        foreach ($this->denominator as $d) {
79
            $returnStr .= '/' . $d;
80
        }
81
82
        return $returnStr;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function compare(Node $other)
89
    {
90
        // we can compare only units
91
        if ($other instanceof self) {
92
            return $this->is($other->toString()) ? 0 : null;
93
        }
94
    }
95
96
    /**
97
     * Take care about backup unit when cloning, see the constructor.
98
     */
99
    public function __clone()
100
    {
101
        if (null === $this->backupUnit && count($this->numerator)) {
102
            $this->backupUnit = $this->numerator[0];
103
        }
104
    }
105
106
    /**
107
     * Is the unit equal to $unitString?
108
     *
109
     * @param string $unitString
110
     *
111
     * @return bool
112
     */
113
    public function is($unitString)
114
    {
115
        return strtoupper($this->toString()) === strtoupper($unitString);
116
    }
117
118
    /**
119
     * Is the unit length unit?
120
     *
121
     * @return bool
122
     */
123
    public function isLength()
124
    {
125
        $css = $this->toCSS(new Context());
126
127
        return (bool) preg_match(self::LENGTH_REGEXP, $css);
128
    }
129
130
    /**
131
     * Is the unit angle unit?
132
     *
133
     * @return bool
134
     */
135
    public function isAngle()
136
    {
137
        $angle = UnitConversion::getGroup('angle');
138
139
        return isset($angle[$this->toCSS(new Context())]);
140
    }
141
142
    /**
143
     * Is the unit empty?
144
     *
145
     * @return bool
146
     */
147
    public function isEmpty()
148
    {
149
        return count($this->numerator) === 0 && count($this->denominator) === 0;
150
    }
151
152
    /**
153
     * Is singular?
154
     *
155
     * @return bool
156
     */
157
    public function isSingular()
158
    {
159
        return count($this->numerator) <= 1 && count($this->denominator) == 0;
160
    }
161
162
    public function usedUnits()
163
    {
164
        $result = [];
165
        foreach (UnitConversion::getGroups() as $groupName) {
166
            $group = UnitConversion::getGroup($groupName);
167
            for ($i = 0; $i < count($this->numerator); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
168
                $atomicUnit = $this->numerator[$i];
169
                if (isset($group[$atomicUnit]) && !isset($result[$groupName])) {
170
                    $result[$groupName] = $atomicUnit;
171
                }
172
            }
173
            for ($i = 0; $i < count($this->denominator); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
174
                $atomicUnit = $this->denominator[$i];
175
                if (isset($group[$atomicUnit]) && !isset($result[$groupName])) {
176
                    $result[$groupName] = $atomicUnit;
177
                }
178
            }
179
        }
180
181
        return $result;
182
    }
183
184
    public function cancel()
185
    {
186
        $counter = [];
187
188
        for ($i = 0; $i < count($this->numerator); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
189
            $atomicUnit = $this->numerator[$i];
190
            $counter[$atomicUnit] = (isset($counter[$atomicUnit]) ? $counter[$atomicUnit] : 0) + 1;
191
        }
192
193
        for ($i = 0; $i < count($this->denominator); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
194
            $atomicUnit = $this->denominator[$i];
195
            $counter[$atomicUnit] = (isset($counter[$atomicUnit]) ? $counter[$atomicUnit] : 0) - 1;
196
        }
197
198
        $this->numerator = [];
199
        $this->denominator = [];
200
201
        foreach ($counter as $atomicUnit => $count) {
202
            if ($count > 0) {
203
                for ($i = 0; $i < $count; ++$i) {
204
                    $this->numerator[] = $atomicUnit;
205
                }
206
            } elseif ($count < 0) {
207
                for ($i = 0; $i < -$count; ++$i) {
208
                    $this->denominator[] = $atomicUnit;
209
                }
210
            }
211
        }
212
213
        sort($this->numerator);
214
        sort($this->denominator);
215
    }
216
217
    /**
218
     * {@inheritdoc}
219
     */
220
    public function generateCSS(Context $context, OutputInterface $output)
221
    {
222
        if (count($this->numerator) === 1) {
223
            $output->add($this->numerator[0]);
224
        } elseif (!$context->strictUnits && $this->backupUnit) {
225
            $output->add($this->backupUnit);
226
        } elseif (!$context->strictUnits && count($this->denominator)) {
227
            $output->add($this->denominator[0]);
228
        }
229
    }
230
231
    /**
232
     * Convert to string.
233
     *
234
     * @return string
235
     */
236
    public function __toString()
237
    {
238
        return $this->toString();
239
    }
240
}
241