Completed
Push — master ( e41e91...2b4213 )
by Aleh
01:47 queued 01:39
created

Specification::satisfy()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 7.2765
cc 10
eloc 11
nc 7
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Padawan\Domain\Project\Collection;
4
5
use Padawan\Domain\Project\Node\MethodData;
6
7
class Specification
8
{
9
    /**
10
     * @param $mode string
11
     * @param $static int|bool
12
     * @param $magic bool
13
     */
14
    public function __construct($mode = 'private', $static = false, $magic = false)
15
    {
16
        $this->expandMode($mode);
17
        $this->showStatic = $static;
18
        $this->magic = $magic;
19
    }
20
    public function satisfy($node)
21
    {
22
        if (!$this->allowProtected && $node->isProtected()) {
23
            return false;
24
        }
25
        if (!$this->allowPrivate && $node->isPrivate()) {
26
            return false;
27
        }
28
        if ($node instanceof MethodData) {
29
            if ($node->isMagic() && !$this->magic) {
30
                return false;
31
            }
32
        }
33
        if ($this->showStatic < 2 && $node->isStatic() != $this->showStatic) {
34
            return false;
35
        }
36
        return true;
37
    }
38
    public function isStatic()
39
    {
40
        return $this->showStatic;
41
    }
42
    public function isMagic()
43
    {
44
        return $this->magic;
45
    }
46
    public function getParentMode()
47
    {
48
        return $this->parentMode;
49
    }
50
    protected function expandMode($mode)
51
    {
52
        if ($mode === 'private') {
53
            $this->allowProtected = $this->allowPrivate = true;
54
            $this->parentMode = 'protected';
55
        } elseif ($mode === 'protected') {
56
            $this->allowProtected = true;
57
            $this->allowPrivate = false;
58
            $this->parentMode = 'protected';
59
        } else {
60
            $this->allowProtected = $this->allowPrivate = false;
61
            $this->parentMode = 'public';
62
        }
63
    }
64
65
    private $allowProtected;
66
    private $allowPrivate;
67
    private $showStatic;
68
    private $magic;
69
    private $parentMode;
70
}
71