Test Failed
Push — master ( a5a28b...999969 )
by Marcin
02:51
created

Color::toGreyScale()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 33
Code Lines 27

Duplication

Lines 33
Ratio 100 %

Importance

Changes 0
Metric Value
dl 33
loc 33
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 27
nc 4
nop 1
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
16
namespace mrcnpdlk\Grandstream\XMLApp\Helper;
17
18
19
class Color
20
{
21
22
    /**
23
     * @var string
24
     */
25
    private $sColor;
26
27
    public function __construct(int $tone = null)
28
    {
29
        $this->sColor = $this->toGreyScale($tone);
30
    }
31
32
    /**
33
     * @param int|null $tone
34
     *
35
     * @return string
36
     */
37 View Code Duplication
    private function toGreyScale(int $tone = null)
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...
38
    {
39
        if (is_null($tone)) {
40
            return 'None';
41
        }
42
        $tTones = [
43
            'White',
44
            'Light6',
45
            'Light5',
46
            'Light4',
47
            'Light3',
48
            'Light2',
49
            'Light1',
50
            'LightGray',
51
            'Gray',
52
            'Dark1',
53
            'Dark2',
54
            'Dark3',
55
            'Dark4',
56
            'Dark5',
57
            'Dark6',
58
            'Black',
59
        ];
60
        $levels = count($tTones);
61
        $index  = (int)ceil($levels * $tone / 100) - 1;
62
        if ($index < 0) {
63
            $index = 0;
64
        } elseif ($index >= $levels) {
65
            $index = $levels - 1;
66
        }
67
68
        return $tTones[$index];
69
    }
70
71
    public function get()
72
    {
73
        return $this->sColor;
74
    }
75
}