Completed
Push — master ( c3b778...fe23d9 )
by Nicholas
03:04
created

generate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 17.07 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 7
loc 41
ccs 14
cts 21
cp 0.6667
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A rgb_contrast() 7 7 4
A rgb_invert() 0 7 1
A yiq_score() 0 3 1
A rand() 0 7 1
A blend() 0 10 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
namespace projectcleverweb\color;
5
6
7
class generate {
8
	
9 1 View Code Duplication
	public static function rgb_contrast(int $r = 0, int $g = 0, int $b = 0) :array {
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...
10
		return [
11 1
			'r' => ($r < 128) ? 255 : 0,
12 1
			'g' => ($g < 128) ? 255 : 0,
13 1
			'b' => ($b < 128) ? 255 : 0
14
		];
15
	}
16
	
17 1
	public static function rgb_invert(int $r = 0, int $g = 0, int $b = 0) :array {
18
		return [
19 1
			'r' => 255 - $r,
20 1
			'g' => 255 - $g,
21 1
			'b' => 255 - $b
22
		];
23
	}
24
	
25 2
	public static function yiq_score(int $r = 0, int $g = 0, int $b = 0) :float {
26 2
		return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
27
	}
28
	
29 1
	public static function rand(int $min_r = 0, int $max_r = 255, int $min_g = 0, int $max_g = 255, int $min_b = 0, int $max_b = 255) :array {
30
		return [
31 1
			'r' => rand(abs((int) $min_r) % 256, abs((int) $max_r) % 256),
32 1
			'g' => rand(abs((int) $min_g) % 256, abs((int) $max_g) % 256),
33 1
			'b' => rand(abs((int) $min_b) % 256, abs((int) $max_b) % 256)
34
		];
35
	}
36
	
37
	public static function blend(float $r1, float $g1, float $b1, float $a1, float $r2, float $g2, float $b2, float $a2, float $amount = 50.0) :array {
38
		$x1 = convert::_div(100 - $amount, 100);
39
		$x2 = convert::_div($amount, 100);
40
		return [
41
			'r' => round(($r1 * $x1) + ($r2 * $x2), 0),
42
			'g' => round(($g1 * $x1) + ($g2 * $x2), 0),
43
			'b' => round(($b1 * $x1) + ($b2 * $x2), 0),
44
			'a' => ($a1 * $x1) + ($a2 * $x2)
45
		];
46
	}
47
}
48