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

MayViewCv::assert()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 9
loc 9
rs 8.8571
c 1
b 0
f 0
cc 5
eloc 6
nc 7
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 Cv\Entity\Cv;
14
use Auth\Entity\UserInterface;
15
use Core\Entity\PermissionsInterface;
16
use Cv\Entity\CvInterface;
17
use Cv\Entity\Status;
18
use Zend\Permissions\Acl\Acl;
19
use Zend\Permissions\Acl\Assertion\AssertionInterface;
20
use Zend\Permissions\Acl\Resource\ResourceInterface;
21
use Zend\Permissions\Acl\Role\RoleInterface;
22
23
/**
24
 * ${CARET}
25
 * 
26
 * @author Mathias Gelhausen <[email protected]>
27
 * @todo write test 
28
 */
29 View Code Duplication
class MayViewCv 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...
30
{
31
    /**
32
     * Returns true if and only if the assertion conditions are met
33
     *
34
     * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
35
     * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
36
     * privileges, respectively.
37
     *
38
     * @param  Acl               $acl
39
     * @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...
40
     * @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...
41
     * @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...
42
     *
43
     * @return bool
44
     */
45
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
46
    {
47
        /* @var ResourceInterface|Cv $resource */
48
        return $role instanceOf UserInterface
49
               && $resource instanceOf CvInterface
50
               && 'view' == $privilege
51
               && ($resource->getPermissions()->isGranted($role, PermissionsInterface::PERMISSION_VIEW)
52
                   || Status::PUBLIC_TO_ALL == (string) $resource->getStatus());
53
    }
54
55
56
}