Api::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * xMDB-API
4
 *
5
 * Copyright © 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
/**
16
 * Created by Marcin Pudełek <[email protected]>
17
 * Date: 29.11.2017
18
 * Time: 16:56
19
 */
20
21
namespace mrcnpdlk\Xmdb;
22
23
24
class Api
25
{
26
    /**
27
     * @var \mrcnpdlk\Xmdb\Api
28
     */
29
    protected static $instance;
30
    /**
31
     * @var \mrcnpdlk\Xmdb\Client
32
     */
33
    private $oClient;
34
35
    /**
36
     * @var \mrcnpdlk\Xmdb\Tmdb
37
     */
38
    private $oTmdbApi;
39
    /**
40
     * @var \mrcnpdlk\Xmdb\Imdb
41
     */
42
    private $oImdbApi;
43
    /**
44
     * @var \mrcnpdlk\Xmdb\Omdb
45
     */
46
    private $oOmdbApi;
47
48
49
    /**
50
     * Api constructor.
51
     *
52
     * @param \mrcnpdlk\Xmdb\Client $oClient
53
     */
54
    protected function __construct(Client $oClient)
55
    {
56
        $this->oClient = $oClient;
57
    }
58
59
    /**
60
     * @param \mrcnpdlk\Xmdb\Client $oClient
61
     *
62
     * @return \mrcnpdlk\Xmdb\Api
63
     */
64
    public static function create(Client $oClient): Api
65
    {
66
        if (null === static::$instance) {
67
            static::$instance = new static($oClient);
68
        }
69
70
        return static::$instance;
71
    }
72
73
    /**
74
     * @return \mrcnpdlk\Xmdb\Api
75
     * @throws \mrcnpdlk\Xmdb\Exception
76
     */
77
    public static function getInstance(): Api
78
    {
79
        if (null === static::$instance) {
80
            throw new Exception(sprintf('First call CREATE method!'));
81
        }
82
83
        return static::$instance;
84
    }
85
86
    /**
87
     * @return \mrcnpdlk\Xmdb\Client
88
     */
89
    public function getClient(): Client
90
    {
91
        return $this->oClient;
92
    }
93
94
    /**
95
     * @return \mrcnpdlk\Xmdb\Imdb
96
     * @throws \mrcnpdlk\Xmdb\Exception
97
     */
98
    public function getImdbApi(): Imdb
99
    {
100
        if (null === $this->oImdbApi) {
101
            $this->oImdbApi = new Imdb($this->oClient);
102
        }
103
104
        return $this->oImdbApi;
105
    }
106
107
    /**
108
     * @return \mrcnpdlk\Xmdb\Omdb
109
     * @throws \mrcnpdlk\Xmdb\Exception
110
     */
111
    public function getOmdbApi(): Omdb
112
    {
113
        if (null === $this->oOmdbApi) {
114
            $this->oOmdbApi = new Omdb($this->oClient);
115
        }
116
117
        return $this->oOmdbApi;
118
    }
119
120
    /**
121
     * @return \mrcnpdlk\Xmdb\Tmdb
122
     * @throws \mrcnpdlk\Xmdb\Exception
123
     */
124
    public function getTmdbApi(): Tmdb
125
    {
126
        if (null === $this->oTmdbApi) {
127
            $this->oTmdbApi = new Tmdb($this->oClient);
128
        }
129
130
        return $this->oTmdbApi;
131
    }
132
}
133