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

Specification   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 64
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B satisfy() 0 18 10
A isStatic() 0 4 1
A isMagic() 0 4 1
A getParentMode() 0 4 1
A expandMode() 0 14 3
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