Passed
Push — master ( 6cc600...7f432b )
by Anton
02:27
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(
57 57
                 sprintf(
58 58
                     'Unauthorized permission `%s` for action `%s`->`%s`',
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
     private function getPermissions(string $controller, string $action): ?array
80 80
     {
81 81
         $key = sprintf('%s:%s', $controller, $action);
82
-        if (array_key_exists($key, $this->cache)) {
82
+        if (array_key_exists($key, $this->cache)){
83 83
             return $this->cache[$key];
84 84
         }
85 85
 
86 86
         $this->cache[$key] = null;
87
-        try {
87
+        try{
88 88
             $method = new \ReflectionMethod($controller, $action);
89
-        } catch (\ReflectionException $e) {
89
+        }catch (\ReflectionException $e){
90 90
             return null;
91 91
         }
92 92
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             Guarded::class
105 105
         );
106 106
 
107
-        if ($action === null) {
107
+        if ($action === null){
108 108
             return null;
109 109
         }
110 110
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             ControllerException::FORBIDDEN
127 127
         ];
128 128
 
129
-        if ($guarded->permission === null && $ns === null) {
129
+        if ($guarded->permission === null && $ns === null){
130 130
             throw new InterceptorException(sprintf(
131 131
                 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
132 132
                 $method->getDeclaringClass()->getName(),
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
             ));
135 135
         }
136 136
 
137
-        if ($ns !== null) {
137
+        if ($ns !== null){
138 138
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
139 139
         }
140 140
 
141
-        if ($this->namespace !== null) {
141
+        if ($this->namespace !== null){
142 142
             // global namespace
143 143
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
144 144
         }
145 145
 
146
-        switch ($guarded->else) {
146
+        switch ($guarded->else){
147 147
             case 'badAction':
148 148
                 $permission[1] = ControllerException::BAD_ACTION;
149 149
                 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(
57 58
                 sprintf(
58 59
                     'Unauthorized permission `%s` for action `%s`->`%s`',
@@ -79,14 +80,18 @@  discard block
 block discarded – undo
79 80
     private function getPermissions(string $controller, string $action): ?array
80 81
     {
81 82
         $key = sprintf('%s:%s', $controller, $action);
82
-        if (array_key_exists($key, $this->cache)) {
83
+        if (array_key_exists($key, $this->cache))
84
+        {
83 85
             return $this->cache[$key];
84 86
         }
85 87
 
86 88
         $this->cache[$key] = null;
87
-        try {
89
+        try
90
+        {
88 91
             $method = new \ReflectionMethod($controller, $action);
89
-        } catch (\ReflectionException $e) {
92
+        }
93
+        catch (\ReflectionException $e)
94
+        {
90 95
             return null;
91 96
         }
92 97
 
@@ -104,7 +109,8 @@  discard block
 block discarded – undo
104 109
             Guarded::class
105 110
         );
106 111
 
107
-        if ($action === null) {
112
+        if ($action === null)
113
+        {
108 114
             return null;
109 115
         }
110 116
 
@@ -126,7 +132,8 @@  discard block
 block discarded – undo
126 132
             ControllerException::FORBIDDEN
127 133
         ];
128 134
 
129
-        if ($guarded->permission === null && $ns === null) {
135
+        if ($guarded->permission === null && $ns === null)
136
+        {
130 137
             throw new InterceptorException(sprintf(
131 138
                 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
132 139
                 $method->getDeclaringClass()->getName(),
@@ -134,16 +141,19 @@  discard block
 block discarded – undo
134 141
             ));
135 142
         }
136 143
 
137
-        if ($ns !== null) {
144
+        if ($ns !== null)
145
+        {
138 146
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
139 147
         }
140 148
 
141
-        if ($this->namespace !== null) {
149
+        if ($this->namespace !== null)
150
+        {
142 151
             // global namespace
143 152
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
144 153
         }
145 154
 
146
-        switch ($guarded->else) {
155
+        switch ($guarded->else)
156
+        {
147 157
             case 'badAction':
148 158
                 $permission[1] = ControllerException::BAD_ACTION;
149 159
                 break;
Please login to merge, or discard this patch.