Passed
Push — develop ( 3d135a...646156 )
by Paul
02:56
created

Helper::getCurrentScreen()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\Pollux;
4
5
use GeminiLabs\Pollux\Application;
6
7
class Helper
8
{
9
	/**
10
	 * @param string $name
11
	 * @param string $path
12
	 * @return string
13
	 */
14
	public function buildClassName( $name, $path = '' )
15
	{
16
		$className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name )));
17
		$className = implode( '', $className );
18
		return !empty( $path )
19
			? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className ))
20
			: $className;
21
	}
22
23
	/**
24
	 * @param string $name
25
	 * @param string $prefix
26
	 * @return string
27
	 */
28
	public function buildMethodName( $name, $prefix = 'get' )
29
	{
30
		return lcfirst( $this->buildClassName( $prefix . '-' . $name ));
31
	}
32
33
	/**
34
	 * @param bool $toLowerCase
35
	 * @return string
36
	 */
37
	public function getClassname( $toLowerCase = true )
38
	{
39
		$paths = explode( '\\', get_class( $this ));
40
		return wp_validate_boolean( $toLowerCase )
41
			? strtolower( end( $paths ))
42
			: end( $paths );
43
	}
44
45
	/**
46
	 * get_current_screen() is unreliable because it is defined on most admin pages, but not all.
47
	 * @return WP_Screen|null
48
	 */
49
	public function getCurrentScreen()
50
	{
51
		global $current_screen;
52
		return isset( $current_screen ) ? $current_screen : (object) [
53
			'base' => '',
54
			'id' => '',
55
		];
56
	}
57
58
	/**
59
	 * @param mixed $value
60
	 * @return array
61
	 */
62
	public function toArray( $value )
63
	{
64
		return array_filter( (array) $value );
65
	}
66
}
67