1 | <?php |
||
10 | class Manager implements Contracts\Manager |
||
11 | { |
||
12 | protected $meta; |
||
13 | protected $schema; |
||
14 | protected $client; |
||
15 | protected $repositores = []; |
||
16 | |||
17 | 65 | public function __construct(TarantoolClient $client) |
|
21 | |||
22 | /** |
||
23 | * @return Contracts\Repository|Contracts\Entity |
||
24 | */ |
||
25 | 64 | public function get($type, $id = null) |
|
26 | { |
||
27 | 64 | if (!array_key_exists($type, $this->repositores)) { |
|
28 | 64 | $this->repositores[$type] = new Repository($this->getMeta()->get($type)); |
|
29 | 64 | } |
|
30 | |||
31 | 64 | if ($id) { |
|
32 | 12 | return $this->repositores[$type]->find($id); |
|
33 | } |
||
34 | |||
35 | 64 | return $this->repositores[$type]; |
|
36 | } |
||
37 | |||
38 | 2 | public function forgetRepository($type) |
|
39 | { |
||
40 | 2 | if (array_key_exists($type, $this->repositores)) { |
|
41 | 1 | unset($this->repositores[$type]); |
|
42 | 1 | } |
|
43 | 2 | } |
|
44 | |||
45 | /** |
||
46 | * @return Contracts\Entity |
||
47 | */ |
||
48 | 64 | public function save(Contracts\Entity $entity) |
|
52 | |||
53 | /** |
||
54 | * @return Contracts\Entity |
||
55 | */ |
||
56 | 6 | public function remove(Contracts\Entity $entity) |
|
60 | |||
61 | 64 | public function findRepository(Contracts\Entity $entity) |
|
62 | { |
||
63 | 64 | foreach ($this->repositores as $repository) { |
|
64 | 64 | if ($repository->knows($entity)) { |
|
65 | 64 | return $repository; |
|
66 | } |
||
67 | 64 | } |
|
68 | 1 | throw new LogicException('Entity should be related with repository'); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return Contracts\Entity |
||
73 | */ |
||
74 | 64 | public function create($type, $data = null) |
|
78 | |||
79 | /** |
||
80 | * @return Client |
||
81 | */ |
||
82 | 65 | public function getClient() |
|
86 | |||
87 | /** |
||
88 | * @return Schema |
||
89 | */ |
||
90 | 64 | public function getSchema() |
|
91 | { |
||
92 | 64 | if (!isset($this->schema)) { |
|
93 | 64 | $this->schema = new Schema($this->getClient()); |
|
94 | 64 | } |
|
95 | |||
96 | 64 | return $this->schema; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param Schema |
||
101 | */ |
||
102 | 1 | public function setSchema(Contracts\Schema $schema) |
|
109 | |||
110 | /** |
||
111 | * @return Meta |
||
112 | */ |
||
113 | 64 | public function getMeta() |
|
114 | { |
||
115 | 64 | if (!isset($this->meta)) { |
|
116 | 64 | $this->meta = new Meta($this); |
|
117 | 64 | } |
|
118 | |||
119 | 64 | return $this->meta; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param Meta |
||
124 | */ |
||
125 | 1 | public function setMeta(Contracts\Meta $meta) |
|
132 | } |
||
133 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: