Endpoint   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 88.24%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 7
c 5
b 2
f 0
lcom 3
cbo 0
dl 0
loc 70
ccs 15
cts 17
cp 0.8824
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A transformer() 0 6 1
A getMethod() 0 4 1
A getUri() 0 8 2
A getTransformer() 0 4 2
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