1 | <?php |
||
9 | class Repository implements Contracts\Repository |
||
10 | { |
||
11 | protected $type; |
||
12 | protected $entities = []; |
||
13 | protected $keyMap = []; |
||
14 | |||
15 | protected $magicMethodRules = [ |
||
16 | 'by' => false, |
||
17 | 'firstBy' => true, |
||
18 | 'oneBy' => true |
||
19 | ]; |
||
20 | |||
21 | 4 | public function __construct(Contracts\Type $type) |
|
25 | |||
26 | 4 | public function make(array $data = null) |
|
30 | |||
31 | 4 | public function __call($method, $arguments) |
|
43 | |||
44 | 4 | public function find($params = [], $oneItem = false) |
|
45 | { |
||
46 | 4 | if(is_int($params)) { |
|
47 | $params = [ |
||
48 | 'id' => $params |
||
49 | 1 | ]; |
|
50 | 1 | $oneItem = true; |
|
51 | 1 | } |
|
52 | |||
53 | 4 | $fields = array_keys($params); |
|
54 | 4 | $values = []; |
|
55 | |||
56 | 4 | sort($fields); |
|
57 | 4 | foreach($fields as $field) { |
|
58 | 4 | $values[] = $params[$field]; |
|
59 | 4 | } |
|
60 | |||
61 | 4 | $index = implode('_', $fields); |
|
62 | |||
63 | 4 | if(!$index) { |
|
64 | 1 | $index = 'id'; |
|
65 | 1 | } |
|
66 | |||
67 | 4 | $space = $this->type->getManager()->getClient()->getSpace($this->type->getName()); |
|
68 | 4 | $data = $space->select($values, $index); |
|
69 | |||
70 | |||
71 | 4 | $result = []; |
|
72 | 4 | if (!empty($data->getData())) { |
|
73 | 4 | foreach ($data->getData() as $tuple) { |
|
74 | 4 | $data = $this->type->decode($tuple); |
|
75 | 4 | if (isset($data['id']) && array_key_exists($data['id'], $this->keyMap)) { |
|
76 | 4 | $entity = $this->entities[$this->keyMap[$data['id']]]; |
|
77 | 4 | $entity->update($data); |
|
78 | 4 | } else { |
|
79 | 4 | $entity = new Entity($data); |
|
80 | 4 | $this->register($entity); |
|
81 | } |
||
82 | 4 | if ($oneItem) { |
|
83 | 4 | return $entity; |
|
84 | } |
||
85 | 4 | $result[] = $entity; |
|
86 | 4 | } |
|
87 | 4 | } |
|
88 | 4 | if (!$oneItem) { |
|
89 | 4 | return $result; |
|
90 | } |
||
91 | 4 | } |
|
92 | |||
93 | /** |
||
94 | * @return Entity |
||
95 | */ |
||
96 | 4 | public function knows(Contracts\Entity $entity) |
|
100 | |||
101 | 4 | public function save(Contracts\Entity $entity) |
|
138 | |||
139 | 4 | protected function register(Contracts\Entity $entity) |
|
149 | |||
150 | 4 | protected function generateId(Contracts\Entity $entity) |
|
175 | } |
||
176 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.