Passed
Push — master ( 288d0a...9fb52b )
by Anton
02:17
created
src/Domain/GuardInterceptor.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     {
53 53
         $permission = $this->getPermissions($controller, $action);
54 54
 
55
-        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) {
55
+        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){
56 56
             throw new ControllerException($permission[2], $permission[1]);
57 57
         }
58 58
 
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
     private function getPermissions(string $controller, string $action): ?array
72 72
     {
73 73
         $key = sprintf('%s:%s', $controller, $action);
74
-        if (array_key_exists($key, $this->cache)) {
74
+        if (array_key_exists($key, $this->cache)){
75 75
             return $this->cache[$key];
76 76
         }
77 77
 
78 78
         $this->cache[$key] = null;
79
-        try {
79
+        try{
80 80
             $method = new \ReflectionMethod($controller, $action);
81
-        } catch (\ReflectionException $e) {
81
+        }catch (\ReflectionException $e){
82 82
             return null;
83 83
         }
84 84
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             Guarded::class
97 97
         );
98 98
 
99
-        if ($action === null) {
99
+        if ($action === null){
100 100
             return null;
101 101
         }
102 102
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             $guarded->errorMessage ?? sprintf('Unauthorized access `%s`', $guarded->permission ?? $method->getName())
120 120
         ];
121 121
 
122
-        if ($guarded->permission === null && $ns === null) {
122
+        if ($guarded->permission === null && $ns === null){
123 123
             throw new InterceptorException(
124 124
                 sprintf(
125 125
                     'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
@@ -129,16 +129,16 @@  discard block
 block discarded – undo
129 129
             );
130 130
         }
131 131
 
132
-        if ($ns !== null) {
132
+        if ($ns !== null){
133 133
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
134 134
         }
135 135
 
136
-        if ($this->namespace !== null) {
136
+        if ($this->namespace !== null){
137 137
             // global namespace
138 138
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
139 139
         }
140 140
 
141
-        switch ($guarded->else) {
141
+        switch ($guarded->else){
142 142
             case 'unauthorized':
143 143
                 $permission[1] = ControllerException::UNAUTHORIZED;
144 144
                 break;
Please login to merge, or discard this patch.
Braces   +19 added lines, -9 removed lines patch added patch discarded remove patch
@@ -52,7 +52,8 @@  discard block
 block discarded – undo
52 52
     {
53 53
         $permission = $this->getPermissions($controller, $action);
54 54
 
55
-        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) {
55
+        if ($permission !== null && !$this->guard->allows($permission[0], $parameters))
56
+        {
56 57
             throw new ControllerException($permission[2], $permission[1]);
57 58
         }
58 59
 
@@ -71,14 +72,18 @@  discard block
 block discarded – undo
71 72
     private function getPermissions(string $controller, string $action): ?array
72 73
     {
73 74
         $key = sprintf('%s:%s', $controller, $action);
74
-        if (array_key_exists($key, $this->cache)) {
75
+        if (array_key_exists($key, $this->cache))
76
+        {
75 77
             return $this->cache[$key];
76 78
         }
77 79
 
78 80
         $this->cache[$key] = null;
79
-        try {
81
+        try
82
+        {
80 83
             $method = new \ReflectionMethod($controller, $action);
81
-        } catch (\ReflectionException $e) {
84
+        }
85
+        catch (\ReflectionException $e)
86
+        {
82 87
             return null;
83 88
         }
84 89
 
@@ -96,7 +101,8 @@  discard block
 block discarded – undo
96 101
             Guarded::class
97 102
         );
98 103
 
99
-        if ($action === null) {
104
+        if ($action === null)
105
+        {
100 106
             return null;
101 107
         }
102 108
 
@@ -119,7 +125,8 @@  discard block
 block discarded – undo
119 125
             $guarded->errorMessage ?? sprintf('Unauthorized access `%s`', $guarded->permission ?? $method->getName())
120 126
         ];
121 127
 
122
-        if ($guarded->permission === null && $ns === null) {
128
+        if ($guarded->permission === null && $ns === null)
129
+        {
123 130
             throw new InterceptorException(
124 131
                 sprintf(
125 132
                     'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
@@ -129,16 +136,19 @@  discard block
 block discarded – undo
129 136
             );
130 137
         }
131 138
 
132
-        if ($ns !== null) {
139
+        if ($ns !== null)
140
+        {
133 141
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
134 142
         }
135 143
 
136
-        if ($this->namespace !== null) {
144
+        if ($this->namespace !== null)
145
+        {
137 146
             // global namespace
138 147
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
139 148
         }
140 149
 
141
-        switch ($guarded->else) {
150
+        switch ($guarded->else)
151
+        {
142 152
             case 'unauthorized':
143 153
                 $permission[1] = ControllerException::UNAUTHORIZED;
144 154
                 break;
Please login to merge, or discard this patch.