1 | <?php |
||
15 | class Repository |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var Mapper |
||
20 | */ |
||
21 | protected $mapper; |
||
22 | |||
23 | /** |
||
24 | * @var DbDriverInterface |
||
25 | */ |
||
26 | protected $dbDriver = null; |
||
27 | |||
28 | /** |
||
29 | * Repository constructor. |
||
30 | * @param DbDriverInterface $dbDataset |
||
31 | * @param Mapper $mapper |
||
32 | */ |
||
33 | 8 | public function __construct(DbDriverInterface $dbDataset, Mapper $mapper) |
|
38 | |||
39 | /** |
||
40 | * @return Mapper |
||
41 | */ |
||
42 | public function getMapper() |
||
46 | |||
47 | /** |
||
48 | * @return DbDriverInterface |
||
49 | */ |
||
50 | 8 | protected function getDbDriver() |
|
54 | |||
55 | /** |
||
56 | * @param array|string $id |
||
57 | * @return mixed|null |
||
58 | */ |
||
59 | 5 | public function get($id) |
|
69 | |||
70 | /** |
||
71 | * @param array $id |
||
72 | * @return mixed|null |
||
73 | */ |
||
74 | 1 | public function delete($id) |
|
83 | |||
84 | /** |
||
85 | * @param $query |
||
86 | * @return bool |
||
87 | */ |
||
88 | 2 | public function deleteByQuery($query) |
|
98 | |||
99 | /** |
||
100 | * @param string $filter |
||
101 | * @param array $params |
||
102 | * @param bool $forUpdate |
||
103 | * @return array |
||
104 | */ |
||
105 | 5 | public function getByFilter($filter, array $params, $forUpdate = false) |
|
106 | { |
||
107 | 5 | $query = new Query(); |
|
108 | 5 | $query->table($this->mapper->getTable()) |
|
109 | 5 | ->where($filter, $params); |
|
110 | |||
111 | 5 | if ($forUpdate) { |
|
112 | $query->forUpdate(); |
||
113 | } |
||
114 | |||
115 | 5 | return $this->getByQuery($query); |
|
116 | 1 | } |
|
117 | |||
118 | /** |
||
119 | * @param Query $query |
||
120 | * @param Mapper[] $mapper |
||
121 | * @return array |
||
122 | */ |
||
123 | 8 | public function getByQuery(Query $query, array $mapper = []) |
|
147 | |||
148 | /** |
||
149 | * @param mixed $instance |
||
150 | */ |
||
151 | 2 | public function save($instance) |
|
167 | |||
168 | /** |
||
169 | * @param Query $query |
||
170 | * @param array $params |
||
171 | * @return int |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | 1 | protected function insert(Query $query, array $params) |
|
180 | |||
181 | /** |
||
182 | * @param Query $query |
||
183 | * @param array $params |
||
184 | * @throws \Exception |
||
185 | */ |
||
186 | 1 | protected function update(Query $query, array $params) |
|
195 | } |
||
196 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.