Passed
Push — master ( 8ce59b...37cbc8 )
by Anton
03:35 queued 36s
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(
131 131
                 sprintf(
132 132
                     'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
@@ -136,16 +136,16 @@  discard block
 block discarded – undo
136 136
             );
137 137
         }
138 138
 
139
-        if ($ns !== null) {
139
+        if ($ns !== null){
140 140
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
141 141
         }
142 142
 
143
-        if ($this->namespace !== null) {
143
+        if ($this->namespace !== null){
144 144
             // global namespace
145 145
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
146 146
         }
147 147
 
148
-        switch ($guarded->else) {
148
+        switch ($guarded->else){
149 149
             case 'unauthorized':
150 150
                 $permission[1] = ControllerException::UNAUTHORIZED;
151 151
                 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(
131 138
                 sprintf(
132 139
                     'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
@@ -136,16 +143,19 @@  discard block
 block discarded – undo
136 143
             );
137 144
         }
138 145
 
139
-        if ($ns !== null) {
146
+        if ($ns !== null)
147
+        {
140 148
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
141 149
         }
142 150
 
143
-        if ($this->namespace !== null) {
151
+        if ($this->namespace !== null)
152
+        {
144 153
             // global namespace
145 154
             $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]);
146 155
         }
147 156
 
148
-        switch ($guarded->else) {
157
+        switch ($guarded->else)
158
+        {
149 159
             case 'unauthorized':
150 160
                 $permission[1] = ControllerException::UNAUTHORIZED;
151 161
                 break;
Please login to merge, or discard this patch.