Passed
Push — master ( 43eb1d...5d3e0a )
by Anton
02:39
created
src/Domain/GuardInterceptor.php 1 patch
Braces   +19 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,7 +47,8 @@  discard block
 block discarded – undo
47 47
     {
48 48
         $permission = $this->getPermissions($controller, $action);
49 49
 
50
-        if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) {
50
+        if ($permission !== null && !$this->guard->allows($permission[0], $parameters))
51
+        {
51 52
             throw new ControllerException(
52 53
                 sprintf(
53 54
                     'Unauthorized permission `%s` for action `%s`->`%s`',
@@ -74,14 +75,18 @@  discard block
 block discarded – undo
74 75
     private function getPermissions(string $controller, string $action): ?array
75 76
     {
76 77
         $key = sprintf('%s:%s', $controller, $action);
77
-        if (array_key_exists($key, $this->cache)) {
78
+        if (array_key_exists($key, $this->cache))
79
+        {
78 80
             return $this->cache[$key];
79 81
         }
80 82
 
81 83
         $this->cache[$key] = null;
82
-        try {
84
+        try
85
+        {
83 86
             $method = new \ReflectionMethod($controller, $action);
84
-        } catch (\ReflectionException $e) {
87
+        }
88
+        catch (\ReflectionException $e)
89
+        {
85 90
             return null;
86 91
         }
87 92
 
@@ -99,11 +104,13 @@  discard block
 block discarded – undo
99 104
             Guarded::class
100 105
         );
101 106
 
102
-        if ($action === null) {
107
+        if ($action === null)
108
+        {
103 109
             return null;
104 110
         }
105 111
 
106
-        if ($action->permission === null && $namespace === null) {
112
+        if ($action->permission === null && $namespace === null)
113
+        {
107 114
             throw new InterceptorException(
108 115
                 'Unable to apply @Guarded annotation without specified permission name or @GuardNamespace'
109 116
             );
@@ -129,7 +136,8 @@  discard block
 block discarded – undo
129 136
             ControllerException::FORBIDDEN
130 137
         ];
131 138
 
132
-        if ($guarded->permission === null && $ns === null) {
139
+        if ($guarded->permission === null && $ns === null)
140
+        {
133 141
             throw new InterceptorException(sprintf(
134 142
                 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`',
135 143
                 $method->getDeclaringClass()->getName(),
@@ -137,11 +145,13 @@  discard block
 block discarded – undo
137 145
             ));
138 146
         }
139 147
 
140
-        if ($ns !== null) {
148
+        if ($ns !== null)
149
+        {
141 150
             $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]);
142 151
         }
143 152
 
144
-        switch ($guarded->else) {
153
+        switch ($guarded->else)
154
+        {
145 155
             case 'badAction':
146 156
                 $permission[1] = ControllerException::BAD_ACTION;
147 157
                 break;
Please login to merge, or discard this patch.