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

PermissionsAwareTrait::getPermissions()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 17
rs 9.2
c 1
b 0
f 1
cc 4
eloc 10
nc 5
nop 0
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 Core\Entity;
12
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
15
/**
16
 * ${CARET}
17
 *
18
 * @property string $permissionsType
19
 *
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @todo write test
22
 *
23
 */
24
trait PermissionsAwareTrait
25
{
26
    /**
27
     * The permissions.
28
     *
29
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
30
     * @var PermissionsInterface
31
     */
32
    private $permissions;
33
34
35
    public function setPermissions(PermissionsInterface $permissions)
36
    {
37
        $this->permissions = $permissions;
38
39
        return $this;
40
    }
41
42
    /**
43
     * Gets the permissions entity.
44
     *
45
     * @internal
46
     *      If no permissions entity is set, it creates a
47
     *      {@link Permissions} instance and set its type to
48
     *      either the value provided with the property 'permissionsType' or
49
     *      to the entity class name, where '\\Entity\\' is replaced with '/',
50
     *      which leads to types such as MODULE/NAME.
51
     *
52
     *      Calls a method named 'setupPermissions' and passing the newly
53
     *      created permissions instance if such a method exists in the using class.
54
     *
55
     * @return PermissionsInterface
56
     */
57
    public function getPermissions()
58
    {
59
        if (!$this->permissions) {
60
            $type = property_exists($this, 'permissionsType')
61
                ? $this->permissionsType
62
                : str_replace('\\Entity\\', '/', static::class);
63
            $permissions = new Permissions($type);
64
65
            if (method_exists($this, 'setupPermissions')) {
66
                $this->setupPermissions($permissions);
0 ignored issues
show
Bug introduced by
The method setupPermissions() does not exist on Core\Entity\PermissionsAwareTrait. Did you maybe mean setPermissions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
            }
68
69
            $this->setPermissions($permissions);
70
        }
71
72
        return $this->permissions;
73
    }
74
}