FlagPermissionResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 3
crap 6
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->scope = $scope;
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