Issues (5)

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.

src/ItemGroup.php (3 issues)

Labels
Severity

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
namespace CL\FluidGallery;
4
5
use ArrayObject;
6
use Closure;
7
8
/**
9
 * @author    Ivan Kerin <[email protected]>
10
 * @copyright 2015, Clippings Ltd.
11
 * @license   http://spdx.org/licenses/BSD-3-Clause
12
 */
13
class ItemGroup extends ArrayObject {
14
15
    private $margin;
16
17
    /**
18
     * @param Item[] $items
19
     * @param float  $margin
20
     */
21 1
    public function __construct(array $items, $margin = 0)
22
    {
23 1
        foreach ($items as $item) {
24 1
            $this->add($item);
25
        }
26
27 1
        $this->margin = $margin;
28 1
    }
29
30
    /**
31
     * Get the margin
32
     * @return float
33
     */
34 1
    public function getMargin()
35
    {
36 1
        return $this->margin;
37
    }
38
39
    /**
40
     * Get the margin as a percentage of total
41
     * @param  float $total
42
     * @return float
43
     */
44 1
    public function getMarginPercent($total)
45
    {
46 1
        return ($this->margin / $total) * 100;
47
    }
48
49
    /**
50
     * Change the margin
51
     * @param float $margin
52
     */
53 1
    public function setMargin($margin)
54
    {
55 1
        $this->margin = $margin;
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * Add item
62
     * @param Item $item
63
     */
64 1
    public function add(Item $item)
65
    {
66 1
        $this->append($item);
67 1
    }
68
69
    /**
70
     * Extract an ItemGroup, removing all the items from the parent ItemGroup
71
     * @param  Closure $extract
72
     * @return ItemGroup
73
     */
74 1
    public function extract(Closure $extract)
75
    {
76 1
        $array = $this->getArrayCopy();
77
78 1
        $extracted = $extract(new ItemGroup($array, $this->margin));
79
80 1
        $this->exchangeArray(array_diff($array, $extracted->getArrayCopy()));
81
82 1
        return $extracted;
83
    }
84
85
    /**
86
     * Set all widths, keeping aspect ratios
87
     * @param integer $width
88
     */
89 1
    public function setWidth($width)
90
    {
91 1
        foreach ($this as $item) {
92 1
            $item->setWidth($width);
93
        }
94
95 1
        return $this;
96
    }
97
98
    /**
99
     * Set all hights, keeping aspect ratios
100
     * @param integer $height
101
     */
102 1
    public function setHeight($height)
103
    {
104 1
        foreach ($this as $item) {
105 1
            $item->setHeight($height);
106
        }
107
108 1
        return $this;
109
    }
110
111
    /**
112
     * Multiple the width/height of all the items by $scale
113
     * @param float $scale
114
     */
115 1
    public function setScale($scale)
116
    {
117 1
        foreach ($this as $item) {
118 1
            $item->setWidth($item->getWidth() * $scale);
119
        }
120
121 1
        return $this;
122
    }
123
124
    /**
125
     * Return a new ItemGroup with items, filtered by the Closure
126
     * @param  Closure $filter
127
     * @return ItemGroup
128
     */
129 1
    public function filter(Closure $filter)
130
    {
131 1
        return new ItemGroup(array_filter($this->getArrayCopy(), $filter), $this->margin);
132
    }
133
134
    /**
135
     * Return a new ItemGroup with items, sliced by the $offcet and $limit
136
     * @param  Closure $filter
0 ignored issues
show
There is no parameter named $filter. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
137
     * @return ItemGroup
138
     */
139 1
    public function slice($offset, $limit)
140
    {
141 1
        return new ItemGroup(array_slice($this->getArrayCopy(), $offset, $limit), $this->margin);
142
    }
143
144
    /**
145
     * Scale all of the widths of the items to match an overall width, respecting margins
146
     * @param  float $width
147
     * @return ItemGroup
148
     */
149 1
    public function scaleToWidth($width)
150
    {
151 1
        $items = clone $this;
152 1
        $widthWithoutMargins = $width - $items->getGaps() * $this->margin;
153 1
        $sumWidths = $items->sumWidths();
154
155 1
        if ($sumWidths and $sumWidths < $widthWithoutMargins) {
156 1
            $difference = $widthWithoutMargins / $sumWidths;
157 1
            $items->setScale($difference);
158
        }
159
160 1
        return $items;
161
    }
162
163
    /**
164
     * Scale all of the widths of the items to match an overall height, respecting margins
165
     * @param  float $height
166
     * @return ItemGroup
167
     */
168 1
    public function scaleToHeight($height)
169
    {
170 1
        $items = clone $this;
171 1
        $heightWithoutMargins = $height - $items->getGaps() * $this->margin;
172 1
        $sumHeights = $items->sumHeights();
173
174 1
        if ($sumHeights and $sumHeights < $heightWithoutMargins) {
175 1
            $difference = $heightWithoutMargins / $sumHeights;
176 1
            $items->setScale($difference);
177
        }
178
179 1
        return $items;
180
    }
181
182
    /**
183
     * Remove all items that fall outside of width, when aligned horizontally, spaced by $margin
184
     * @param  integer $width
185
     * @param  integer $margin
0 ignored issues
show
There is no parameter named $margin. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
186
     */
187 1
    public function horizontalSlice($width)
188
    {
189 1
        $current = 0;
190
191
        return $this
192
            ->filter(function(Item $item) use ($width, &$current) {
193 1
                $current += $item->getWidth() + $this->margin;
194
195 1
                return $current <= ($width + $this->margin);
196 1
            });
197
    }
198
199
    /**
200
     * Remove all items that fall outside of height, when aligned horizontally, spaced by $margin
201
     * @param  integer $height
202
     * @param  integer $margin
0 ignored issues
show
There is no parameter named $margin. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
203
     */
204 1
    public function verticalSlice($height)
205
    {
206 1
        $current = 0;
207
208
        return $this->filter(function(Item $item) use ($height, &$current) {
209 1
            $current += $item->getHeight() + $this->margin;
210
211 1
            return $current <= ($height + $this->margin);
212 1
        });
213
    }
214
215
    /**
216
     * @return integer
217
     */
218 1
    public function getGaps()
219
    {
220 1
        return max(count($this) - 1, 0);
221
    }
222
223
    /**
224
     * @return float
225
     */
226 1
    public function getWidth()
227
    {
228 1
        return $this->sumWidths() + $this->getGaps() * $this->margin;
229
    }
230
231
    /**
232
     * @return float
233
     */
234 1
    public function getHeight()
235
    {
236 1
        return $this->sumHeights() + $this->getGaps() * $this->margin;
237
    }
238
239
    /**
240
     * @return float
241
     */
242 1
    public function sumWidths()
243
    {
244
        return array_sum(array_map(function(Item $item) {
245 1
            return $item->getWidth();
246 1
        }, $this->getArrayCopy()));
247
    }
248
249
    /**
250
     * @return float
251
     */
252 1
    public function sumHeights()
253
    {
254
        return array_sum(array_map(function(Item $item) {
255 1
            return $item->getHeight();
256 1
        }, $this->getArrayCopy()));
257
    }
258
}
259