Configuration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 45
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getRedirectUrl() 0 8 2
1
<?php
2
/**
3
 * Configuration.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Permissions!
9
 * @subpackage     common
10
 * @since          2.0.0
11
 *
12
 * @date           17.02.15
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Permissions;
18
19
use Nette;
20
use Nette\Application;
21
22
/**
23
 * Permissions's extension configuration storage. Store basic extension settings
24
 *
25
 * @package        iPublikuj:Permissions!
26
 * @subpackage     common
27
 *
28
 * @author         Adam Kadlec <[email protected]>
29
 */
30 1
class Configuration
31
{
32
	/**
33
	 * Implement nette smart magic
34
	 */
35 1
	use Nette\SmartObject;
36
37
	/**
38
	 * @var string|NULL
39
	 */
40
	private $redirectUrl;
41
42
	/**
43
	 * @var Application\LinkGenerator
44
	 */
45
	private $linkGenerator;
46
47
	/**
48
	 * @param string|NULL $redirectUrl
49
	 * @param Application\LinkGenerator $linkGenerator
50
	 */
51
	public function __construct(?string $redirectUrl = NULL, Application\LinkGenerator $linkGenerator)
52
	{
53 1
		$this->redirectUrl = $redirectUrl;
54 1
		$this->linkGenerator = $linkGenerator;
55 1
	}
56
57
	/**
58
	 * Build the URL for redirection if is set
59
	 *
60
	 * @param array $params
61
	 *
62
	 * @return string|NULL
63
	 *
64
	 * @throws Application\UI\InvalidLinkException
65
	 */
66
	public function getRedirectUrl(array $params = []) : ?string
67
	{
68 1
		if ($this->redirectUrl) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->redirectUrl of type string|null is loosely compared to true; 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...
69
			return $this->linkGenerator->link($this->redirectUrl, $params);
70
		}
71
72 1
		return NULL;
73
	}
74
}
75