Failed Conditions
Branch refactor/kernels (50d60a)
by Atanas
01:41
created

AdminCondition::isAdminPage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 1
nc 3
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Routing\Conditions;
11
12
use WPEmerge\Requests\RequestInterface;
13
14
/**
15
 * Check against the current ajax action.
16
 */
17
class AdminCondition implements ConditionInterface {
18
	/**
19
	 * Menu slug.
20
	 *
21
	 * @var string
22
	 */
23
	protected $menu = '';
24
25
	/**
26
	 * Parent menu slug.
27
	 *
28
	 * @var string
29
	 */
30
	protected $parent_menu = '';
31
32
	/**
33
	 * Constructor
34
	 *
35
	 * @codeCoverageIgnore
36
	 * @param string $menu
37
	 * @param string $parent_menu
38
	 */
39
	public function __construct( $menu, $parent_menu = '' ) {
40
		$this->menu = $menu;
41
		$this->parent_menu = $parent_menu;
42
	}
43
44
	/**
45
	 * Check if the admin page requirement matches.
46
	 *
47
	 * @return boolean
48
	 */
49
	protected function isAdminPage() {
50
		return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX );
51
	}
52
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	public function isSatisfied( RequestInterface $request ) {
57
		if ( ! $this->isAdminPage() ) {
58
			return false;
59
		}
60
61
		$screen = get_current_screen();
1 ignored issue
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
62
63
		if ( ! $screen ) {
1 ignored issue
show
introduced by
$screen is of type null, thus it always evaluated to false.
Loading history...
64
			return false;
65
		}
66
67
		return $screen->id === get_plugin_page_hookname( $this->menu, $this->parent_menu );
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public function getArguments( RequestInterface $request ) {
74
		return ['hook' => get_plugin_page_hookname( $this->menu, $this->parent_menu )];
75
	}
76
}
77