Completed
Push — master ( 819036...d88ff8 )
by Joschi
08:13
created

ServerFacade::buildDefaultDateRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
ccs 31
cts 31
cp 1
rs 9.5797
cc 1
eloc 42
nc 1
nop 2
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * apparat-server
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Server
8
 * @subpackage  Apparat\Server\Ports
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Server\Ports\Facade;
38
39
use Apparat\Kernel\Ports\Kernel;
40
use Apparat\Object\Ports\Object;
41
use Apparat\Server\Domain\Contract\RouteInterface;
42
use Apparat\Server\Infrastructure\Model\Server;
43
use Psr\Http\Message\ResponseInterface;
44
use Psr\Http\Message\ServerRequestInterface;
45
46
/**
47
 * Server facade
48
 *
49
 * @package Apparat\Server\Ports
50
 */
51
class ServerFacade
52
{
53
    /**
54
     * Server instance
55
     *
56
     * @var \Apparat\Server\Domain\Model\Server
57
     */
58
    protected static $server = null;
59
60
    /**
61
     * Register the default routes for a particular repository
62
     *
63
     * @param string $repositoryPath Repository path
64
     * @param bool $enable Enable / disable default routes
65
     * @api
66
     */
67 1
    public static function registerRepositoryDefaultRoutes($repositoryPath = '', $enable = true)
68
    {
69 1
        self::getServer()->registerRepositoryDefaultRoutes($repositoryPath, $enable);
70 1
    }
71
72
    /**
73
     * Register a route
74
     *
75
     * @param RouteInterface $route
76
     * @api
77
     */
78 1
    public static function registerRoute(RouteInterface $route)
79
    {
80 1
        self::getServer()->registerRoute($route);
81 1
    }
82
83
    /**
84
     * Dispatch a request
85
     *
86
     * @param ServerRequestInterface $request
87
     * @return ResponseInterface $response
88
     */
89 2
    public static function dispatchRequest(ServerRequestInterface $request)
90
    {
91 2
        return self::getServer()->dispatchRequest($request);
92
    }
93
94
    /**
95
     * Create and return the server instance
96
     *
97
     * @return Server Server instance
98
     */
99 2
    protected static function getServer()
100
    {
101 2
        if (self::$server === null) {
102 1
            self::$server = Kernel::create(Server::class);
103 1
        }
104 2
        return self::$server;
105
    }
106
}
107