Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
81.82% |
9 / 11 |
| getValue | |
100.00% |
1 / 1 |
0 | |
100.00% |
1 / 1 |
|||
| __toString | |
0.00% |
0 / 1 |
0 | |
0.00% |
0 / 1 |
|||
| Enum | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
3.05 | |
81.82% |
9 / 11 |
| __construct | |
0.00% |
0 / 1 |
2.02 | |
83.33% |
5 / 6 |
|||
| __callStatic | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| <?php | |
| namespace Puyo\DataStructure; | |
| /** | |
| * Enumlator | |
| */ | |
| abstract class Enum | |
| { | |
| private $scalar; | |
| public function __construct($value) { | |
| $ref = new \ReflectionObject($this); | |
| $constans = $ref->getConstants(); | |
| if(!in_array($value, $constans, true)) { | |
| throw new \InvalidArgumentException(); | |
| } | |
| $this->scalar = $value; | |
| } | |
| /** | |
| * $className::constName() でインスタンスを作れるように | |
| * @param string $label | |
| * @param array $args | |
| * @return self | |
| */ | |
| final public static function __callStatic($label, $args) { | |
| $className = get_called_class(); | |
| $const = constant("${className}::${label}"); | |
| return new $className($const); | |
| } | |
| final public function getValue() { | |
| return $this->scalar; | |
| } | |
| final public function __toString() { | |
| return (string) $this->scalar; | |
| } | |
| } |