Total Complexity | 5 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | trait HasClient |
||
10 | { |
||
11 | /** |
||
12 | * Client instance |
||
13 | * |
||
14 | * @var Client |
||
15 | */ |
||
16 | protected $client; |
||
17 | |||
18 | /** |
||
19 | * Get the Client instance |
||
20 | * |
||
21 | * If there is no client assigned on the model, but it has a parent, then try to get the parent's client |
||
22 | * |
||
23 | * @return Client |
||
24 | * @throws NoClientException |
||
25 | */ |
||
26 | 121 | public function getClient(): Client |
|
27 | { |
||
28 | 121 | if (!$this->client && $this->parentModel) { |
|
29 | 1 | $this->client = $this->parentModel->getClient(); |
|
30 | } |
||
31 | |||
32 | 121 | if ($this->client) { |
|
33 | 120 | return $this->client; |
|
34 | } |
||
35 | |||
36 | 1 | throw new NoClientException(); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Set the client instance |
||
41 | * |
||
42 | * @param Client $client |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | 204 | public function setClient(?Client $client): self |
|
51 | } |
||
52 | } |
||
53 |