Enum   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 0
cbo 0
dl 0
loc 39
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A valueOf() 0 4 1
A __toString() 0 4 1
A __construct() 0 11 2
A __callStatic() 0 11 2
1
<?php
2
/**
3
 * spindle/types
4
 *
5
 * @license CC0-1.0 (Public Domain) https://creativecommons.org/publicdomain/zero/1.0/
6
 */
7
namespace Spindle\Types;
8
9
abstract class Enum
10
{
11
    private $scalar;
12
    private static $cache = array();
13
14 3
    function __construct($value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
    {
16 3
        $ref = new \ReflectionObject($this);
17 3
        $consts = $ref->getConstants();
18 3
        if (! in_array($value, $consts, true)) {
19 1
            throw new \InvalidArgumentException(
20 1
                'value must be ' . implode(',', $consts) . ". but $value passed."
21 1
            );
22
        }
23 2
        $this->scalar = $value;
24 2
    }
25
26 1
    final static function __callStatic($name, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
    {
28 1
        $class = get_called_class();
29 1
        $constantName = "$class::$name";
30 1
        if (isset(self::$cache[$constantName])) {
31 1
            return self::$cache[$constantName];
32
        } else {
33 1
            $const = constant($constantName);
34 1
            return self::$cache[$constantName] = new $class($const);
35
        }
36
    }
37
38 2
    final function valueOf()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    {
40 2
        return $this->scalar;
41
    }
42
43 2
    final function __toString()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44
    {
45 2
        return (string) $this->scalar;
46
    }
47
}
48