Completed
Push — master ( ca1131...42ef77 )
by Woody
03:33
created

Directory::assertValid()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.2
ccs 7
cts 7
cp 1
nc 3
cc 4
eloc 5
nop 1
crap 4
1
<?php
2
3
namespace Equip;
4
5
use Equip\Action;
6
use Equip\Compatibility\StructureWithDataAlias;
7
use Equip\Exception\DirectoryException;
8
use Equip\Structure\Dictionary;
9
10
class Directory extends Dictionary
11
{
12
    use StructureWithDataAlias;
13
14
    const GET = 'GET';
15
    const POST = 'POST';
16
    const PUT = 'PUT';
17
    const PATCH = 'PATCH';
18
    const HEAD = 'HEAD';
19
    const DELETE = 'DELETE';
20
    const OPTIONS = 'OPTIONS';
21
22
    /**
23
     * @param string $path
24
     * @param string|Action $domainOrAction
25
     *
26
     * @return static
27
     */
28 3
    public function get($path, $domainOrAction)
29
    {
30 3
        return $this->action(self::GET, $path, $domainOrAction);
31
    }
32
33
    /**
34
     * @param string $path
35
     * @param string|Action $domainOrAction
36
     *
37
     * @return static
38
     */
39 1
    public function post($path, $domainOrAction)
40
    {
41 1
        return $this->action(self::POST, $path, $domainOrAction);
42
    }
43
44
    /**
45
     * @param string $path
46
     * @param string|Action $domainOrAction
47
     *
48
     * @return static
49
     */
50 1
    public function put($path, $domainOrAction)
51
    {
52 1
        return $this->action(self::PUT, $path, $domainOrAction);
53
    }
54
55
    /**
56
     * @param string $path
57
     * @param string|Action $domainOrAction
58
     *
59
     * @return static
60
     */
61 1
    public function patch($path, $domainOrAction)
62
    {
63 1
        return $this->action(self::PATCH, $path, $domainOrAction);
64
    }
65
66
    /**
67
     * @param string $path
68
     * @param string|Action $domainOrAction
69
     *
70
     * @return static
71
     */
72 1
    public function head($path, $domainOrAction)
73
    {
74 1
        return $this->action(self::HEAD, $path, $domainOrAction);
75
    }
76
77
    /**
78
     * @param string $path
79
     * @param string|Action $domainOrAction
80
     *
81
     * @return static
82
     */
83 1
    public function delete($path, $domainOrAction)
84
    {
85 1
        return $this->action(self::DELETE, $path, $domainOrAction);
86
    }
87
88
    /**
89
     * @param string $path
90
     * @param string|Action $domainOrAction
91
     *
92
     * @return static
93
     */
94 1
    public function options($path, $domainOrAction)
95
    {
96 1
        return $this->action(self::OPTIONS, $path, $domainOrAction);
97
    }
98
99
    /**
100
     * @param string $method
101
     * @param string $path
102
     * @param string|Action $domainOrAction
103
     *
104
     * @return static
105
     */
106 11
    public function action($method, $path, $domainOrAction)
107
    {
108 11
        if ($domainOrAction instanceof Action) {
109 10
            $action = $domainOrAction;
110 10
        } else {
111 1
            $action = new Action($domainOrAction);
112
        }
113
114 11
        return $this->withValue("$method $path", $action);
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $method instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
115
    }
116
117
    /**
118
     * @inheritDoc
119
     *
120
     * @throws DirectoryException If a value is not an Action instance
121
     */
122 14
    protected function assertValid(array $data)
123
    {
124 14
        parent::assertValid($data);
125
126 14
        foreach ($data as $value) {
127 12
            if (!is_object($value) || !$value instanceof Action) {
128 1
                throw DirectoryException::invalidEntry($value);
129
            }
130 14
        }
131 14
    }
132
}
133