Completed
Pull Request — master (#94)
by Maxime
01:58
created

ReadableEnumTrait::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the "elao/enum" package.
5
 *
6
 * Copyright (C) Elao
7
 *
8
 * @author Elao <[email protected]>
9
 */
10
11
namespace Elao\Enum;
12
13
use Elao\Enum\Exception\InvalidValueException;
14
15
/**
16
 * @see ReadableEnumInterface which this trait implements
17
 */
18
trait ReadableEnumTrait
19
{
20
    use EnumTrait;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 View Code Duplication
    public static function readableFor($value): string
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...
26
    {
27
        if (!static::accepts($value)) {
28
            throw new InvalidValueException($value, static::class);
29
        }
30
31
        return static::readables()[$value];
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getReadable(): string
38
    {
39
        return static::readableFor($this->getValue());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function __toString()
46
    {
47
        return $this->getReadable();
48
    }
49
}
50