Completed
Push — master ( 1481a4...14a440 )
by Dan
05:18
created
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.
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/Handler.php 1 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.
Src/Router/Routes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,12 +49,12 @@
 block discarded – undo
49 49
     {
50 50
 
51 51
         $pattern = ltrim($pattern, '/');
52
-        $pattern = '/'.$pattern;
52
+        $pattern = '/' . $pattern;
53 53
 
54
-        if ($this->groupedRoute === false){
54
+        if ($this->groupedRoute === false) {
55 55
             $routePattern = $pattern;
56
-        }else{
57
-            $routePattern = implode('',$this->dir).$pattern;
56
+        } else {
57
+            $routePattern = implode('', $this->dir) . $pattern;
58 58
         }
59 59
 
60 60
         $this->isUnique($method, $routePattern);
Please login to merge, or discard this patch.
Tests/Router/RoutesTest.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
         $this->routes = new Routes();
15 15
     }
16 16
 
17
-    public function testGroup(){
17
+    public function testGroup() {
18 18
 
19 19
         $handler = $this->getMockBuilder('Ds\Router\Interfaces\RouteHandlerInterface')->getMock();
20 20
         $routes = $this->routes;
21 21
 
22
-        $this->routes->group('/path',function() use ($routes, $handler){
23
-            $routes->add(['GET','POST'], '/foo', $handler, ['global']);
22
+        $this->routes->group('/path', function() use ($routes, $handler){
23
+            $routes->add(['GET', 'POST'], '/foo', $handler, ['global']);
24 24
 
25
-                $routes->group('/sub-dir',function() use ($routes, $handler){
25
+                $routes->group('/sub-dir', function() use ($routes, $handler){
26 26
                     $routes->add(['GET'], '/sub-page', $handler, ['sub-dir']);
27 27
                 });
28 28
         });
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
         $this->assertEquals($expected, $actual);
54 54
     }
55 55
 
56
-    public function testAdd(){
56
+    public function testAdd() {
57 57
 
58 58
         $handler = $this->getMockBuilder('Ds\Router\Interfaces\RouteHandlerInterface')->getMock();
59
-        $this->routes->add(['GET','POST'], '/foo', $handler, ['global']);
59
+        $this->routes->add(['GET', 'POST'], '/foo', $handler, ['global']);
60 60
 
61 61
         $actual = $this->routes->getRoutes();
62 62
 
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
         $this->assertEquals($expected, $actual);
79 79
     }
80 80
 
81
-    public function testGetRoutes(){
81
+    public function testGetRoutes() {
82 82
         $handler = $this->getMockBuilder('Ds\Router\Interfaces\RouteHandlerInterface')->getMock();
83 83
 
84 84
         $this->routes->add('GET', '/foo', $handler, ['global']);
85
-        $this->routes->add('POST', '/baz', $handler, ['some','other','names']);
85
+        $this->routes->add('POST', '/baz', $handler, ['some', 'other', 'names']);
86 86
 
87 87
         $actual = $this->routes->getRoutes();
88 88
 
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
                 'method' => 'POST',
98 98
                 'pattern' => '/baz',
99 99
                 'handler' => $handler,
100
-                'name' => ['some','other','names']
100
+                'name' => ['some', 'other', 'names']
101 101
             ]
102 102
         ];
103 103
 
104 104
         $this->assertEquals($expected, $actual);
105 105
     }
106 106
 
107
-    public function testIsUnique(){
107
+    public function testIsUnique() {
108 108
         $handler = $this->getMockBuilder('Ds\Router\Interfaces\RouteHandlerInterface')->getMock();
109 109
         $this->routes->add('GET', '/foo', $handler, ['global']);
110 110
         $this->setExpectedException('\Exception');
Please login to merge, or discard this patch.
Src/Router/Handler/ClassHandler.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * @param string $method
25 25
      * @return ClassHandler
26 26
      */
27
-    public static function add($controller, $method){
27
+    public static function add($controller, $method) {
28 28
         return new ClassHandler($controller, $method);
29 29
     }
30 30
 
@@ -51,19 +51,19 @@  discard block
 block discarded – undo
51 51
      * @return $this
52 52
      * @throws \Exception
53 53
      */
54
-    public function resolve(...$arguments){
54
+    public function resolve(...$arguments) {
55 55
 
56 56
 
57
-        $controllerMethod = explode('::',$this->getPreResponse());
57
+        $controllerMethod = explode('::', $this->getPreResponse());
58 58
 
59 59
         $this->controller = isset($controllerMethod[0]) ? $controllerMethod[0] : $this->controller;
60 60
         $this->method = isset($controllerMethod[1]) ? $controllerMethod[1] : $this->method;
61 61
 
62
-        try{
63
-            $this->resolveController( $this->controller);
64
-            $this->resolveMethod( $this->method );
62
+        try {
63
+            $this->resolveController($this->controller);
64
+            $this->resolveMethod($this->method);
65 65
             $this->resolved = new $this->controller(...$arguments);
66
-        }catch(\Exception $e){
66
+        }catch (\Exception $e) {
67 67
             throw new \Exception($e->getMessage());
68 68
         }
69 69
         return $this;
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
      * @return ResponseInterface
78 78
      * @throws \Exception
79 79
      */
80
-    public function getResponse($vars = [] ){
80
+    public function getResponse($vars = []) {
81 81
 
82
-        if ($this->resolved === null){
82
+        if ($this->resolved === null) {
83 83
             throw new \Exception("Handler must be resolved before calling getContents().");
84 84
         }
85 85
 
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
      * @return bool
97 97
      * @throws \Exception controller:{controller} not found
98 98
      */
99
-    private function resolveController($controller){
99
+    private function resolveController($controller) {
100 100
 
101
-        if ( !class_exists($controller)){
101
+        if (!class_exists($controller)) {
102 102
             throw new \Exception("Controller {$controller} not found");
103 103
         }
104 104
         return true;
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
      * @return bool
112 112
      * @throws \Exception
113 113
      */
114
-    private function resolveMethod($method){
115
-        if (method_exists($this->controller,$method)){
114
+    private function resolveMethod($method) {
115
+        if (method_exists($this->controller, $method)) {
116 116
             return true;
117 117
         }
118 118
         throw new \Exception("method: {$this->controller}::{$method} not found");
Please login to merge, or discard this patch.