Completed
Pull Request — master (#1)
by Ondrej
01:51
created

VotingDecisionEnum   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 57
loc 57
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A ALLOWED() 4 4 1
A DENIED() 4 4 1
A instance() 7 7 2
A __toString() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace SpareParts\Overseer;
3
4
5 View Code Duplication
final class VotingDecisionEnum
0 ignored issues
show
Duplication introduced by
This class 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...
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');
0 ignored issues
show
Comprehensibility introduced by
Since SpareParts\Overseer\VotingDecisionEnum is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
29
    }
30
31
32
    /**
33
     * @return self
34
     */
35
    public static function DENIED()
36
    {
37
        return static::instance('allowed');
0 ignored issues
show
Comprehensibility introduced by
Since SpareParts\Overseer\VotingDecisionEnum is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
38
    }
39
40
41
    /**
42
     * @param $string
43
     * @return self
44
     */
45
    private static function instance($string)
46
    {
47
        if (!isset(static::$registry[$string])) {
0 ignored issues
show
Comprehensibility introduced by
Since SpareParts\Overseer\VotingDecisionEnum is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
48
            static::$registry[$string] = new static($string);
0 ignored issues
show
Comprehensibility introduced by
Since SpareParts\Overseer\VotingDecisionEnum is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
49
        }
50
        return static::$registry[$string];
0 ignored issues
show
Comprehensibility introduced by
Since SpareParts\Overseer\VotingDecisionEnum is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
51
    }
52
53
54
    /**
55
     * @return string
56
     */
57
    public function __toString()
58
    {
59
        return $this->value;
60
    }
61
}