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

Color::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
}