UpDownBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2019 - present
4
 * laravel-updown - UpDownBuilder.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 15/2/2019
8
 * MIT license: https://github.com/biscolab/laravel-updown/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\LaravelUpDown;
12
13
use Biscolab\UpDown\Fields\UpDownRequestFields;
14
use Biscolab\UpDown\UpDown;
15
16
class UpDownBuilder
17
{
18
19
    /**
20
     * @var UpDown
21
     */
22
    protected $updown;
23
24
    /**
25
     * UpDownBuilder constructor.
26
     *
27
     * @param string $api_key
28
     */
29 7
    public function __construct(string $api_key)
30
    {
31
32 7
        $this->updown = UpDown::init([
33 7
            UpDownRequestFields::API_KEY => $api_key
34
        ]);
35
36 7
    }
37
38
    /**
39
     * @return UpDown
40
     */
41 1
    public function getUpDown(): UpDown {
42 1
        return $this->updown;
43
    }
44
45
    /**
46
     * @param $name
47
     * @param $arguments
48
     *
49
     * @return mixed
50
     */
51 5
    public function __call($name, $arguments)
52
    {
53 5
        $class_name = 'Biscolab\UpDown\Objects\\' . $name;
54
55 5
        if(class_exists($class_name)) {
56
57 5
            if(is_array($arguments) && !empty(current($arguments))) {
58
                $arguments = current($arguments);
59
            }
60 5
            return new $class_name($arguments);
61
        }
62
    }
63
64
}