Completed
Push — master ( 169ca3...e1781d )
by Dan
02:52
created
Src/Router/Handler/Handler.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
     /**
71 71
      * Get route (early) middleware pre-response.
72
-     * @return mixed
72
+     * @return string
73 73
      */
74 74
     public function getPreResponse(){
75 75
         return $this->preResponse;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
     /**
79 79
      * Set handler pre-response.
80
-     * @param $string
80
+     * @param string $string
81 81
      * @return $this
82 82
      */
83 83
     public function withPreResponse($string){
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
      * @param $name
57 57
      */
58 58
     public function addName($name = ''){
59
-       $this->name[$name] = $name;
59
+        $this->name[$name] = $name;
60 60
     }
61 61
 
62 62
     /**
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * Set Route name;
48 48
      * @param $name
49 49
      */
50
-    public function setName(array $name = []){
50
+    public function setName(array $name = []) {
51 51
             $this->name = $name;
52 52
     }
53 53
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * Add Route name;
56 56
      * @param $name
57 57
      */
58
-    public function addName($name = ''){
58
+    public function addName($name = '') {
59 59
        $this->name[$name] = $name;
60 60
     }
61 61
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * Get all added names
64 64
      * @return mixed
65 65
      */
66
-    public function getNames(){
66
+    public function getNames() {
67 67
         return (array)$this->name;
68 68
     }
69 69
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * Get route (early) middleware pre-response.
72 72
      * @return mixed
73 73
      */
74
-    public function getPreResponse(){
74
+    public function getPreResponse() {
75 75
         return $this->preResponse;
76 76
     }
77 77
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @param $string
81 81
      * @return $this
82 82
      */
83
-    public function withPreResponse($string){
83
+    public function withPreResponse($string) {
84 84
 
85 85
         $new = clone $this;
86 86
         $new->preResponse = $string;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     public static function __set_state($fields) {
99 99
 
100 100
         $args = [];
101
-        foreach($fields as $key => $value){
101
+        foreach ($fields as $key => $value) {
102 102
             $args[] = $value;
103 103
         }
104 104
 
Please login to merge, or discard this patch.
Tests/Router/Adaptor/FastRouteTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use Ds\Router\Adaptor\FastRoute;
6 6
 use Ds\Router\Handler\Handler;
7 7
 
8
-class MockHandler extends Handler{
8
+class MockHandler extends Handler {
9 9
 
10 10
     function getResponse($vars = [])
11 11
     {
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     public $fastRoute;
23 23
     public $options;
24 24
 
25
-    public function setUp(){
25
+    public function setUp() {
26 26
 
27 27
         $this->options = [
28 28
             'handler' => '\Tests\Ds\Router\Adaptor\MockHandler',
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
         $this->fastRoute = new FastRoute($this->options);
42 42
     }
43 43
 
44
-    public function testFindHandler(){
44
+    public function testFindHandler() {
45 45
         $result = $this->fastRoute->findHandler('default');
46 46
         $this->assertInstanceOf('\Tests\Ds\Router\Adaptor\MockHandler', $result);
47 47
     }
48 48
 
49
-    public function testFindHandlerDefault(){
49
+    public function testFindHandlerDefault() {
50 50
         $result = $this->fastRoute->findHandler('notFound');
51 51
         $this->assertInstanceOf('\Tests\Ds\Router\Adaptor\MockHandler', $result);
52 52
     }
53 53
 
54
-    public function testCheckCacheFileDisabled(){
54
+    public function testCheckCacheFileDisabled() {
55 55
         $expected = true;
56 56
         $actual = $this->fastRoute->checkCacheFile();
57 57
         $this->assertEquals($expected, $actual);
58 58
     }
59 59
 
60
-    public function testGetCachedDispatcher(){}
61
-    public function testMatch(){}
60
+    public function testGetCachedDispatcher() {}
61
+    public function testMatch() {}
62 62
 }
63 63
\ No newline at end of file
Please login to merge, or discard this patch.
Tests/Router/Handler/ClassHandlerTest.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Ds\Router\Handler\ClassHandler;
6 6
 
7
-class TestController{
7
+class TestController {
8 8
 
9 9
     public $resolveValue;
10 10
 
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
         $this->resolveValue = $resolveValue;
14 14
     }
15 15
 
16
-    public function test($var){
17
-        return 'foo'.$var;
16
+    public function test($var) {
17
+        return 'foo' . $var;
18 18
     }
19 19
 }
20 20
 
@@ -29,44 +29,44 @@  discard block
 block discarded – undo
29 29
         $this->controller = 'Tests\Ds\Router\Handler\TestController';
30 30
     }
31 31
 
32
-    public function testConstructController(){
33
-        $reflector = new \ReflectionClass(  $this->handler);
34
-        $prop = $reflector->getProperty( 'controller' );
32
+    public function testConstructController() {
33
+        $reflector = new \ReflectionClass($this->handler);
34
+        $prop = $reflector->getProperty('controller');
35 35
         $prop->setAccessible(true);
36 36
         $this->assertEquals($this->controller, $prop->getValue($this->handler));
37 37
     }
38 38
 
39
-    public function testConstructMethod(){
40
-        $reflector = new \ReflectionClass(  $this->handler);
41
-        $prop = $reflector->getProperty( 'method' );
39
+    public function testConstructMethod() {
40
+        $reflector = new \ReflectionClass($this->handler);
41
+        $prop = $reflector->getProperty('method');
42 42
         $prop->setAccessible(true);
43 43
         $this->assertEquals('test', $prop->getValue($this->handler));
44 44
     }
45 45
 
46
-    public function testConstructPreResponse(){
47
-        $reflector = new \ReflectionClass(  $this->handler);
48
-        $prop = $reflector->getProperty( 'preResponse' );
46
+    public function testConstructPreResponse() {
47
+        $reflector = new \ReflectionClass($this->handler);
48
+        $prop = $reflector->getProperty('preResponse');
49 49
         $prop->setAccessible(true);
50
-        $this->assertEquals($this->controller.'::test', $prop->getValue($this->handler));
50
+        $this->assertEquals($this->controller . '::test', $prop->getValue($this->handler));
51 51
     }
52 52
 
53
-    public function testResolveClassInstance(){
53
+    public function testResolveClassInstance() {
54 54
         $handler = $this->handler->resolve();
55 55
         $reflector = new \ReflectionClass($handler);
56
-        $prop = $reflector->getProperty( 'resolved' );
56
+        $prop = $reflector->getProperty('resolved');
57 57
         $prop->setAccessible(true);
58 58
         $this->assertInstanceOf($this->controller, $prop->getValue($handler));
59 59
     }
60 60
 
61 61
 
62
-    public function testGetResponse(){
62
+    public function testGetResponse() {
63 63
         $expected = 'foobar';
64 64
         $this->handler->resolve();
65 65
         $actual = $this->handler->getResponse('bar');
66 66
         $this->assertEquals($expected, $actual);
67 67
     }
68 68
 
69
-    public function testGetResponseException(){
69
+    public function testGetResponseException() {
70 70
         $this->setExpectedException('Exception');
71 71
         $this->handler->getResponse('bar');
72 72
     }
Please login to merge, or discard this patch.
Tests/Router/Handler/HandlerTest.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 use Ds\Router\Handler\Handler;
12 12
 
13
-class TestHandler extends Handler{
13
+class TestHandler extends Handler {
14 14
 
15 15
     public $preResponse = 'pre-response';
16 16
     public $name = ['foo' => 'foo'];
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         $this->handler = new TestHandler();
45 45
     }
46 46
 
47
-    public function testSetName(){
47
+    public function testSetName() {
48 48
         $expected = ['bar'];
49 49
         $this->handler->setName($expected);
50 50
 
@@ -53,20 +53,20 @@  discard block
 block discarded – undo
53 53
         $reflectionProperty->setAccessible(true);
54 54
         $actual = $reflectionProperty->getValue($this->handler);
55 55
 
56
-        $this->assertEquals($expected,$actual);
56
+        $this->assertEquals($expected, $actual);
57 57
     }
58 58
 
59
-    public function testAddName(){
59
+    public function testAddName() {
60 60
         $expected = 'foo';
61 61
         $this->handler->addName($expected);
62 62
         $reflectionClass = new \ReflectionClass('Tests\Ds\Router\Handler\TestHandler');
63 63
         $reflectionProperty = $reflectionClass->getProperty('name');
64 64
         $reflectionProperty->setAccessible(true);
65 65
         $actual = $reflectionProperty->getValue($this->handler);
66
-        $this->assertEquals([$expected => $expected],$actual);
66
+        $this->assertEquals([$expected => $expected], $actual);
67 67
     }
68 68
     
69
-    public function testGetNames(){
69
+    public function testGetNames() {
70 70
         $expected = [
71 71
             'foo' => 'foo',
72 72
         ];
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         $this->assertEquals($expected, $this->handler->getNames());
75 75
     }
76 76
 
77
-    public function testWithPreResponse(){
77
+    public function testWithPreResponse() {
78 78
      
79 79
         $expected = 'preResponse String';
80 80
         $this->handler = $this->handler->withPreResponse($expected);
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
 
92
-    public function testGetPreResponse(){
92
+    public function testGetPreResponse() {
93 93
         $expected = 'preResponse String';
94 94
         $this->handler = $this->handler->withPreResponse($expected);
95 95
         $this->assertEquals($expected, $this->handler->getPreResponse());
96 96
     }
97 97
     
98
-    public function testSetState(){
98
+    public function testSetState() {
99 99
         $actual = TestHandler::__set_state(['state' => 'newState']);
100 100
         $expected = new TestHandler('newState');
101 101
         $this->assertEquals($expected, $actual);
Please login to merge, or discard this patch.
Tests/Router/RouterResponseTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
         );
25 25
     }
26 26
 
27
-    public function testGetHandler(){
27
+    public function testGetHandler() {
28 28
         $handler = $this->response->getHandler();
29 29
         $this->assertInstanceOf('\Ds\Router\Interfaces\RouteHandlerInterface', $handler);
30 30
         $this->assertSame($this->handler, $handler);
31 31
     }
32 32
 
33
-    public function testWithHandler(){
33
+    public function testWithHandler() {
34 34
 
35 35
         $newHandler = $this->getMockBuilder('\Ds\Router\Interfaces\RouteHandlerInterface')->getMock();
36 36
         $oldHandler = $this->response->getHandler();
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
      * Returns the Status Code.
43 43
      * @return int
44 44
      */
45
-    public function testGetStatusCode(){
46
-        $this->assertEquals( $this->response->getStatusCode(), 200);
45
+    public function testGetStatusCode() {
46
+        $this->assertEquals($this->response->getStatusCode(), 200);
47 47
     }
48 48
 
49
-    public function testGetResponseInstance(){
49
+    public function testGetResponseInstance() {
50 50
 
51 51
         $httpResponse = $this->getMockBuilder('\Psr\Http\Message\ResponseInterface')->getMock();
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             ->method('getResponse')
55 55
             ->willReturn($httpResponse);
56 56
         
57
-        $response = new RouterResponse( 200, ['get'], $this->handler, []);
57
+        $response = new RouterResponse(200, ['get'], $this->handler, []);
58 58
         $psrResponse = $response->getResponse();
59 59
 
60 60
         $this->assertInstanceOf('\Psr\Http\Message\ResponseInterface', $psrResponse);
Please login to merge, or discard this patch.
Tests/Router/RouterTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,45 +44,45 @@
 block discarded – undo
44 44
         );
45 45
     }
46 46
 
47
-    public function testGetAdaptor(){
47
+    public function testGetAdaptor() {
48 48
         $expected = $this->adaptor;
49 49
         $actual = $this->router->getAdaptor();
50 50
         $this->assertEquals($expected, $actual);
51 51
     }
52 52
 
53
-    public function testWithAdaptor(){
53
+    public function testWithAdaptor() {
54 54
         $newAdaptor = $this->getMockBuilder('\Ds\Router\Interfaces\AdaptorInterface')->getMock();
55 55
         $newRouter = $this->router->withAdaptor($newAdaptor);
56 56
         $this->assertNotSame($this->adaptor, $newRouter->getAdaptor());
57 57
     }
58 58
 
59
-    public function testGetRouterResponse(){
59
+    public function testGetRouterResponse() {
60 60
 
61 61
         $request = $this->getMockBuilder('\Psr\Http\Message\RequestInterface')->getMock();
62 62
 
63
-        $routerResponse = new RouterResponse(200,[],null,[]);
63
+        $routerResponse = new RouterResponse(200, [], null, []);
64 64
 
65
-        $this->adaptor->expects( $this->once() )
65
+        $this->adaptor->expects($this->once())
66 66
             ->method('match')
67 67
             ->willReturn($routerResponse);
68 68
 
69
-        $this->routes->expects( $this->once() )
69
+        $this->routes->expects($this->once())
70 70
             ->method('getRoutes')
71 71
             ->willReturn([]);
72 72
 
73 73
         $response = $this->router->getRouterResponse($request);
74
-        $this->assertInstanceOf('\Ds\Router\Interfaces\RouterResponseInterface' , $response);
74
+        $this->assertInstanceOf('\Ds\Router\Interfaces\RouterResponseInterface', $response);
75 75
 
76 76
     }
77 77
 
78
-    public function testWithRoutes(){
78
+    public function testWithRoutes() {
79 79
 
80 80
         $routes = $this->getMockBuilder('\Ds\Router\Interfaces\RoutesInterface')->getMock();
81 81
         $this->router->withRoutes($routes);
82 82
 
83
-        $reflector = new \ReflectionClass( '\Ds\Router\Router' );
84
-        $prop = $reflector->getProperty( 'routes' );
85
-        $prop->setAccessible( true );
83
+        $reflector = new \ReflectionClass('\Ds\Router\Router');
84
+        $prop = $reflector->getProperty('routes');
85
+        $prop->setAccessible(true);
86 86
 
87 87
         $this->assertSame($routes, $prop->getValue($this->router));
88 88
 
Please login to merge, or discard this patch.
Src/Router/Adaptor/FastRoute.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,10 +114,10 @@
 block discarded – undo
114 114
         return \FastRoute\cachedDispatcher(
115 115
             function(RouteCollector $r) use ($routes){
116 116
                 foreach($routes as $route){
117
-                   $r->addRoute($route['method'],$route['pattern'],$route['handler']);
117
+                    $r->addRoute($route['method'],$route['pattern'],$route['handler']);
118 118
                 }
119 119
             },
120
-           $this->options
120
+            $this->options
121 121
         );
122 122
     }
123 123
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
         $this->options = $options;
16 16
         $this->checkCacheFile();
17 17
 
18
-        if (!isset($this->options['errorHandlers']['default'])){
18
+        if (!isset($this->options['errorHandlers']['default'])) {
19 19
             throw new \Exception('Error Handlers must be specified');
20 20
         }
21 21
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * Check cache file and update self::$cacheDisabled
28 28
      * @return bool
29 29
      */
30
-    public function checkCacheFile(){
30
+    public function checkCacheFile() {
31 31
         $cacheDir = isset($this->options['cacheFile'])
32 32
             ? $this->options['cacheFile'] : __DIR__;
33 33
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      * @param string $requestTarget
49 49
      * @return RouterResponse
50 50
      */
51
-    public function match(array $routes, $method, $requestTarget){
51
+    public function match(array $routes, $method, $requestTarget) {
52 52
 
53 53
         $response = [
54 54
             'statusCode' => 500,
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             'vars' => []
57 57
         ];
58 58
 
59
-        $routeInfo =  $this->getCachedDispatcher($routes)->dispatch($method, $requestTarget);
59
+        $routeInfo = $this->getCachedDispatcher($routes)->dispatch($method, $requestTarget);
60 60
 
61 61
         switch ($routeInfo[0]) {
62 62
             case Dispatcher::FOUND:
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
      * @param $code
92 92
      * @return mixed
93 93
      */
94
-    public function findHandler($code){
94
+    public function findHandler($code) {
95 95
         $handlerName = $this->options['handler'];
96 96
         $handlerArgs = $this->options['errorHandlers']['default'];
97
-        if (isset($this->options['errorHandlers'][$code])){
97
+        if (isset($this->options['errorHandlers'][$code])) {
98 98
             $handlerArgs = $this->options['errorHandlers'][$code];
99 99
         }
100 100
 
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
      * @param array $routes
110 110
      * @return FastRouteAdaptor
111 111
      */
112
-    public function getCachedDispatcher(array $routes = []){
112
+    public function getCachedDispatcher(array $routes = []) {
113 113
 
114 114
         return \FastRoute\cachedDispatcher(
115 115
             function(RouteCollector $r) use ($routes){
116
-                foreach($routes as $route){
117
-                   $r->addRoute($route['method'],$route['pattern'],$route['handler']);
116
+                foreach ($routes as $route) {
117
+                   $r->addRoute($route['method'], $route['pattern'], $route['handler']);
118 118
                 }
119 119
             },
120 120
            $this->options
Please login to merge, or discard this patch.
Src/Router/Adaptor/Adaptor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * Return Adaptor Options
37 37
      * @return array
38 38
      */
39
-    public function getOptions(){
39
+    public function getOptions() {
40 40
         return $this->options;
41 41
     }
42 42
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param array $options
46 46
      * @return void
47 47
      */
48
-    public function withOptions(array $options = []){
48
+    public function withOptions(array $options = []) {
49 49
         $this->options = $options;
50 50
         return;
51 51
     }
Please login to merge, or discard this patch.
Src/Router/Handler/ClassHandler.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return mixed
44 44
      */
45
-    public function resolve(...$arguments){
45
+    public function resolve(...$arguments) {
46 46
 
47 47
 
48
-        $controllerMethod = explode('::',$this->getPreResponse());
48
+        $controllerMethod = explode('::', $this->getPreResponse());
49 49
 
50 50
         $this->controller = isset($controllerMethod[0]) ? $controllerMethod[0] : $this->controller;
51 51
         $this->method = isset($controllerMethod[1]) ? $controllerMethod[1] : $this->method;
52 52
 
53
-        try{
54
-            $this->resolveController( $this->controller);
55
-            $this->resolveMethod( $this->method );
56
-        }catch(\Exception $e){
53
+        try {
54
+            $this->resolveController($this->controller);
55
+            $this->resolveMethod($this->method);
56
+        }catch (\Exception $e) {
57 57
             $this->resolved = new $this->controller(...$arguments);
58 58
         }
59 59
 
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
      * @return ResponseInterface
70 70
      * @throws \Exception
71 71
      */
72
-    public function getResponse($vars = [] ){
72
+    public function getResponse($vars = []) {
73 73
 
74
-        if ($this->resolved === null){
74
+        if ($this->resolved === null) {
75 75
             throw new \Exception("Handler must be resolved before calling getContents().");
76 76
         }
77 77
 
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
      * @return bool
89 89
      * @throws \Exception controller:{controller} not found
90 90
      */
91
-    private function resolveController($controller){
91
+    private function resolveController($controller) {
92 92
 
93
-        if ( !class_exists($controller)){
93
+        if (!class_exists($controller)) {
94 94
             throw new \Exception("Controller {$controller} not found");
95 95
         }
96 96
         return true;
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
      * @return bool
104 104
      * @throws \Exception
105 105
      */
106
-    private function resolveMethod($method){
107
-        if (method_exists($this->controller,$method)){
106
+    private function resolveMethod($method) {
107
+        if (method_exists($this->controller, $method)) {
108 108
             return true;
109 109
         }
110 110
         throw new \Exception("method: {$this->controller}::{$method} not found");
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
         try{
54 54
             $this->resolveController( $this->controller);
55 55
             $this->resolveMethod( $this->method );
56
-        }catch(\Exception $e){
56
+        } catch(\Exception $e){
57 57
             $this->resolved = new $this->controller(...$arguments);
58 58
         }
59 59
 
Please login to merge, or discard this patch.