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

FlagResolverAbstract::resolve()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 9
nc 12
nop 3
crap 30
1
<?php
2
3
namespace Dazzle\Filesystem\Driver\Flag;
4
5
abstract class FlagResolverAbstract
6
{
7
    /**
8
     * @return int
9
     */
10
    abstract protected function getFlags();
11
12
    /**
13
     * @return array
14
     */
15
    abstract protected function getMapping();
16
17
    /**
18
     * @see FlagResolverInterface::resolve
19
     */
20
    public function resolve($flagString, $flags = null, $mapping = null)
21
    {
22
        if ($flags === null)
23
        {
24
            $flags = $this->getFlags();
25
        }
26
27
        if ($mapping === null)
28
        {
29
            $mapping = $this->getMapping();
30
        }
31
32
        foreach (str_split($flagString) as $flag)
33
        {
34
            if (isset($mapping[$flag]))
35
            {
36
                $flags |= $mapping[$flag];
37
            }
38
        }
39
40
        return $flags;
41
    }
42
}
43