HasClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setClient() 0 5 1
A getClient() 0 11 4
1
<?php
2
3
namespace Spinen\Halo\Concerns;
4
5
use Spinen\Halo\Api\Client;
6
use Spinen\Halo\Exceptions\NoClientException;
7
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
39
    {
40 114
        $this->client = $client;
41
42 114
        return $this;
43
    }
44
}
45