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