Completed
Branch master (610f90)
by Michael
07:23 queued 02:42
created

colorTools::foncer()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 36
Code Lines 19

Duplication

Lines 11
Ratio 30.56 %

Importance

Changes 0
Metric Value
cc 6
eloc 19
c 0
b 0
f 0
nc 9
nop 3
dl 11
loc 36
rs 8.439
1
<?php
2
3
/**
4
 * Class ColorTools.
5
 */
6
class colorTools
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     *
10
     */
11
    public function __construct()
12
    {
13
    }
14
15
    /**************************************************************
16
     * Ajoute ou rtir un icrement sur chaque compsante RGB d'une couleur
17
     * Les valeur sont limiter au bornes inférieure et supérieure 0 et 255
18
     **************************************************************
19
     *
20
     * @param     $colorHexa
21
     * @param     $incrementRouge
22
     * @param     $incrementVert
23
     * @param     $incrementBleu
24
     * @param int $plancherRouge
25
     * @param int $plafondRouge
26
     * @param int $plancherVert
27
     * @param int $plafondVert
28
     * @param int $plancherBleu
29
     * @param int $plafondBleu
30
     *
31
     * @return string
32
     */
33
    public function modifierCouleur($colorHexa, $incrementRouge, $incrementVert, $incrementBleu, $plancherRouge = 0, $plafondRouge = 255, $plancherVert = 0, $plafondVert = 255, $plancherBleu = 0, $plafondBleu = 255)
34
    {
35
        $t10 = static::hexa2rgbA($colorHexa);
36
37
        $t10[1] = static::bornerValeur($t10[1] + $incrementRouge, $plancherRouge, $plafondRouge);
38
        $t10[2] = static::bornerValeur($t10[2] + $incrementVert, $plancherVert, $plafondVert);
39
        $t10[3] = static::bornerValeur($t10[3] + $incrementBleu, $plancherBleu, $plafondBleu);
40
41
        $newColorHexa = static::getHexaColorFromA($t10);
42
43
        return $newColorHexa;
44
    }
45
46
    /**************************************************************
47
     * Eclairci une couleur
48
     * elle borné pa un plancher et un plafond pur évite le tout blanc ou tout blanc
49
     * ou les blocage sur une couleur pur (ex #FF0000)
50
     **************************************************************
51
     * @param     $colorHexa
52
     * @param int $plancher
53
     * @param int $plafond
54
     * @return string
55
     */
56
    public static function eclaircir($colorHexa, $plancher = 0, $plafond = 255)
57
    {
58
        $tMin = array('', $plancher, $plancher, $plancher);
59
        $tMax = array('', $plafond, $plafond, $plafond);
0 ignored issues
show
Unused Code introduced by
$tMax is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
61
        $t10 = static::hexa2rgbA($colorHexa);
62
        // echo "<hr>";
63
        // ext_echoArray($t10);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
        $max = $plancher;
65 View Code Duplication
        for ($h = 1; $h <= 3; ++$h) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
            if ($max < $t10[$h]) {
67
                $max = $t10[$h];
68
            }
69
        }
70
71
        $increment = $plafond - $max;
72
73
        //     $t10[1] = $t10[1] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
        //     $t10[2] = $t10[2] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
        //     $t10[3] = $t10[3] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
77
        $min = 0;
78 View Code Duplication
        for ($h = 1; $h <= 3; ++$h) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
79
            $t10[$h] += $increment;
80
            if ($t10[$h] < $tMin[$h] && $min < ($tMin[$h] - $t10[$h])) {
81
                $min = ($tMin[$h] - $t10[$h]);
82
            }
83
        }
84
85
        // echo "{$colorHexa}-{$plancher}-{$plafond}<br>";
86
        // echo "{$min}-{$max}-{$increment}<br>";
87
88
        $t10[1] = static::bornerValeur($t10[1] + $min, $plancher, $plafond);
89
        $t10[2] = static::bornerValeur($t10[2] + $min, $plancher, $plafond);
90
        $t10[3] = static::bornerValeur($t10[3] + $min, $plancher, $plafond);
91
92
        // ext_echoArray($t10);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
93
94
        $newColorHexa = static::getHexaColorFromA($t10);
95
        // echo "colorHexa = {$newColorHexa}-{$colorHexa}<br>";
96
        return $newColorHexa;
97
    }
98
99
    /**************************************************************
100
     * Fonce une couleur
101
     * elle borné pa un plancher et un plafond pur évite le tout blanc ou tout blanc
102
     * ou les blocage sur une couleur pur (ex #FFFF00)
103
     **************************************************************
104
     * @param     $colorHexa
105
     * @param int $plancher
106
     * @param int $plafond
107
     * @return string
108
     */
109
    public function foncer($colorHexa, $plancher = 0, $plafond = 255)
110
    {
111
        $tMin = array('', $plancher, $plancher, $plancher);
0 ignored issues
show
Unused Code introduced by
$tMin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
112
        $tMax = array('', $plafond, $plafond, $plafond);
113
114
        $t10 = static::hexa2rgbA($colorHexa);
115
        $max = 255;
116
117 View Code Duplication
        for ($h = 1; $h <= 3; ++$h) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
118
            if ($max > $t10[$h]) {
119
                $max = $t10[$h];
120
            }
121
        }
122
123
        $increment = -$max;
124
125
        //     $t10[1] = $t10[1] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
        //     $t10[2] = $t10[2] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
127
        //     $t10[3] = $t10[3] + $increment;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
128
129
        $min = 0;
130 View Code Duplication
        for ($h = 1; $h <= 3; ++$h) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
131
            $t10[$h] += $increment;
132
            if ($t10[$h] > $tMax[$h] && $min < ($t10[$h] - $tMax[$h])) {
133
                $min = ($t10[$h] - $tMax[$h]);
134
            }
135
        }
136
137
        $t10[1] = static::bornerValeur($t10[1] - $min, $plancher, $plafond);
138
        $t10[2] = static::bornerValeur($t10[2] - $min, $plancher, $plafond);
139
        $t10[2] = static::bornerValeur($t10[3] - $min, $plancher, $plafond);
140
141
        $colorHexa = static::getHexaColorFromA($t10);
142
143
        return $colorHexa;
144
    }
145
146
    /**************************************************************
147
     * Renvoi une couleur RGB en hexa a partir du tableau passe en parametr
148
     * Description du tableau
149
     * 0 = doit contenir '#' ou ''
150
     * 1 = int red
151
     * 2 = int vert
152
     * 3 = int bleu
153
     **************************************************************
154
     * @param $aColors
155
     * @return string
156
     */
157
    public static function getHexaColorFromA($aColors)
158
    {
159
        $tHex = array('', '', '', '');
160
161
        $tHex[0] = $aColors[0];
162
        $tHex[1] = substr('00'.dechex($aColors[1]), -2);
163
        $tHex[2] = substr('00'.dechex($aColors[2]), -2);
164
        $tHex[3] = substr('00'.dechex($aColors[3]), -2);
165
166
        $colorHexa = implode('', $tHex);
167
168
        return $colorHexa;
169
    }
170
171
    /**************************************************************
172
     * Transforme les composante d'une couleur en valeu hexa
173
     * prefixe doit contenir '#'  ou ''
174
     **************************************************************
175
     * @param        $r
176
     * @param        $g
177
     * @param        $b
178
     * @param string $prefixe
179
     * @return string
180
     */
181
    public function rgb2hexa($r, $g, $b, $prefixe = '')
182
    {
183
        $colorHexa = static::getHexaColorFromA(array($prefixe, $r, $g, $b));
184
185
        return $colorHexa;
186
    }
187
188
    /**************************************************************
189
     * renvoi un tableau d'entier des valeur rgbd d'une couleur a partir d'un hexa
190
     * Description du tableau renvoyé
191
     * 0 = contient '#' ou ''  (selon premier cactere de la couleur hexa)
192
     * 1 = int red
193
     * 2 = int vert
194
     * 3 = int bleu
195
     **************************************************************
196
     * @param $colorHexa
197
     * @return array
198
     */
199
    public static function hexa2rgbA($colorHexa)
200
    {
201
        $t = array('', '', '', '');
202
203
        if (0 === strpos($colorHexa, '#')) {
204
            $t[0] = '#';
205
            $offsetCar = 1;
206
        } else {
207
            $t[0] = '';
208
            $offsetCar = 0;
209
        }
210
211
        $t[1] = hexdec(substr($colorHexa, $offsetCar + 0, 2));
212
        $t[2] = hexdec(substr($colorHexa, $offsetCar + 2, 2));
213
        $t[3] = hexdec(substr($colorHexa, $offsetCar + 4, 2));
214
215
        return $t;
216
    }
217
218
    /**************************************************************
219
     * Renvoi les composante rgb d'une couleur par référence
220
     **************************************************************
221
     * @param $colorHexa
222
     * @param $r
223
     * @param $v
224
     * @param $b
225
     * @param $diese
226
     * @return bool
227
     */
228
    public function hexa2rgb($colorHexa, &$r, &$v, &$b, &$diese)
0 ignored issues
show
Unused Code introduced by
The parameter $b is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
229
    {
230
        $t = static::hexa2rgbA($colorHexa);
231
        $r = $t[1];
232
        $v = $t[2];
233
        $v = $t[3];
234
        $diese = $t[0];
235
236
        return true;
237
    }
238
239
    /**************************************************************
240
     * Borne les valeurs max et min d'une valeur
241
     **************************************************************
242
     * @param $val
243
     * @param $min
244
     * @param $max
245
     * @return mixed
246
     */
247
    public static function bornerValeur($val, $min, $max)
248
    {
249
        if ($val < $min) {
250
            $val = $min;
251
        } elseif ($val > $max) {
252
            $val = $max;
253
        }
254
255
        return $val;
256
    }
257
258
    //--------------------------------------------------------
259
} // --- fin de la classe colors
260
//--------------------------------------------------------
261