Access::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 3
nc 3
nop 2
crap 3
1
<?php
2
namespace Redaxscript\Validator;
3
4
use function array_intersect;
5
use function in_array;
6
use function json_decode;
7
8
/**
9
 * children class to validate access again group
10
 *
11
 * @since 2.2.0
12
 *
13
 * @package Redaxscript
14
 * @category Validator
15
 * @author Henry Ruhs
16
 * @author Sven Weingartner
17
 */
18
19
class Access implements ValidatorInterface
20
{
21
	/**
22
	 * validate the access
23
	 *
24
	 * @since 4.0.0
25
	 *
26
	 * @param string $access access to be validated
27
	 * @param string $groups groups of the user
28
	 *
29
	 * @return bool
30
	 */
31
32 4
	public function validate(string $access = null, string $groups = null) : bool
33
	{
34 4
		$accessArray = (array)json_decode($access);
35 4
		$groupArray = (array)json_decode($groups);
36 4
		return !$access || in_array(1, $groupArray) || array_intersect($accessArray, $groupArray);
0 ignored issues
show
Bug Best Practice introduced by
The expression $access of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
	}
38
}
39