@@ -75,21 +75,21 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | $namespace = $this->defaultNamespace; |
78 | - if (strpos($filename, '.') === false) { |
|
78 | + if (strpos($filename, '.') === false){ |
|
79 | 79 | //Force default extension |
80 | - $filename .= '.' . $this->extension; |
|
81 | - } elseif (!$this->match($filename)) { |
|
80 | + $filename .= '.'.$this->extension; |
|
81 | + } elseif (!$this->match($filename)){ |
|
82 | 82 | return null; |
83 | 83 | } |
84 | 84 | |
85 | - if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false) { |
|
85 | + if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false){ |
|
86 | 86 | list($namespace, $filename) = explode(LoaderInterface::NS_SEPARATOR, $filename); |
87 | 87 | } |
88 | 88 | |
89 | 89 | //Twig like namespaces |
90 | - if (isset($filename[0]) && $filename[0] == '@') { |
|
90 | + if (isset($filename[0]) && $filename[0] == '@'){ |
|
91 | 91 | $separator = strpos($filename, '/'); |
92 | - if ($separator === false) { |
|
92 | + if ($separator === false){ |
|
93 | 93 | throw new PathException(sprintf('Malformed view path"%s" (expecting "@namespace/name").', $path)); |
94 | 94 | } |
95 | 95 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | */ |
124 | 124 | private function validatePath(string $path): void |
125 | 125 | { |
126 | - if (empty($path)) { |
|
126 | + if (empty($path)){ |
|
127 | 127 | throw new PathException('A view path is empty'); |
128 | 128 | } |
129 | 129 | |
130 | - if (false !== strpos($path, "\0")) { |
|
130 | + if (false !== strpos($path, "\0")){ |
|
131 | 131 | throw new PathException('A view path cannot contain NUL bytes'); |
132 | 132 | } |
133 | 133 | |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | $parts = explode('/', $path); |
136 | 136 | $level = 0; |
137 | 137 | |
138 | - foreach ($parts as $part) { |
|
139 | - if ('..' === $part) { |
|
138 | + foreach ($parts as $part){ |
|
139 | + if ('..' === $part){ |
|
140 | 140 | --$level; |
141 | - } elseif ('.' !== $part) { |
|
141 | + } elseif ('.' !== $part){ |
|
142 | 142 | ++$level; |
143 | 143 | } |
144 | 144 | |
145 | - if ($level < 0) { |
|
145 | + if ($level < 0){ |
|
146 | 146 | throw new PathException(sprintf( |
147 | 147 | 'Looks like you try to load a view outside configured directories (%s)', |
148 | 148 | $path |
@@ -75,21 +75,27 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | $namespace = $this->defaultNamespace; |
78 | - if (strpos($filename, '.') === false) { |
|
78 | + if (strpos($filename, '.') === false) |
|
79 | + { |
|
79 | 80 | //Force default extension |
80 | 81 | $filename .= '.' . $this->extension; |
81 | - } elseif (!$this->match($filename)) { |
|
82 | + } |
|
83 | + elseif (!$this->match($filename)) |
|
84 | + { |
|
82 | 85 | return null; |
83 | 86 | } |
84 | 87 | |
85 | - if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false) { |
|
88 | + if (strpos($filename, LoaderInterface::NS_SEPARATOR) !== false) |
|
89 | + { |
|
86 | 90 | list($namespace, $filename) = explode(LoaderInterface::NS_SEPARATOR, $filename); |
87 | 91 | } |
88 | 92 | |
89 | 93 | //Twig like namespaces |
90 | - if (isset($filename[0]) && $filename[0] == '@') { |
|
94 | + if (isset($filename[0]) && $filename[0] == '@') |
|
95 | + { |
|
91 | 96 | $separator = strpos($filename, '/'); |
92 | - if ($separator === false) { |
|
97 | + if ($separator === false) |
|
98 | + { |
|
93 | 99 | throw new PathException(sprintf('Malformed view path"%s" (expecting "@namespace/name").', $path)); |
94 | 100 | } |
95 | 101 | |
@@ -123,11 +129,13 @@ discard block |
||
123 | 129 | */ |
124 | 130 | private function validatePath(string $path): void |
125 | 131 | { |
126 | - if (empty($path)) { |
|
132 | + if (empty($path)) |
|
133 | + { |
|
127 | 134 | throw new PathException('A view path is empty'); |
128 | 135 | } |
129 | 136 | |
130 | - if (false !== strpos($path, "\0")) { |
|
137 | + if (false !== strpos($path, "\0")) |
|
138 | + { |
|
131 | 139 | throw new PathException('A view path cannot contain NUL bytes'); |
132 | 140 | } |
133 | 141 | |
@@ -135,14 +143,19 @@ discard block |
||
135 | 143 | $parts = explode('/', $path); |
136 | 144 | $level = 0; |
137 | 145 | |
138 | - foreach ($parts as $part) { |
|
139 | - if ('..' === $part) { |
|
146 | + foreach ($parts as $part) |
|
147 | + { |
|
148 | + if ('..' === $part) |
|
149 | + { |
|
140 | 150 | --$level; |
141 | - } elseif ('.' !== $part) { |
|
151 | + } |
|
152 | + elseif ('.' !== $part) |
|
153 | + { |
|
142 | 154 | ++$level; |
143 | 155 | } |
144 | 156 | |
145 | - if ($level < 0) { |
|
157 | + if ($level < 0) |
|
158 | + { |
|
146 | 159 | throw new PathException(sprintf( |
147 | 160 | 'Looks like you try to load a view outside configured directories (%s)', |
148 | 161 | $path |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | array $namespaces, |
44 | 44 | FilesInterface $files = null, |
45 | 45 | string $defaultNamespace = self::DEFAULT_NAMESPACE |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | $this->namespaces = $namespaces; |
48 | 48 | $this->files = $files ?? new Files(); |
49 | 49 | $this->defaultNamespace = $defaultNamespace; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function getExtension(): ?string |
67 | 67 | { |
68 | - if ($this->parser !== null) { |
|
68 | + if ($this->parser !== null){ |
|
69 | 69 | return $this->parser->getExtension(); |
70 | 70 | } |
71 | 71 | |
@@ -80,22 +80,22 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function exists(string $path, string &$filename = null, ViewPath &$parsed = null): bool |
82 | 82 | { |
83 | - if (empty($this->parser)) { |
|
83 | + if (empty($this->parser)){ |
|
84 | 84 | throw new LoaderException('Unable to locate view source, no extension has been associated.'); |
85 | 85 | } |
86 | 86 | |
87 | 87 | $parsed = $this->parser->parse($path); |
88 | - if (empty($parsed)) { |
|
88 | + if (empty($parsed)){ |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - if (!isset($this->namespaces[$parsed->getNamespace()])) { |
|
92 | + if (!isset($this->namespaces[$parsed->getNamespace()])){ |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | - foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) { |
|
96 | + foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory){ |
|
97 | 97 | $directory = $this->files->normalizePath($directory, true); |
98 | - if ($this->files->exists(sprintf('%s%s', $directory, $parsed->getBasename()))) { |
|
98 | + if ($this->files->exists(sprintf('%s%s', $directory, $parsed->getBasename()))){ |
|
99 | 99 | $filename = sprintf('%s%s', $directory, $parsed->getBasename()); |
100 | 100 | |
101 | 101 | return true; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function load(string $path): ViewSource |
112 | 112 | { |
113 | - if (!$this->exists($path, $filename, $parsed)) { |
|
113 | + if (!$this->exists($path, $filename, $parsed)){ |
|
114 | 114 | throw new LoaderException("Unable to load view `$path`, file does not exists."); |
115 | 115 | } |
116 | 116 | |
@@ -123,21 +123,21 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function list(string $namespace = null): array |
125 | 125 | { |
126 | - if (empty($this->parser)) { |
|
126 | + if (empty($this->parser)){ |
|
127 | 127 | throw new LoaderException('Unable to list view sources, no extension has been associated.'); |
128 | 128 | } |
129 | 129 | |
130 | 130 | $result = []; |
131 | - foreach ($this->namespaces as $ns => $directories) { |
|
132 | - if (!empty($namespace) && $namespace != $ns) { |
|
131 | + foreach ($this->namespaces as $ns => $directories){ |
|
132 | + if (!empty($namespace) && $namespace != $ns){ |
|
133 | 133 | continue; |
134 | 134 | } |
135 | 135 | |
136 | - foreach ((array)$directories as $directory) { |
|
136 | + foreach ((array)$directories as $directory){ |
|
137 | 137 | $files = $this->files->getFiles($directory); |
138 | 138 | |
139 | - foreach ($files as $filename) { |
|
140 | - if (!$this->parser->match($filename)) { |
|
139 | + foreach ($files as $filename){ |
|
140 | + if (!$this->parser->match($filename)){ |
|
141 | 141 | // does not belong to this loader |
142 | 142 | continue; |
143 | 143 | } |
@@ -65,7 +65,8 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function getExtension(): ?string |
67 | 67 | { |
68 | - if ($this->parser !== null) { |
|
68 | + if ($this->parser !== null) |
|
69 | + { |
|
69 | 70 | return $this->parser->getExtension(); |
70 | 71 | } |
71 | 72 | |
@@ -80,22 +81,27 @@ discard block |
||
80 | 81 | */ |
81 | 82 | public function exists(string $path, string &$filename = null, ViewPath &$parsed = null): bool |
82 | 83 | { |
83 | - if (empty($this->parser)) { |
|
84 | + if (empty($this->parser)) |
|
85 | + { |
|
84 | 86 | throw new LoaderException('Unable to locate view source, no extension has been associated.'); |
85 | 87 | } |
86 | 88 | |
87 | 89 | $parsed = $this->parser->parse($path); |
88 | - if (empty($parsed)) { |
|
90 | + if (empty($parsed)) |
|
91 | + { |
|
89 | 92 | return false; |
90 | 93 | } |
91 | 94 | |
92 | - if (!isset($this->namespaces[$parsed->getNamespace()])) { |
|
95 | + if (!isset($this->namespaces[$parsed->getNamespace()])) |
|
96 | + { |
|
93 | 97 | return false; |
94 | 98 | } |
95 | 99 | |
96 | - foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) { |
|
100 | + foreach ((array)$this->namespaces[$parsed->getNamespace()] as $directory) |
|
101 | + { |
|
97 | 102 | $directory = $this->files->normalizePath($directory, true); |
98 | - if ($this->files->exists(sprintf('%s%s', $directory, $parsed->getBasename()))) { |
|
103 | + if ($this->files->exists(sprintf('%s%s', $directory, $parsed->getBasename()))) |
|
104 | + { |
|
99 | 105 | $filename = sprintf('%s%s', $directory, $parsed->getBasename()); |
100 | 106 | |
101 | 107 | return true; |
@@ -110,7 +116,8 @@ discard block |
||
110 | 116 | */ |
111 | 117 | public function load(string $path): ViewSource |
112 | 118 | { |
113 | - if (!$this->exists($path, $filename, $parsed)) { |
|
119 | + if (!$this->exists($path, $filename, $parsed)) |
|
120 | + { |
|
114 | 121 | throw new LoaderException("Unable to load view `$path`, file does not exists."); |
115 | 122 | } |
116 | 123 | |
@@ -123,21 +130,27 @@ discard block |
||
123 | 130 | */ |
124 | 131 | public function list(string $namespace = null): array |
125 | 132 | { |
126 | - if (empty($this->parser)) { |
|
133 | + if (empty($this->parser)) |
|
134 | + { |
|
127 | 135 | throw new LoaderException('Unable to list view sources, no extension has been associated.'); |
128 | 136 | } |
129 | 137 | |
130 | 138 | $result = []; |
131 | - foreach ($this->namespaces as $ns => $directories) { |
|
132 | - if (!empty($namespace) && $namespace != $ns) { |
|
139 | + foreach ($this->namespaces as $ns => $directories) |
|
140 | + { |
|
141 | + if (!empty($namespace) && $namespace != $ns) |
|
142 | + { |
|
133 | 143 | continue; |
134 | 144 | } |
135 | 145 | |
136 | - foreach ((array)$directories as $directory) { |
|
146 | + foreach ((array)$directories as $directory) |
|
147 | + { |
|
137 | 148 | $files = $this->files->getFiles($directory); |
138 | 149 | |
139 | - foreach ($files as $filename) { |
|
140 | - if (!$this->parser->match($filename)) { |
|
150 | + foreach ($files as $filename) |
|
151 | + { |
|
152 | + if (!$this->parser->match($filename)) |
|
153 | + { |
|
141 | 154 | // does not belong to this loader |
142 | 155 | continue; |
143 | 156 | } |
@@ -90,8 +90,8 @@ |
||
90 | 90 | $this->assertEquals($allowRule, $manager->getRule(static::ROLE, static::PERMISSION)); |
91 | 91 | |
92 | 92 | // test pattern permission |
93 | - $this->assertEquals($manager, $manager->associate(static::ROLE, static::PERMISSION . '.*', AllowRule::class)); |
|
94 | - $this->assertEquals($allowRule, $manager->getRule(static::ROLE, static::PERMISSION . '.' . static::PERMISSION)); |
|
93 | + $this->assertEquals($manager, $manager->associate(static::ROLE, static::PERMISSION.'.*', AllowRule::class)); |
|
94 | + $this->assertEquals($allowRule, $manager->getRule(static::ROLE, static::PERMISSION.'.'.static::PERMISSION)); |
|
95 | 95 | |
96 | 96 | $this->assertEquals($manager, $manager->deassociate(static::ROLE, static::PERMISSION)); |
97 | 97 | $this->assertEquals($forbidRule, $manager->getRule(static::ROLE, static::PERMISSION)); |
@@ -100,7 +100,7 @@ |
||
100 | 100 | $this->assertEquals(static::OPERATION, $guarded->resolvePermission(static::OPERATION)); |
101 | 101 | |
102 | 102 | $guarded = new GuardedWithNamespace(); |
103 | - $resolvedPermission = GuardedWithNamespace::GUARD_NAMESPACE . '.' . static::OPERATION; |
|
103 | + $resolvedPermission = GuardedWithNamespace::GUARD_NAMESPACE.'.'.static::OPERATION; |
|
104 | 104 | $this->assertEquals($resolvedPermission, $guarded->resolvePermission(static::OPERATION)); |
105 | 105 | } |
106 | 106 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | // other rule types |
61 | 61 | $manager->set('RuleInterface', $this->rule); |
62 | 62 | $this->assertEquals($this->rule, $manager->get('RuleInterface')); |
63 | - $manager->set('Closure', function () { |
|
63 | + $manager->set('Closure', function (){ |
|
64 | 64 | return true; |
65 | 65 | }); |
66 | 66 | $this->assertTrue($manager->get('Closure') instanceof CallableRule); |
@@ -60,7 +60,8 @@ |
||
60 | 60 | // other rule types |
61 | 61 | $manager->set('RuleInterface', $this->rule); |
62 | 62 | $this->assertEquals($this->rule, $manager->get('RuleInterface')); |
63 | - $manager->set('Closure', function () { |
|
63 | + $manager->set('Closure', function () |
|
64 | + { |
|
64 | 65 | return true; |
65 | 66 | }); |
66 | 67 | $this->assertTrue($manager->get('Closure') instanceof CallableRule); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function addRole(string $role): PermissionManager |
74 | 74 | { |
75 | - if ($this->hasRole($role)) { |
|
75 | + if ($this->hasRole($role)){ |
|
76 | 76 | throw new RoleException("Role '{$role}' already exists"); |
77 | 77 | } |
78 | 78 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function removeRole(string $role): PermissionManager |
92 | 92 | { |
93 | - if (!$this->hasRole($role)) { |
|
93 | + if (!$this->hasRole($role)){ |
|
94 | 94 | throw new RoleException("Undefined role '{$role}'"); |
95 | 95 | } |
96 | 96 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getPermissions(string $role): array |
114 | 114 | { |
115 | - if (!$this->hasRole($role)) { |
|
115 | + if (!$this->hasRole($role)){ |
|
116 | 116 | throw new RoleException("Undefined role '{$role}'"); |
117 | 117 | } |
118 | 118 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getRule(string $role, string $permission): RuleInterface |
126 | 126 | { |
127 | - if (!$this->hasRole($role)) { |
|
127 | + if (!$this->hasRole($role)){ |
|
128 | 128 | throw new RoleException("Undefined role '{$role}'"); |
129 | 129 | } |
130 | 130 | |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function associate(string $role, string $permission, string $rule = AllowRule::class): PermissionManager |
141 | 141 | { |
142 | - if (!$this->hasRole($role)) { |
|
142 | + if (!$this->hasRole($role)){ |
|
143 | 143 | throw new RoleException("Undefined role '{$role}'"); |
144 | 144 | } |
145 | 145 | |
146 | - if (!$this->rules->has($rule)) { |
|
146 | + if (!$this->rules->has($rule)){ |
|
147 | 147 | throw new PermissionException("Undefined rule '{$rule}'"); |
148 | 148 | } |
149 | 149 | |
@@ -176,14 +176,14 @@ discard block |
||
176 | 176 | */ |
177 | 177 | private function findRule(string $role, string $permission): string |
178 | 178 | { |
179 | - if (isset($this->permissions[$role][$permission])) { |
|
179 | + if (isset($this->permissions[$role][$permission])){ |
|
180 | 180 | //O(1) check |
181 | 181 | return $this->permissions[$role][$permission]; |
182 | 182 | } |
183 | 183 | |
184 | 184 | //Matching using star syntax |
185 | - foreach ($this->permissions[$role] as $pattern => $rule) { |
|
186 | - if ($this->matcher->matches($permission, $pattern)) { |
|
185 | + foreach ($this->permissions[$role] as $pattern => $rule){ |
|
186 | + if ($this->matcher->matches($permission, $pattern)){ |
|
187 | 187 | return $rule; |
188 | 188 | } |
189 | 189 | } |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function addRole(string $role): PermissionManager |
74 | 74 | { |
75 | - if ($this->hasRole($role)) { |
|
75 | + if ($this->hasRole($role)) |
|
76 | + { |
|
76 | 77 | throw new RoleException("Role '{$role}' already exists"); |
77 | 78 | } |
78 | 79 | |
@@ -90,7 +91,8 @@ discard block |
||
90 | 91 | */ |
91 | 92 | public function removeRole(string $role): PermissionManager |
92 | 93 | { |
93 | - if (!$this->hasRole($role)) { |
|
94 | + if (!$this->hasRole($role)) |
|
95 | + { |
|
94 | 96 | throw new RoleException("Undefined role '{$role}'"); |
95 | 97 | } |
96 | 98 | |
@@ -112,7 +114,8 @@ discard block |
||
112 | 114 | */ |
113 | 115 | public function getPermissions(string $role): array |
114 | 116 | { |
115 | - if (!$this->hasRole($role)) { |
|
117 | + if (!$this->hasRole($role)) |
|
118 | + { |
|
116 | 119 | throw new RoleException("Undefined role '{$role}'"); |
117 | 120 | } |
118 | 121 | |
@@ -124,7 +127,8 @@ discard block |
||
124 | 127 | */ |
125 | 128 | public function getRule(string $role, string $permission): RuleInterface |
126 | 129 | { |
127 | - if (!$this->hasRole($role)) { |
|
130 | + if (!$this->hasRole($role)) |
|
131 | + { |
|
128 | 132 | throw new RoleException("Undefined role '{$role}'"); |
129 | 133 | } |
130 | 134 | |
@@ -139,11 +143,13 @@ discard block |
||
139 | 143 | */ |
140 | 144 | public function associate(string $role, string $permission, string $rule = AllowRule::class): PermissionManager |
141 | 145 | { |
142 | - if (!$this->hasRole($role)) { |
|
146 | + if (!$this->hasRole($role)) |
|
147 | + { |
|
143 | 148 | throw new RoleException("Undefined role '{$role}'"); |
144 | 149 | } |
145 | 150 | |
146 | - if (!$this->rules->has($rule)) { |
|
151 | + if (!$this->rules->has($rule)) |
|
152 | + { |
|
147 | 153 | throw new PermissionException("Undefined rule '{$rule}'"); |
148 | 154 | } |
149 | 155 | |
@@ -176,14 +182,17 @@ discard block |
||
176 | 182 | */ |
177 | 183 | private function findRule(string $role, string $permission): string |
178 | 184 | { |
179 | - if (isset($this->permissions[$role][$permission])) { |
|
185 | + if (isset($this->permissions[$role][$permission])) |
|
186 | + { |
|
180 | 187 | //O(1) check |
181 | 188 | return $this->permissions[$role][$permission]; |
182 | 189 | } |
183 | 190 | |
184 | 191 | //Matching using star syntax |
185 | - foreach ($this->permissions[$role] as $pattern => $rule) { |
|
186 | - if ($this->matcher->matches($permission, $pattern)) { |
|
192 | + foreach ($this->permissions[$role] as $pattern => $rule) |
|
193 | + { |
|
194 | + if ($this->matcher->matches($permission, $pattern)) |
|
195 | + { |
|
187 | 196 | return $rule; |
188 | 197 | } |
189 | 198 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | PermissionsInterface $permissions, |
37 | 37 | ActorInterface $actor = null, |
38 | 38 | array $roles = [] |
39 | - ) { |
|
39 | + ){ |
|
40 | 40 | $this->roles = $roles; |
41 | 41 | $this->actor = $actor; |
42 | 42 | $this->permissions = $permissions; |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | public function allows(string $permission, array $context = []): bool |
49 | 49 | { |
50 | 50 | $allows = false; |
51 | - foreach ($this->getRoles() as $role) { |
|
52 | - if (!$this->permissions->hasRole($role)) { |
|
51 | + foreach ($this->getRoles() as $role){ |
|
52 | + if (!$this->permissions->hasRole($role)){ |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getActor(): ActorInterface |
97 | 97 | { |
98 | - if (empty($this->actor)) { |
|
98 | + if (empty($this->actor)){ |
|
99 | 99 | throw new GuardException('Unable to get Guard Actor, no value set'); |
100 | 100 | } |
101 | 101 |
@@ -48,8 +48,10 @@ discard block |
||
48 | 48 | public function allows(string $permission, array $context = []): bool |
49 | 49 | { |
50 | 50 | $allows = false; |
51 | - foreach ($this->getRoles() as $role) { |
|
52 | - if (!$this->permissions->hasRole($role)) { |
|
51 | + foreach ($this->getRoles() as $role) |
|
52 | + { |
|
53 | + if (!$this->permissions->hasRole($role)) |
|
54 | + { |
|
53 | 55 | continue; |
54 | 56 | } |
55 | 57 | |
@@ -95,7 +97,8 @@ discard block |
||
95 | 97 | */ |
96 | 98 | public function getActor(): ActorInterface |
97 | 99 | { |
98 | - if (empty($this->actor)) { |
|
100 | + if (empty($this->actor)) |
|
101 | + { |
|
99 | 102 | throw new GuardException('Unable to get Guard Actor, no value set'); |
100 | 103 | } |
101 | 104 |
@@ -40,10 +40,10 @@ |
||
40 | 40 | */ |
41 | 41 | public function matches(string $string, string $pattern): bool |
42 | 42 | { |
43 | - if ($string === $pattern) { |
|
43 | + if ($string === $pattern){ |
|
44 | 44 | return true; |
45 | 45 | } |
46 | - if (!$this->isPattern($pattern)) { |
|
46 | + if (!$this->isPattern($pattern)){ |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | return (bool)preg_match($this->getRegex($pattern), $string); |
@@ -40,10 +40,12 @@ |
||
40 | 40 | */ |
41 | 41 | public function matches(string $string, string $pattern): bool |
42 | 42 | { |
43 | - if ($string === $pattern) { |
|
43 | + if ($string === $pattern) |
|
44 | + { |
|
44 | 45 | return true; |
45 | 46 | } |
46 | - if (!$this->isPattern($pattern)) { |
|
47 | + if (!$this->isPattern($pattern)) |
|
48 | + { |
|
47 | 49 | return false; |
48 | 50 | } |
49 | 51 | return (bool)preg_match($this->getRegex($pattern), $string); |
@@ -63,20 +63,20 @@ |
||
63 | 63 | $parameters = compact('actor', 'permission', 'context') + $context; |
64 | 64 | |
65 | 65 | //Mounting aliases |
66 | - foreach (static::ALIASES as $target => $alias) { |
|
66 | + foreach (static::ALIASES as $target => $alias){ |
|
67 | 67 | $parameters[$target] = $parameters[$alias]; |
68 | 68 | } |
69 | 69 | |
70 | - try { |
|
70 | + try{ |
|
71 | 71 | $method = new \ReflectionMethod($this, static::CHECK_METHOD); |
72 | 72 | $method->setAccessible(true); |
73 | - } catch (\ReflectionException $e) { |
|
73 | + }catch (\ReflectionException $e){ |
|
74 | 74 | throw new RuleException($e->getMessage(), $e->getCode(), $e); |
75 | 75 | } |
76 | 76 | |
77 | - try { |
|
77 | + try{ |
|
78 | 78 | return $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
79 | - } catch (\Throwable $e) { |
|
79 | + }catch (\Throwable $e){ |
|
80 | 80 | throw new RuleException(sprintf('[%s] %s', get_class($this), $e->getMessage()), $e->getCode(), $e); |
81 | 81 | } |
82 | 82 | } |
@@ -63,20 +63,27 @@ |
||
63 | 63 | $parameters = compact('actor', 'permission', 'context') + $context; |
64 | 64 | |
65 | 65 | //Mounting aliases |
66 | - foreach (static::ALIASES as $target => $alias) { |
|
66 | + foreach (static::ALIASES as $target => $alias) |
|
67 | + { |
|
67 | 68 | $parameters[$target] = $parameters[$alias]; |
68 | 69 | } |
69 | 70 | |
70 | - try { |
|
71 | + try |
|
72 | + { |
|
71 | 73 | $method = new \ReflectionMethod($this, static::CHECK_METHOD); |
72 | 74 | $method->setAccessible(true); |
73 | - } catch (\ReflectionException $e) { |
|
75 | + } |
|
76 | + catch (\ReflectionException $e) |
|
77 | + { |
|
74 | 78 | throw new RuleException($e->getMessage(), $e->getCode(), $e); |
75 | 79 | } |
76 | 80 | |
77 | - try { |
|
81 | + try |
|
82 | + { |
|
78 | 83 | return $method->invokeArgs($this, $this->resolver->resolveArguments($method, $parameters)); |
79 | - } catch (\Throwable $e) { |
|
84 | + } |
|
85 | + catch (\Throwable $e) |
|
86 | + { |
|
80 | 87 | throw new RuleException(sprintf('[%s] %s', get_class($this), $e->getMessage()), $e->getCode(), $e); |
81 | 88 | } |
82 | 89 | } |