Viddler::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.2
cc 4
eloc 3
nc 8
nop 2
crap 4
1
<?php
2
3
namespace LeadThread\Viddler\Api;
4
5
/**
6
 * Viddler PHP Wrapper for Viddler's API
7
 * Documentation: http://developers.viddler.com
8
 * Version 4.2 (18Jul2014)
9
 */
10
class Viddler
11
{
12
    public $apiKey = null;
13
    public $secure  = false;
14
    protected $requestClass = Request::class;
15
16
    // Constructor
17 9
    public function __construct($apiKey = null, $secure = false)
18
    {
19 9
        $this->apiKey = (! empty($apiKey)) ? $apiKey : $this->apiKey;
20 9
        $this->secure = (! is_null($secure) && is_bool($secure)) ? $secure : $this->secure;
21 9
    }
22
23
    /**
24
     * Can be called like such:
25
     * $__api = new Viddler_API("YOUR KEY");
26
     * $array = $__api->viddler_users_getProfile(array("user"=>"phpfunk"));
27
     */
28 6
    public function __call($method, $args)
29
    {
30 6
        return self::call($method, $args);
31
    }
32
33
    /**
34
     * Format the Method
35
     * Accepted Formats:
36
     *
37
     * $viddler->viddler_users_auth();
38
     */
39 6
    protected function call($method, $args)
40
    {
41 6
        $method = str_replace("_", ".", $method);
42 6
        $request = new $this->requestClass($this->apiKey, $method, $args, $this->secure);
43 6
        return $request->execute();
44
    }
45
}
46