AbstractComponent::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-google-places-library project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace dosamigos\google\places;
13
14
use Da\Google\Places\Client\AbstractClient;
15
use Da\Google\Places\Client\PlaceClient;
16
use Da\Google\Places\Client\SearchClient;
17
use yii\base\Component;
18
use yii\base\InvalidConfigException;
19
20
abstract class AbstractComponent extends Component
21
{
22
    /**
23
     * @var string response format. Can be json or xml.
24
     */
25
    public $format = 'json';
26
    /**
27
     * @var string your API key
28
     */
29
    public $key;
30
    /**
31
     * @var return json results as arrays instead of objects
32
     */
33
    public $forceJsonArrayResponse = false;
34
    /**
35
     * @var AbstractClient|PlaceClient|SearchClient
36
     */
37
    protected $client;
38
39
    /**
40
     * Wraps PlaceClient methods.
41
     *
42
     * @param string $name
43
     * @param array  $params
44
     *
45
     * @return mixed
46
     */
47
    public function __call($name, $params)
48
    {
49
        if (method_exists($this->getClient(), $name)) {
50
            return call_user_func_array([$this->getClient(), $name], $params);
51
        }
52
53
        return parent::__call($name, $params);
54
    }
55
56
    /**
57
     * @throws InvalidConfigException
58
     */
59
    public function init()
60
    {
61
        if (empty($this->key) || empty($this->format)) {
62
            throw new InvalidConfigException('"key" and/or "format" cannot be empty.');
63
        }
64
65
        parent::init();
66
    }
67
68
    /**
69
     * @return AbstractClient|PlaceClient|SearchClient
70
     */
71
    abstract public function getClient();
72
}
73