Completed
Pull Request — master (#5)
by Ondrej
01:58
created

StrategyEnum::DENY_UNLESS_ALLOWED()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace SpareParts\Overseer;
3
4
5
class StrategyEnum
6
{
7
    /**
8
     * @var string
9
     */
10
    private $value;
11
12
    /**
13
     * @var self[]
14
     */
15
    static protected $registry = [];
16
17
    private function __construct($value)
18
    {
19
        $this->value = $value;
20
    }
21
22
23
    /**
24
     * @return self
25
     */
26
    public static function FIRST_VOTE_DECIDES()
27
    {
28
        return static::instance('first_vote_decides');
29
    }
30
31
32
    /**
33
     * @return self
34
     */
35
    public static function ALLOW_UNLESS_DENIED()
36
    {
37
        return static::instance('allow_unless_denied');
38
    }
39
40
41
    /**
42
     * @return self
43
     */
44
    public static function DENY_UNLESS_ALLOWED()
45
    {
46
        return static::instance('deny_unless_allowed');
47
    }
48
49
50
    /**
51
     * @return self
52
     */
53
    public static function EVERYONE_MUST_ALLOW_TO_BE_ALLOWED()
54
    {
55
        return static::instance('everyone_must_allow_to_be_allowed');
56
    }
57
58
59
    /**
60
     * @return self
61
     */
62
    public static function EVERYONE_MUST_DENY_TO_BE_DENIED()
63
    {
64
        return static::instance('everyone_must_deny_to_be_denied');
65
    }
66
67
68
    /**
69
     * @param string $string
70
     * @return self
71
     */
72 View Code Duplication
    protected static function instance($string)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        if (!isset(static::$registry[$string])) {
75
            static::$registry[$string] = new static($string);
76
        }
77
        return static::$registry[$string];
78
    }
79
80
81
    /**
82
     * @return string
83
     */
84
    public function __toString()
85
    {
86
        return $this->value;
87
    }
88
}
89