Code Duplication    Length = 57-66 lines in 2 locations

src/StrategyEnum.php 1 location

@@ 5-70 (lines=66) @@
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 private $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
     * @param $string
52
     * @return self
53
     */
54
    private static function instance($string)
55
    {
56
        if (!isset(static::$registry[$string])) {
57
            static::$registry[$string] = new static($string);
58
        }
59
        return static::$registry[$string];
60
    }
61
62
63
    /**
64
     * @return string
65
     */
66
    public function __toString()
67
    {
68
        return $this->value;
69
    }
70
}
71

src/VotingDecisionEnum.php 1 location

@@ 5-61 (lines=57) @@
2
namespace SpareParts\Overseer;
3
4
5
final class VotingDecisionEnum
6
{
7
    /**
8
     * @var string
9
     */
10
    private $value;
11
12
    /**
13
     * @var self[]
14
     */
15
    static private $registry = [];
16
17
    private function __construct($value)
18
    {
19
        $this->value = $value;
20
    }
21
22
23
    /**
24
     * @return self
25
     */
26
    public static function ALLOWED()
27
    {
28
        return static::instance('allowed');
29
    }
30
31
32
    /**
33
     * @return self
34
     */
35
    public static function DENIED()
36
    {
37
        return static::instance('allowed');
38
    }
39
40
41
    /**
42
     * @param $string
43
     * @return self
44
     */
45
    private static function instance($string)
46
    {
47
        if (!isset(static::$registry[$string])) {
48
            static::$registry[$string] = new static($string);
49
        }
50
        return static::$registry[$string];
51
    }
52
53
54
    /**
55
     * @return string
56
     */
57
    public function __toString()
58
    {
59
        return $this->value;
60
    }
61
}