Completed
Push — master ( da5b20...773556 )
by Kamil
03:06
created

FlagPermissionResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 71
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 15 2
A getFlags() 0 4 1
A getMapping() 0 4 1
1
<?php
2
3
namespace Dazzle\Filesystem\Driver\Flag;
4
5
class FlagPermissionResolver extends FlagResolverAbstract implements FlagResolverInterface
6
{
7
    /**
8
     * @var int|null
9
     */
10
    const DEFAULT_FLAG = null;
11
12
    /**
13
     * @var string
14
     */
15
    private $scope = '';
16
17
    /**
18
     * @var array
19
     */
20
    private $mapping = [
21
        'user' => [
22
            'w' => 128,
23
            'x' => 64,
24
            'r' => 256,
25
        ],
26
        'group' => [
27
            'w' => 16,
28
            'x' => 8,
29
            'r' => 32,
30
        ],
31
        'universe' => [
32
            'w' => 2,
33
            'x' => 1,
34
            'r' => 4,
35
        ],
36
    ];
37
38
    /**
39
     * @override
40
     * @inheritDoc
41
     */
42
    public function resolve($flag, $flags = null, $mapping = null)
43
    {
44
        $resultFlags = 0;
45
        $start = 0;
46
47
        foreach ([ 'universe', 'group', 'user' ] as $scope)
48
        {
49
            $this->currentScope = $scope;
0 ignored issues
show
Bug introduced by
The property currentScope does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
50
            $start -= 3;
51
            $chunk = substr($flag, $start, 3);
52
            $resultFlags |= parent::resolve($chunk, $flags, $mapping);
53
        }
54
55
        return $resultFlags;
56
    }
57
58
    /**
59
     * @override
60
     * @inheritDoc
61
     */
62
    protected function getFlags()
63
    {
64
        return static::DEFAULT_FLAG;
65
    }
66
67
    /**
68
     * @override
69
     * @inheritDoc
70
     */
71
    protected function getMapping()
72
    {
73
        return $this->mapping[$this->scope];
74
    }
75
}
76