HasApiProvider::getApiProvider()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Osnova\Support\Traits;
4
5
use Osnova\Api\ApiProvider;
6
use Osnova\Exceptions\ApiProviderDoesNotExistsException;
7
8
trait HasApiProvider
9
{
10
    /**
11
     * Determines whether the current object has ApiProvider instance.
12
     *
13
     * @return bool
14
     */
15
    public function hasApiProvider()
16
    {
17
        return !is_null($this->apiProvider);
18
    }
19
20
    /**
21
     * Get the ApiProvider instance.
22
     *
23
     * @throws ApiProviderDoesNotExistsException
24
     *
25
     * @return ApiProvider
26
     */
27
    public function getApiProvider()
28
    {
29
        if (!$this->hasApiProvider()) {
30
            throw new ApiProviderDoesNotExistsException(
31
                'Current instance of the "'.get_class($this).'" class has no ApiProvider instance!'
32
            );
33
        }
34
35
        return $this->apiProvider;
36
    }
37
}
38