Completed
Pull Request — master (#73)
by Maxime
01:40
created

ReadableEnum::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
abstract class ReadableEnum extends Enum implements ReadableEnumInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 10
    public static function readableFor($value): string
21
    {
22 10
        if (!static::accepts($value)) {
23 1
            throw new InvalidValueException($value, static::class);
24
        }
25 9
        $humanRepresentations = static::readables();
26
27 9
        return $humanRepresentations[$value];
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 6
    public static function readablesFor(array $values): array
34
    {
35 6
        return array_map('self::readableFor', $values);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function getReadable(): string
42
    {
43 1
        return static::readableFor($this->getValue());
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function __toString()
50
    {
51
        return $this->getReadable();
52
    }
53
}
54