PermissionAwareTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPermissions() 0 4 1
A setPermissions() 0 5 1
A isReadable() 0 4 1
A isWritable() 0 4 1
A isDeletable() 0 4 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Storage
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Storage\Traits;
16
17
use Phossa2\Storage\Interfaces\PermissionAwareInterface;
18
19
/**
20
 * PermissionAwareTrait
21
 *
22
 * Implementation of PermissionAwareInterface
23
 *
24
 * @package Phossa2\Storage
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     PermissionAwareInterface
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
trait PermissionAwareTrait
31
{
32
    /**
33
     * permissions
34
     *
35
     * @var    int
36
     * @access protected
37
     */
38
    protected $perm = PermissionAwareInterface::PERM_ALL;
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function getPermissions()/*# : int */
44
    {
45
        return $this->perm;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function setPermissions(/*# int */ $permissions)
52
    {
53
        $this->perm = $permissions;
54
        return $this;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function isReadable()/*# : bool */
61
    {
62
        return (bool) ($this->perm & PermissionAwareInterface::PERM_READ);
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function isWritable()/*# : bool */
69
    {
70
        return (bool) ($this->perm & PermissionAwareInterface::PERM_WRITE);
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function isDeletable()/*# : bool */
77
    {
78
        return (bool) ($this->perm & PermissionAwareInterface::PERM_WRITE);
79
    }
80
}
81