Enum::fromNative()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
namespace EventStore\ValueObjects\Enum;
3
4
use EventStore\ValueObjects\Util\Util;
5
use EventStore\ValueObjects\ValueObjectInterface;
6
use MabeEnum\Enum as BaseEnum;
7
8
abstract class Enum extends BaseEnum implements ValueObjectInterface
9
{
10
    /**
11
     * Returns a new Enum object from passed value matching argument
12
     *
13
     * @param  string $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
14
     * @return static
15
     */
16
    public static function fromNative()
17
    {
18
        return static::get(func_get_arg(0));
19
    }
20
21
    /**
22
     * Returns the PHP native value of the enum
23
     *
24
     * @return mixed
25
     */
26 21
    public function toNative()
27
    {
28 21
        return parent::getValue();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getValue() instead of toNative()). Are you sure this is correct? If so, you might want to change this to $this->getValue().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
29
    }
30
31
    /**
32
     * Tells whether two Enum objects are sameValueAs by comparing their values
33
     *
34
     * @param  Enum $enum
35
     * @return bool
36
     */
37 View Code Duplication
    public function sameValueAs(ValueObjectInterface $enum)
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...
38
    {
39
        if (false === Util::classEquals($this, $enum)) {
40
            return false;
41
        }
42
43
        return $this->toNative() === $enum->toNative();
44
    }
45
46
    /**
47
     * Returns a native string representation of the Enum value
48
     *
49
     * @return string
50
     */
51 6
    public function __toString()
52
    {
53 6
        return \strval($this->toNative());
54
    }
55
}
56