adespresso /
FeatureBundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Ae\FeatureBundle\Security; |
||
| 4 | |||
| 5 | use Symfony\Component\Security\Core\SecurityContextInterface; |
||
| 6 | use Ae\FeatureBundle\Entity\Feature; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Controls access to a Feature. |
||
| 10 | * |
||
| 11 | * @author Carlo Forghieri <[email protected]> |
||
| 12 | */ |
||
| 13 | class FeatureSecurity |
||
| 14 | { |
||
| 15 | protected $context; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param \Symfony\Component\Security\Core\SecurityContextInterface $context |
||
| 19 | */ |
||
| 20 | 4 | public function __construct(SecurityContextInterface $context = null) |
|
| 21 | { |
||
| 22 | 4 | $this->context = $context; |
|
| 23 | 4 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @param \Ae\FeatureBundle\Entity\Feature $feature |
||
| 27 | * |
||
| 28 | * @return bool |
||
| 29 | */ |
||
| 30 | 4 | public function isGranted(Feature $feature) |
|
| 31 | { |
||
| 32 | 4 | if (null === $this->context) { |
|
| 33 | return false; |
||
| 34 | } |
||
| 35 | |||
| 36 | 4 | if (!$feature->isEnabled()) { |
|
| 37 | 1 | return false; |
|
| 38 | } |
||
| 39 | |||
| 40 | 3 | if ($feature->getRole()) { |
|
| 41 | 2 | if (!$this->context->isGranted($feature->getRole())) { |
|
| 42 | return false; |
||
| 43 | } |
||
| 44 | 2 | } |
|
| 45 | |||
| 46 | 3 | if ($feature->getParentRole()) { |
|
|
0 ignored issues
–
show
|
|||
| 47 | 1 | if (!$this->context->isGranted($feature->getParentRole())) { |
|
| 48 | 1 | return false; |
|
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | 2 | return true; |
|
| 53 | } |
||
| 54 | } |
||
| 55 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: