Skip to content

Commit 86eb119

Browse files
committed
🚨 Fix scrutinizer issues
1 parent d55a663 commit 86eb119

10 files changed

Lines changed: 169 additions & 42 deletions

File tree

‎benchmarks/TreeMapBench.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TreeMapBench
3333
protected $tree;
3434

3535
/**
36-
* @var chdemko\SortedCollection\SortedMap The sorted map
36+
* @var \chdemko\SortedCollection\SortedMap The sorted map
3737
*
3838
* @since 1.0.5
3939
*/

‎src/SortedCollection/Iterator.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ public function current(): mixed
188188
*/
189189
public function next(): void
190190
{
191+
if ($this->current === null) {
192+
return;
193+
}
194+
191195
try {
192196
$this->current = $this->map->successor($this->current);
193197
} catch (\OutOfBoundsException $e) {

‎src/SortedCollection/ReversedMap.php‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ReversedMap extends AbstractMap
4141
*
4242
* @since 1.0.0
4343
*/
44-
private $map;
44+
private $mapInternal;
4545

4646
/**
4747
* @var callable Comparator function
@@ -55,7 +55,7 @@ class ReversedMap extends AbstractMap
5555
*
5656
* @since 1.0.0
5757
*/
58-
private $comparator;
58+
private $comparatorInternal;
5959

6060
/**
6161
* Constructor
@@ -66,9 +66,9 @@ class ReversedMap extends AbstractMap
6666
*/
6767
protected function __construct(SortedMap $map)
6868
{
69-
$this->map = $map;
70-
$this->comparator = function ($key1, $key2) {
71-
return - call_user_func($this->map->comparator, $key1, $key2);
69+
$this->mapInternal = $map;
70+
$this->comparatorInternal = function ($key1, $key2) {
71+
return - call_user_func($this->mapInternal->comparator, $key1, $key2);
7272
};
7373
}
7474

@@ -99,7 +99,7 @@ public function __get($property)
9999
{
100100
switch ($property) {
101101
case 'map':
102-
return $this->map;
102+
return $this->mapInternal;
103103
default:
104104
return parent::__get($property);
105105
}
@@ -114,7 +114,7 @@ public function __get($property)
114114
*/
115115
public function comparator()
116116
{
117-
return $this->comparator;
117+
return $this->comparatorInternal;
118118
}
119119

120120
/**
@@ -128,7 +128,7 @@ public function comparator()
128128
*/
129129
public function first()
130130
{
131-
return $this->map->last();
131+
return $this->mapInternal->last();
132132
}
133133

134134
/**
@@ -142,7 +142,7 @@ public function first()
142142
*/
143143
public function last()
144144
{
145-
return $this->map->first();
145+
return $this->mapInternal->first();
146146
}
147147

148148
/**
@@ -158,7 +158,7 @@ public function last()
158158
*/
159159
public function predecessor($element)
160160
{
161-
return $this->map->successor($element);
161+
return $this->mapInternal->successor($element);
162162
}
163163

164164
/**
@@ -172,7 +172,7 @@ public function predecessor($element)
172172
*/
173173
public function successor($element)
174174
{
175-
return $this->map->predecessor($element);
175+
return $this->mapInternal->predecessor($element);
176176
}
177177

178178
/**
@@ -188,7 +188,7 @@ public function successor($element)
188188
*/
189189
public function lower($key)
190190
{
191-
return $this->map->higher($key);
191+
return $this->mapInternal->higher($key);
192192
}
193193

194194
/**
@@ -204,7 +204,7 @@ public function lower($key)
204204
*/
205205
public function floor($key)
206206
{
207-
return $this->map->ceiling($key);
207+
return $this->mapInternal->ceiling($key);
208208
}
209209

210210
/**
@@ -220,7 +220,7 @@ public function floor($key)
220220
*/
221221
public function find($key)
222222
{
223-
return $this->map->find($key);
223+
return $this->mapInternal->find($key);
224224
}
225225

226226
/**
@@ -236,7 +236,7 @@ public function find($key)
236236
*/
237237
public function ceiling($key)
238238
{
239-
return $this->map->floor($key);
239+
return $this->mapInternal->floor($key);
240240
}
241241

242242
/**
@@ -252,7 +252,7 @@ public function ceiling($key)
252252
*/
253253
public function higher($key)
254254
{
255-
return $this->map->lower($key);
255+
return $this->mapInternal->lower($key);
256256
}
257257

258258
/**
@@ -264,7 +264,7 @@ public function higher($key)
264264
*/
265265
public function jsonSerialize(): array
266266
{
267-
return array('ReversedMap' => $this->map->jsonSerialize());
267+
return array('ReversedMap' => $this->mapInternal->jsonSerialize());
268268
}
269269

270270
/**
@@ -276,6 +276,6 @@ public function jsonSerialize(): array
276276
*/
277277
public function count(): int
278278
{
279-
return $this->map->count();
279+
return $this->mapInternal->count();
280280
}
281281
}

‎src/SortedCollection/ReversedSet.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ReversedSet extends AbstractSet
3535
*
3636
* @since 1.0.0
3737
*/
38-
private $set;
38+
private $setInternal;
3939

4040
/**
4141
* Constructor
@@ -46,7 +46,7 @@ class ReversedSet extends AbstractSet
4646
*/
4747
protected function __construct(SortedSet $set)
4848
{
49-
$this->setMap(ReversedMap::create($set->getMap()))->set = $set;
49+
$this->setMap(ReversedMap::create($set->getMap()))->setInternal = $set;
5050
}
5151

5252
/**
@@ -76,7 +76,7 @@ public function __get($property)
7676
{
7777
switch ($property) {
7878
case 'set':
79-
return $this->set;
79+
return $this->setInternal;
8080
default:
8181
return parent::__get($property);
8282
}
@@ -91,6 +91,6 @@ public function __get($property)
9191
*/
9292
public function jsonSerialize(): array
9393
{
94-
return array('ReversedSet' => $this->set->jsonSerialize());
94+
return array('ReversedSet' => $this->setInternal->jsonSerialize());
9595
}
9696
}

‎src/SortedCollection/SubMap.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SubMap extends AbstractMap
6666
*
6767
* @since 1.0.0
6868
*/
69-
private $map;
69+
private $mapInternal;
7070

7171
/**
7272
* @var integer from option
@@ -146,7 +146,7 @@ public function __get($property)
146146
}
147147

148148
case 'map':
149-
return $this->map;
149+
return $this->mapInternal;
150150
default:
151151
return parent::__get($property);
152152
}
@@ -227,6 +227,8 @@ public function __unset($property)
227227
default:
228228
throw new \RuntimeException('Undefined property');
229229
}
230+
231+
$this->setEmpty();
230232
}
231233

232234
/**
@@ -265,7 +267,7 @@ public function __isset($property)
265267
*/
266268
protected function __construct(SortedMap $map, $fromKey, $fromOption, $toKey, $toOption)
267269
{
268-
$this->map = $map;
270+
$this->mapInternal = $map;
269271
$this->fromKey = $fromKey;
270272
$this->fromOption = $fromOption;
271273
$this->toKey = $toKey;
@@ -283,7 +285,7 @@ protected function __construct(SortedMap $map, $fromKey, $fromOption, $toKey, $t
283285
protected function setEmpty()
284286
{
285287
if ($this->fromOption != self::UNUSED && $this->toOption != self::UNUSED) {
286-
$cmp = call_user_func($this->map->comparator(), $this->fromKey, $this->toKey);
288+
$cmp = call_user_func($this->mapInternal->comparator(), $this->fromKey, $this->toKey);
287289

288290
$this->empty = $cmp > 0
289291
|| $cmp == 0 && ($this->fromOption == self::EXCLUSIVE || $this->toOption == self::EXCLUSIVE);
@@ -371,7 +373,7 @@ public static function view(SortedMap $map)
371373
*/
372374
public function comparator()
373375
{
374-
return $this->map->comparator();
376+
return $this->mapInternal->comparator();
375377
}
376378

377379
/**
@@ -391,13 +393,13 @@ public function first()
391393

392394
switch ($this->fromOption) {
393395
case self::INCLUSIVE:
394-
$first = $this->map->ceiling($this->fromKey);
396+
$first = $this->mapInternal->ceiling($this->fromKey);
395397
break;
396398
case self::EXCLUSIVE:
397-
$first = $this->map->higher($this->fromKey);
399+
$first = $this->mapInternal->higher($this->fromKey);
398400
break;
399401
default:
400-
$first = $this->map->first();
402+
$first = $this->mapInternal->first();
401403
break;
402404
}
403405

‎src/SortedCollection/TreeMap.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class TreeMap extends AbstractMap
6565
*/
6666
protected function __construct($comparator = null)
6767
{
68-
if ($comparator == null) {
68+
if ($comparator === null) {
6969
$this->comparator = function ($key1, $key2) {
70-
return $key1 - $key2;
70+
return $key1 <=> $key2;
7171
};
7272
} else {
7373
$this->comparator = $comparator;
@@ -313,7 +313,7 @@ public function higher($key)
313313
/**
314314
* Put values in the map
315315
*
316-
* @param \Traversable $traversable Values to put in the map
316+
* @param iterable $traversable Values to put in the map
317317
*
318318
* @return TreeMap $this for chaining
319319
*
@@ -345,7 +345,7 @@ public function clear()
345345
/**
346346
* Initialise the map
347347
*
348-
* @param \Traversable $traversable Values to initialise the map
348+
* @param iterable $traversable Values to initialise the map
349349
*
350350
* @return TreeMap $this for chaining
351351
*

‎src/SortedCollection/TreeNode.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class TreeNode implements \Countable
7373
* @param mixed $key The node key
7474
* @param mixed $value The node value
7575
*
76-
* @return A new node
76+
* @return TreeNode A new node
7777
*
7878
* @since 1.0.0
7979
*/
@@ -134,7 +134,7 @@ public function __get($property)
134134
/**
135135
* Get the first node
136136
*
137-
* @return the first node
137+
* @return TreeNode the first node
138138
*
139139
* @since 1.0.0
140140
*/
@@ -152,7 +152,7 @@ public function first()
152152
/**
153153
* Get the last node
154154
*
155-
* @return the last node
155+
* @return TreeNode the last node
156156
*
157157
* @since 1.0.0
158158
*/
@@ -170,7 +170,7 @@ public function last()
170170
/**
171171
* Get the predecessor
172172
*
173-
* @return the predecessor node
173+
* @return TreeNode the predecessor node
174174
*
175175
* @since 1.0.0
176176
*/
@@ -192,7 +192,7 @@ public function predecessor()
192192
/**
193193
* Get the successor
194194
*
195-
* @return the successor node
195+
* @return TreeNode the successor node
196196
*
197197
* @since 1.0.0
198198
*/
@@ -262,6 +262,7 @@ public function count(): int
262262
public function find($key, $comparator, $type = 0)
263263
{
264264
$node = $this;
265+
$cmp = 0;
265266

266267
while (true) {
267268
$cmp = call_user_func($comparator, $key, $node->key);

‎src/SortedCollection/TreeSet.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function create($comparator = null)
5858
/**
5959
* Put values in the set
6060
*
61-
* @param \Traversable $traversable Values to put in the set
61+
* @param iterable $traversable Values to put in the set
6262
*
6363
* @return TreeSet $this for chaining
6464
*
@@ -90,7 +90,7 @@ public function clear()
9090
/**
9191
* Initialise the set
9292
*
93-
* @param \Traversable $traversable Values to initialise the set
93+
* @param iterable $traversable Values to initialise the set
9494
*
9595
* @return TreeSet $this for chaining
9696
*

0 commit comments

Comments
 (0)