Enum::toNative()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\System;
13
14
use Cubiche\Core\Enum\Enum as BaseEnum;
15
use Cubiche\Domain\Model\NativeValueObjectInterface;
16
17
/**
18
 * Enum Class.
19
 *
20
 * @author Karel Osorio Ramírez <[email protected]>
21
 */
22
abstract class Enum extends BaseEnum implements NativeValueObjectInterface
23
{
24
    /**
25
     * @param mixed $value
26
     *
27
     * @return \Cubiche\Domain\System\Enum
28
     */
29
    public static function fromNative($value)
30
    {
31
        try {
32
            return new static($value);
33
        } catch (\UnexpectedValueException $e) {
34
            throw new \InvalidArgumentException($e->getMessage(), $e->getCode());
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function toNative()
42
    {
43
        return $this->value();
44
    }
45
}
46