ComicVine::createFormat()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace ComicVine;
4
5
use ComicVine\Api\Connection\Connection;
6
use ComicVine\Api\Connection\CURLConnection;
7
use ComicVine\Api\Connection\GuzzleConnection;
8
use ComicVine\Api\Controllers\ControllerRequest;
9
use ComicVine\Api\RegisterKey;
10
use ComicVine\Api\Response\Type\JsonFormat;
11
use ComicVine\Api\Response\Type\XmlFormat;
12
13
/**
14
 * Static wrapper for ComicVine package.
15
 *
16
 * Class ComicVine
17
 *
18
 * @package grzgajda/comicvine-api
19
 * @author  Grzegorz Gajda <[email protected]>
20
 */
21
class ComicVine
22
{
23
24
    /**
25
     * Api Key
26
     *
27
     * @var string
28
     */
29
    public static $key;
30
31
    /**
32
     * Connection object.
33
     *
34
     * @var \ComicVine\Api\Connection\Connection;
35
     */
36
    public static $conn;
37
38
    /**
39
     * Create instance of RegisterKey.
40
     *
41
     * @param $key
42
     *
43
     * @return \ComicVine\Api\RegisterKey
44
     */
45
    public static function makeApiKey($key)
46
    {
47
        return new RegisterKey($key);
48
    }
49
50
    /**
51
     * Register a key to make connection.
52
     *
53
     * @param \ComicVine\Api\RegisterKey           $key
54
     * @param \ComicVine\Api\Connection\Connection $conn
55
     */
56
    public static function register(RegisterKey $key, Connection $conn = null)
57
    {
58
        self::$key  = $key->getKey();
59
        self::$conn = ($conn === null) ? new GuzzleConnection() : $conn;
60
    }
61
62
    /**
63
     * Make a new controller to start defining request.
64
     *
65
     * @return \ComicVine\Api\Controllers\ControllerRequest
66
     */
67
    public static function make()
68
    {
69
        return new ControllerRequest();
70
    }
71
72
    /**
73
     * Get API KEY.
74
     *
75
     * @return string
76
     */
77
    public static function getKey()
78
    {
79
        return self::$key;
80
    }
81
82
    /**
83
     * Get Connection instance.
84
     *
85
     * @return CURLConnection
86
     */
87
    public static function getConnection()
88
    {
89
        return self::$conn;
90
    }
91
92
    /**
93
     * Simple factory for response format.
94
     *
95
     * @param string $formatType
96
     *
97
     * @return \ComicVine\Api\Response\Type\JsonFormat|\ComicVine\Api\Response\Type\XmlFormat
98
     */
99
    public static function createFormat($formatType = 'json')
100
    {
101
        switch ($formatType) {
102
            case 'json':
103
                return new JsonFormat();
104
            case 'xml':
105
                return new XmlFormat();
106
            default:
107
                return new JsonFormat();
108
        }
109
    }
110
111
}