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

ReadableEnum   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A readableFor() 0 9 2
A readablesFor() 0 4 1
A getReadable() 0 4 1
A __toString() 0 4 1
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