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

ReadableEnumTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 8
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readableFor() 8 8 2
A getReadable() 0 4 1
A __toString() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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