Completed
Push — master ( 2bc6aa...f63f47 )
by Indra
04:48
created

Service::hasErrorShape()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace IndraGunawan\RestService;
4
5
use IndraGunawan\RestService\Parser\SpecificationParser;
6
7
class Service implements ServiceInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $service;
13
14
    /**
15
     * @param string $specificationFile
16
     * @param array  $defaults
17
     * @param string $cacheDir
18
     * @param bool   $debug
19
     *
20
     * @throws \IndraGunawan\RestService\Exception\InvalidSpecificationException
21
     */
22 5
    public function __construct($specificationFile, array $defaults = [], $cacheDir = null, $debug = false)
23
    {
24 5
        $parser = new SpecificationParser();
25 5
        $this->service = $parser->parse($specificationFile, $defaults ?: [], $cacheDir, $debug);
26 5
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function getName()
32
    {
33 1
        return $this->service['name'];
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function getEndpoint()
40
    {
41 1
        return $this->service['endpoint'];
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function getOperations()
48
    {
49 1
        return $this->service['operations'];
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function hasOperation($name)
56
    {
57 1
        return array_key_exists($name, $this->getOperations());
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function getOperation($name)
64
    {
65 1
        if ($this->hasOperation($name)) {
66 1
            return $this->getOperations()[$name];
67
        }
68
69 1
        return;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 1
    public function getShapes()
76
    {
77 1
        return $this->service['shapes'];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 1
    public function hasShape($name)
84
    {
85 1
        return array_key_exists($name, $this->getShapes());
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 1
    public function getShape($name)
92
    {
93 1
        if ($this->hasShape($name)) {
94 1
            return $this->getShapes()[$name];
95
        }
96
97 1
        return;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 1
    public function getErrorShapes()
104
    {
105 1
        return $this->service['errorShapes'];
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 1
    public function hasErrorShape($name)
112
    {
113 1
        return array_key_exists($name, $this->getErrorShapes());
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119 1
    public function getErrorShape($name)
120
    {
121 1
        if ($this->hasErrorShape($name)) {
122 1
            return $this->getErrorShapes()[$name];
123
        }
124
125 1
        return;
126
    }
127
}
128