Endpoint::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Raidros\Storer;
4
5
class Endpoint
6
{
7
    protected $method;
8
    protected $uri;
9
    protected $transformers;
10
11
    /**
12
     * Setup a new endpoint.
13
     *
14
     * @param string
15
     * @param string
16
     */
17 15
    public function __construct($method, $uri)
18
    {
19 15
        $this->method = $method;
20 15
        $this->uri = $uri;
21 15
        $this->transformers = [];
22 15
    }
23
24
    /**
25
     * Add a transformer to a endpoint response.
26
     *
27
     * @param Raidros\Storer\Transformer $transformer
28
     * @param string                     $type
29
     *
30
     * @return Raidros\Storer\Transformer
31
     */
32 6
    public function transformer(Transformer $transformer, $type = 'response')
33
    {
34 6
        $this->transformers[$type] = $transformer;
35
36 6
        return $this;
37
    }
38
39
    /**
40
     * get the endpoint method.
41
     *
42
     * @return string
43
     */
44 15
    public function getMethod()
45
    {
46 15
        return strtoupper($this->method);
47
    }
48
49
    /**
50
     * get the endpoint uri.
51
     *
52
     * @param array $data
53
     *
54
     * @return string
55
     */
56 15
    public function getUri($data = null)
57
    {
58 15
        if (isset($data['uriData'])) {
59
            $this->uri = str_replace('{params}', implode('/', $data['uriData']), $this->uri);
60
        }
61
62 15
        return $this->uri;
63
    }
64
65
    /**
66
     * Get the endpoint transformer.
67
     *
68
     * @return Raidros\Storer\Transformer
69
     */
70 15
    public function getTransformer($type = 'response')
71
    {
72 15
        return isset($this->transformers[$type]) ? $this->transformers[$type] : null;
73
    }
74
}
75