Access   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 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 for contents and modules
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 Henry Ruhs
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