Completed
Push — development ( 557e78...5d0b39 )
by
unknown
02:50
created

Color   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hex_to_rgba() 0 17 2
1
<?php
2
3
namespace Carbon_Fields\Helper;
4
5
/**
6
 * Color functions
7
 */
8
class Color {
9
	/**
10
	 * Converts a hexadecimal color into it's RGBA components
11
	 * Accepts hex with and without alpha: #112233, #112233FF
12
	 * Accepts hex with and without a leading # sign
13
	 *
14
	 * @param  string $hex
15
	 * @return array
16
	 */
17 4
	public static function hex_to_rgba( $hex ) {
18 4
		$hex = str_replace( '#', '', $hex );
19 4
		$hex = strlen( $hex ) > 6 ? $hex : $hex . 'FF';
20
21 4
		$int = hexdec( $hex );
22 4
		$r = ($int >> 24) & 255;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
23 4
		$g = ($int >> 16) & 255;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $g. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
24 4
		$b = ($int >> 8) & 255;
25 4
		$a = floatval($int & 255) / 255;
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
26
27
		return array(
28 4
			'red' => $r,
29 4
			'green' => $g,
30 4
			'blue' => $b,
31 4
			'alpha' => $a,
32 4
		);
33
	}
34
}
35