Skip to content

Commit 69d9f69

Browse files
committed
🚨 Fix scrutinizer
1 parent cf88b99 commit 69d9f69

4 files changed

Lines changed: 67 additions & 29 deletions

File tree

‎src/SortedCollection/ReversedSet.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ class ReversedSet extends AbstractSet
4646
*/
4747
protected function __construct(SortedSet $set)
4848
{
49-
$this->setMap(ReversedMap::create($set->getMap()))->setInternal = $set;
49+
if ($set instanceof AbstractSet) {
50+
$map = $set->getMap();
51+
} else {
52+
$map = TreeMap::create($set->comparator());
53+
54+
foreach ($set as $value) {
55+
$map[$value] = true;
56+
}
57+
}
58+
59+
$this->setMap(ReversedMap::create($map))->setInternal = $set;
5060
}
5161

5262
/**

‎src/SortedCollection/SubSet.php‎

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ class SubSet extends AbstractSet
6262
*/
6363
private $set;
6464

65+
/**
66+
* Get the underlying map as a SubMap
67+
*
68+
* @throws RuntimeException If the underlying map is not a SubMap
69+
*
70+
* @return SubMap The underlying sub map
71+
*
72+
* @since 1.0.0
73+
*/
74+
private function getSubMap()
75+
{
76+
$map = $this->getMap();
77+
78+
if (!$map instanceof SubMap) {
79+
throw new \RuntimeException('Unexpected map type');
80+
}
81+
82+
return $map;
83+
}
84+
6585
/**
6686
* Magic get method
6787
*
@@ -73,15 +93,17 @@ class SubSet extends AbstractSet
7393
*/
7494
public function __get($property)
7595
{
96+
$map = $this->getSubMap();
97+
7698
switch ($property) {
7799
case 'from':
78-
return $this->getMap()->fromKey;
100+
return $map->fromKey;
79101
case 'to':
80-
return $this->getMap()->toKey;
102+
return $map->toKey;
81103
case 'fromInclusive':
82-
return $this->getMap()->fromInclusive;
104+
return $map->fromInclusive;
83105
case 'toInclusive':
84-
return $this->getMap()->toInclusive;
106+
return $map->toInclusive;
85107
case 'set':
86108
return $this->set;
87109
default:
@@ -103,18 +125,20 @@ public function __get($property)
103125
*/
104126
public function __set($property, $value)
105127
{
128+
$map = $this->getSubMap();
129+
106130
switch ($property) {
107131
case 'from':
108-
$this->getMap()->fromKey = $value;
132+
$map->fromKey = $value;
109133
break;
110134
case 'to':
111-
$this->getMap()->toKey = $value;
135+
$map->toKey = $value;
112136
break;
113137
case 'fromInclusive':
114-
$this->getMap()->fromInclusive = $value;
138+
$map->fromInclusive = $value;
115139
break;
116140
case 'toInclusive':
117-
$this->getMap()->toInclusive = $value;
141+
$map->toInclusive = $value;
118142
break;
119143
default:
120144
throw new \RuntimeException('Undefined property');
@@ -134,18 +158,20 @@ public function __set($property, $value)
134158
*/
135159
public function __unset($property)
136160
{
161+
$map = $this->getSubMap();
162+
137163
switch ($property) {
138164
case 'from':
139-
unset($this->getMap()->fromKey);
165+
unset($map->fromKey);
140166
break;
141167
case 'to':
142-
unset($this->getMap()->toKey);
168+
unset($map->toKey);
143169
break;
144170
case 'fromInclusive':
145-
unset($this->getMap()->fromInclusive);
171+
unset($map->fromInclusive);
146172
break;
147173
case 'toInclusive':
148-
unset($this->getMap()->toInclusive);
174+
unset($map->toInclusive);
149175
break;
150176
default:
151177
throw new \RuntimeException('Undefined property');
@@ -163,15 +189,17 @@ public function __unset($property)
163189
*/
164190
public function __isset($property)
165191
{
192+
$map = $this->getSubMap();
193+
166194
switch ($property) {
167195
case 'from':
168-
return isset($this->getMap()->fromKey);
196+
return isset($map->fromKey);
169197
case 'to':
170-
return isset($this->getMap()->toKey);
198+
return isset($map->toKey);
171199
case 'fromInclusive':
172-
return isset($this->getMap()->fromInclusive);
200+
return isset($map->fromInclusive);
173201
case 'toInclusive':
174-
return isset($this->getMap()->toInclusive);
202+
return isset($map->toInclusive);
175203
default:
176204
return false;
177205
}

‎src/SortedCollection/TreeMap.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function predecessor($element)
151151
{
152152
$predecessor = $element->predecessor;
153153

154-
if ($predecessor) {
154+
if ($predecessor !== null) {
155155
return $predecessor;
156156
} else {
157157
throw new \OutOfBoundsException('Predecessor element unexisting');
@@ -173,7 +173,7 @@ public function successor($element)
173173
{
174174
$successor = $element->successor;
175175

176-
if ($successor) {
176+
if ($successor !== null) {
177177
return $successor;
178178
} else {
179179
throw new \OutOfBoundsException('Successor element unexisting');

‎src/SortedCollection/TreeNode.php‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
*
2222
* @since 1.0.0
2323
*
24-
* @property-read TreeNode $first The first node of the tree
25-
* @property-read TreeNode $last The last node of the tree
26-
* @property-read TreeNode $predecessor The predecessor node
27-
* @property-read TreeNode $successor The successor node
28-
* @property-read mixed $key The key
29-
* @property-read integer $count The number of elements in the tree
24+
* @property-read TreeNode $first The first node of the tree
25+
* @property-read TreeNode $last The last node of the tree
26+
* @property-read TreeNode|null $predecessor The predecessor node
27+
* @property-read TreeNode|null $successor The successor node
28+
* @property-read mixed $key The key
29+
* @property-read integer $count The number of elements in the tree
3030
*/
3131
class TreeNode implements \Countable
3232
{
@@ -40,14 +40,14 @@ class TreeNode implements \Countable
4040
private $information = 0;
4141

4242
/**
43-
* @var TreeNode Left|Predecessor node
43+
* @var TreeNode|null Left|Predecessor node
4444
*
4545
* @since 1.0.0
4646
*/
4747
private $left;
4848

4949
/**
50-
* @var TreeNode Right|Successor node
50+
* @var TreeNode|null Right|Successor node
5151
*
5252
* @since 1.0.0
5353
*/
@@ -170,7 +170,7 @@ public function last()
170170
/**
171171
* Get the predecessor
172172
*
173-
* @return TreeNode the predecessor node
173+
* @return TreeNode|null 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 TreeNode the successor node
195+
* @return TreeNode|null the successor node
196196
*
197197
* @since 1.0.0
198198
*/

0 commit comments

Comments
 (0)