Completed
Push — develop ( 725207...6c2664 )
by
unknown
08:34
created

MayChangeCv::assert()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 7
loc 7
rs 9.2
c 1
b 0
f 0
cc 4
eloc 5
nc 4
nop 4
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Cv\Acl\Assertion;
12
13
use Auth\Entity\UserInterface;
14
use Core\Entity\PermissionsInterface;
15
use Cv\Entity\CvInterface;
16
use Zend\Permissions\Acl\Acl;
17
use Zend\Permissions\Acl\Assertion\AssertionInterface;
18
use Zend\Permissions\Acl\Resource\ResourceInterface;
19
use Zend\Permissions\Acl\Role\RoleInterface;
20
21
/**
22
 * ${CARET}
23
 * 
24
 * @author Mathias Gelhausen <[email protected]>
25
 * @todo write test 
26
 */
27 View Code Duplication
class MayChangeCv implements AssertionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
{
29
    /**
30
     * Returns true if and only if the assertion conditions are met
31
     *
32
     * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
33
     * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
34
     * privileges, respectively.
35
     *
36
     * @param  Acl               $acl
37
     * @param  RoleInterface     $role
0 ignored issues
show
Documentation introduced by
Should the type for parameter $role not be null|RoleInterface?

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.

Loading history...
38
     * @param  ResourceInterface $resource
0 ignored issues
show
Documentation introduced by
Should the type for parameter $resource not be null|ResourceInterface?

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.

Loading history...
39
     * @param  string            $privilege
0 ignored issues
show
Documentation introduced by
Should the type for parameter $privilege not be string|null?

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.

Loading history...
40
     *
41
     * @return bool
42
     */
43
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
44
    {
45
        return $role instanceOf UserInterface
46
               && $resource instanceOf CvInterface
47
               && 'edit' == $privilege
48
               && $resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_CHANGE);
49
    }
50
51
52
}