Completed
Pull Request — master (#1)
by Woody
27:07 queued 01:07
created

Directory   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 13
c 3
b 1
f 0
lcom 1
cbo 3
dl 0
loc 121
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 4
A get() 0 4 1
A post() 0 4 1
A put() 0 4 1
A patch() 0 4 1
A head() 0 4 1
A delete() 0 4 1
A options() 0 4 1
A action() 0 10 2
1
<?php
2
3
namespace Equip;
4
5
use Equip\Action;
6
use Destrukt\Dictionary;
7
use Equip\Exception\DirectoryException;
8
9
class Directory extends Dictionary
10
{
11
    const GET = 'GET';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
12
    const POST = 'POST';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
13
    const PUT = 'PUT';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
14
    const PATCH = 'PATCH';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
15
    const HEAD = 'HEAD';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
16
    const DELETE = 'DELETE';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
17
    const OPTIONS = 'OPTIONS';
18
19
    /**
20
     * @inheritDoc
21
     *
22
     * @throws DirectoryException If a value is not an Action instance
23
     */
24 12
    public function validate(array $data)
25
    {
26 12
        parent::validate($data);
27
28 12
        foreach ($data as $value) {
29 12
            if (!is_object($value) || !$value instanceof Action) {
30 12
                throw DirectoryException::invalidEntry($value);
31
            }
32
        }
33 11
    }
34
35
    /**
36
     * @param string $path
37
     * @param string|Action $domainOrAction
38
     *
39
     * @return static
40
     */
41 3
    public function get($path, $domainOrAction)
42
    {
43 3
        return $this->action(self::GET, $path, $domainOrAction);
44
    }
45
46
    /**
47
     * @param string $path
48
     * @param string|Action $domainOrAction
49
     *
50
     * @return static
51
     */
52 1
    public function post($path, $domainOrAction)
53
    {
54 1
        return $this->action(self::POST, $path, $domainOrAction);
55
    }
56
57
    /**
58
     * @param string $path
59
     * @param string|Action $domainOrAction
60
     *
61
     * @return static
62
     */
63 1
    public function put($path, $domainOrAction)
64
    {
65 1
        return $this->action(self::PUT, $path, $domainOrAction);
66
    }
67
68
    /**
69
     * @param string $path
70
     * @param string|Action $domainOrAction
71
     *
72
     * @return static
73
     */
74 1
    public function patch($path, $domainOrAction)
75
    {
76 1
        return $this->action(self::PATCH, $path, $domainOrAction);
77
    }
78
79
    /**
80
     * @param string $path
81
     * @param string|Action $domainOrAction
82
     *
83
     * @return static
84
     */
85 1
    public function head($path, $domainOrAction)
86
    {
87 1
        return $this->action(self::HEAD, $path, $domainOrAction);
88
    }
89
90
    /**
91
     * @param string $path
92
     * @param string|Action $domainOrAction
93
     *
94
     * @return static
95
     */
96 1
    public function delete($path, $domainOrAction)
97
    {
98 1
        return $this->action(self::DELETE, $path, $domainOrAction);
99
    }
100
101
    /**
102
     * @param string $path
103
     * @param string|Action $domainOrAction
104
     *
105
     * @return static
106
     */
107 1
    public function options($path, $domainOrAction)
108
    {
109 1
        return $this->action(self::OPTIONS, $path, $domainOrAction);
110
    }
111
112
    /**
113
     * @param string $method
114
     * @param string $path
115
     * @param string|Action $domainOrAction
116
     *
117
     * @return static
118
     */
119 11
    public function action($method, $path, $domainOrAction)
120
    {
121 11
        if ($domainOrAction instanceof Action) {
122 10
            $action = $domainOrAction;
123
        } else {
124 1
            $action = new Action($domainOrAction);
125
        }
126
127 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...
128
    }
129
}
130