Skip to content

Commit 3b45692

Browse files
committed
🚨 Reduce complexity
1 parent 005e20a commit 3b45692

2 files changed

Lines changed: 310 additions & 137 deletions

File tree

‎src/SortedCollection/AbstractMap.php‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,26 @@ abstract class AbstractMap implements SortedMap
4848
*/
4949
public function __get($property)
5050
{
51-
switch ($property) {
52-
case 'comparator':
53-
return $this->comparator();
54-
case 'firstKey':
55-
return $this->firstKey();
56-
case 'lastKey':
57-
return $this->lastKey();
58-
case 'firstValue':
59-
return $this->firstValue();
60-
case 'lastValue':
61-
return $this->lastValue();
62-
case 'first':
63-
return $this->first();
64-
case 'last':
65-
return $this->last();
66-
case 'keys':
67-
return $this->keys();
68-
case 'values':
69-
return $this->values();
70-
case 'count':
71-
return $this->count();
72-
default:
73-
throw new \RuntimeException('Undefined property');
51+
$map = array(
52+
'comparator' => 'comparator',
53+
'firstKey' => 'firstKey',
54+
'lastKey' => 'lastKey',
55+
'firstValue' => 'firstValue',
56+
'lastValue' => 'lastValue',
57+
'first' => 'first',
58+
'last' => 'last',
59+
'keys' => 'keys',
60+
'values' => 'values',
61+
'count' => 'count',
62+
);
63+
64+
if (!isset($map[$property])) {
65+
throw new \RuntimeException('Undefined property');
7466
}
67+
68+
$method = $map[$property];
69+
70+
return $this->$method();
7571
}
7672

7773
/**

0 commit comments

Comments
 (0)