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 Kunstmaan\NodeBundle\Helper\Services; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission; |
||
6 | |||
7 | use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\MaskBuilder, |
||
8 | Symfony\Component\DependencyInjection\ContainerInterface; |
||
9 | |||
10 | use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity, |
||
11 | Symfony\Component\Security\Acl\Exception\AclNotFoundException, |
||
12 | Symfony\Component\Security\Acl\Model\MutableAclProviderInterface, |
||
13 | Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface; |
||
14 | |||
15 | /** |
||
16 | * Service to add the correct permissions to new HasNodeInterface objects. |
||
17 | * |
||
18 | */ |
||
19 | class ACLPermissionCreatorService |
||
20 | { |
||
21 | |||
22 | /* @var MutableAclProviderInterface $aclProvider */ |
||
23 | protected $aclProvider; |
||
24 | public function setAclProvider($aclProvider) |
||
25 | { |
||
26 | $this->aclProvider = $aclProvider; |
||
27 | } |
||
28 | |||
29 | /* @var ObjectIdentityRetrievalStrategyInterface $oidStrategy */ |
||
30 | protected $oidStrategy; |
||
31 | public function setObjectIdentityRetrievalStrategy($oidStrategy) |
||
32 | { |
||
33 | $this->oidStrategy = $oidStrategy; |
||
34 | } |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Sets the Container. This is still here for backwards compatibility. |
||
39 | * The ContainerAwareInterface has been removed so the container won't be injected automatically. |
||
40 | * This function is just there for code that calls it manually. |
||
41 | * |
||
42 | * @param ContainerInterface $container A ContainerInterface instance. |
||
0 ignored issues
–
show
|
|||
43 | * |
||
44 | * @api |
||
45 | */ |
||
46 | public function setContainer(ContainerInterface $container = null) |
||
47 | { |
||
48 | $this->setAclProvider($container->get('security.acl.provider')); |
||
0 ignored issues
–
show
It seems like
$container is not always an object, but can also be of type null . Maybe add an additional type check?
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: function someFunction(A $objectMaybe = null)
{
if ($objectMaybe instanceof A) {
$objectMaybe->doSomething();
}
}
Loading history...
|
|||
49 | $this->setObjectIdentityRetrievalStrategy($container->get('security.acl.object_identity_retrieval_strategy')); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param object $object |
||
54 | * |
||
55 | * Create ACL permissions for an object. |
||
56 | */ |
||
57 | public function createPermission($object) |
||
58 | { |
||
59 | $aclProvider = $this->aclProvider; |
||
60 | |||
61 | $oidStrategy = $this->oidStrategy; |
||
62 | |||
63 | $objectIdentity = $oidStrategy->getObjectIdentity($object); |
||
64 | try { |
||
65 | $aclProvider->deleteAcl($objectIdentity); |
||
66 | } catch (AclNotFoundException $e) { |
||
67 | // Don't fail when the ACL didn't exist yet. |
||
68 | } |
||
69 | $acl = $aclProvider->createAcl($objectIdentity); |
||
70 | |||
71 | $securityIdentity = new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'); |
||
72 | $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_VIEW); |
||
73 | |||
74 | $securityIdentity = new RoleSecurityIdentity('ROLE_ADMIN'); |
||
75 | $acl->insertObjectAce( |
||
76 | $securityIdentity, |
||
77 | MaskBuilder::MASK_VIEW | MaskBuilder::MASK_EDIT | MaskBuilder::MASK_DELETE | MaskBuilder::MASK_PUBLISH | MaskBuilder::MASK_UNPUBLISH |
||
78 | ); |
||
79 | |||
80 | $securityIdentity = new RoleSecurityIdentity('ROLE_SUPER_ADMIN'); |
||
81 | $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_IDDQD); |
||
82 | $aclProvider->updateAcl($acl); |
||
83 | } |
||
84 | |||
85 | } |
||
86 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.