Server   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 2
dl 0
loc 133
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setGroup() 0 4 1
A onCreate() 0 4 1
A onRead() 0 4 1
A onUpdate() 0 4 1
A onModify() 0 4 1
A onDelete() 0 4 1
A onHelp() 0 4 1
A onTest() 0 4 1
A proxy() 0 9 1
1
<?php
2
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix;
14
15
if (!defined('APIX_START_TIME')) {
16
    define('APIX_START_TIME', microtime(true));
17
}
18
19
class Server extends Main
20
{
21
22
   /**
23
    * POST request handler
24
    *
25
    * @param string $path The path name to match against.
26
    * @param mixed  $to   Callback that returns the response when matched.
27
    * @see  Server::proxy
28
    * @return Controller Provides a fluent interface.
29
    */
30
    public function onCreate($path, $to)
31
    {
32
        return $this->proxy('POST', $path, $to);
33
    }
34
35
    /**
36
     * GET request handler
37
     *
38
     * @param  string     $path The path name to match against.
39
     * @param  mixed      $to   Callback that returns the response when matched.
40
     * @see  Server::proxy
41
     * @return Controller Provides a fluent interface.
42
     */
43
    public function onRead($path, $to)
44
    {
45
        return $this->proxy('GET', $path, $to);
46
    }
47
48
    /**
49
     * PUT request handler
50
     *
51
     * @param  string     $path The path name to match against.
52
     * @param  mixed      $to   Callback that returns the response when matched.
53
     * @see  Server::proxy
54
     * @return Controller Provides a fluent interface.
55
     */
56
    public function onUpdate($path, $to)
57
    {
58
        return $this->proxy('PUT', $path, $to);
59
    }
60
61
    /**
62
     * PATCH request handler
63
     *
64
     * @param  string     $path The path name to match against.
65
     * @param  mixed      $to   Callback that returns the response when matched.
66
     * @see  Server::proxy
67
     * @return Controller Provides a fluent interface.
68
     */
69
    public function onModify($path, $to)
70
    {
71
        return $this->proxy('PATCH', $path, $to);
72
    }
73
74
    /**
75
     * DELETE request handler
76
     *
77
     * @param  string     $path The path name to match against.
78
     * @param  mixed      $to   Callback that returns the response when matched.
79
     * @see  Server::proxy
80
     * @return Controller Provides a fluent interface.
81
     */
82
    public function onDelete($path, $to)
83
    {
84
        return $this->proxy('DELETE', $path, $to);
85
    }
86
87
    /**
88
     * OPTIONS request handler
89
     *
90
     * @param  string     $path The path name to match against.
91
     * @param  mixed      $to   Callback that returns the response when matched.
92
     * @see  Server::proxy
93
     * @return Controller Provides a fluent interface.
94
     */
95
    public function onHelp($path, $to)
96
    {
97
        return $this->proxy('OPTIONS', $path, $to);
98
    }
99
100
    /**
101
     * HEAD request handler
102
     *
103
     * @param  string     $path The path name to match against.
104
     * @param  mixed      $to   Callback that returns the response when matched.
105
     * @see  Server::proxy
106
     * @return Controller Provides a fluent interface.
107
     */
108
    public function onTest($path, $to)
109
    {
110
        return $this->proxy('HEAD', $path, $to);
111
    }
112
113
   /**
114
    * Acts as a shortcut to resources::add.
115
    * @see      Resources::add
116
    *
117
    * @param    string          $method     The HTTP method to match against.
118
    * @param    string          $path       The path name to match against.
119
    * @param    mixed           $to         Callback that returns the response
120
    *                                       when matched.
121
    * @return   Controller
122
    */
123
    protected function proxy($method, $path, \Closure $to)
124
    {
125
        return $this->resources->add($path,
126
            array(
127
                'action' => $to,
128
                'method' => $method
129
            )
130
        );
131
    }
132
133
    // public function setGroupInfo($path, array $docs=null)
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
    // {
135
    //     var_dump( $this->resources); exit;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
136
    //     $this->group = $infos;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
137
    // }
138
139
    /**
140
     * TODO: Test Read from a group.
141
     *
142
     * @param  array  $opts Options are:
0 ignored issues
show
Bug introduced by
There is no parameter named $opts. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
143
     * @return string
144
     * @codeCoverageIgnore
145
     */
146
    public function setGroup($name, array $groupInfo=null)
147
    {
148
        $this->group[$name] = $groupInfo;
0 ignored issues
show
Bug introduced by
The property group does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
149
    }
150
151
}
152