Color   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 65
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B toGreyScale() 0 33 4
A get() 0 4 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
 * @package mrcnpdlk\Grandstream\XMLApp\Helper
22
 */
23
class Color
24
{
25
26
    /**
27
     * @var string
28
     */
29
    private $sColor;
30
31
    /**
32
     * Color constructor.
33
     *
34
     * @param int|null $tone 0-100% greyscale tone. NULL = None
35
     */
36 4
    public function __construct(int $tone = null)
37
    {
38 4
        $this->sColor = $this->toGreyScale($tone);
39 4
    }
40
41
    /**
42
     * @param int|null $tone 0 (White) - 100% (Black) greyscale tone. NULL = None
43
     *
44
     * @return string
45
     */
46 4
    private function toGreyScale(int $tone = null)
47
    {
48 4
        if (is_null($tone)) {
49 1
            return 'None';
50
        }
51
        $tTones = [
52 4
            'White',
53
            'Light6',
54
            'Light5',
55
            'Light4',
56
            'Light3',
57
            'Light2',
58
            'Light1',
59
            'LightGray',
60
            'Gray',
61
            'Dark1',
62
            'Dark2',
63
            'Dark3',
64
            'Dark4',
65
            'Dark5',
66
            'Dark6',
67
            'Black',
68
        ];
69 4
        $levels = count($tTones);
70 4
        $index  = (int)ceil($levels * $tone / 100) - 1;
71 4
        if ($index < 0) {
72 2
            $index = 0;
73 4
        } elseif ($index >= $levels) {
74 1
            $index = $levels - 1;
75
        }
76
77 4
        return $tTones[$index];
78
    }
79
80
    /**
81
     * @return string
82
     */
83 4
    public function get()
84
    {
85 4
        return $this->sColor;
86
    }
87
}
88