Completed
Push — master ( 425846...6cb170 )
by Adam
07:36
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
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        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Permissions!
9
 * @subpackage     common
10
 * @since          2.0.0
11
 *
12
 * @date           17.02.15
13
 */
14
15
namespace IPub\Permissions;
16
17
use Nette;
18
use Nette\Application;
19
20
/**
21
 * Permissions's extension configuration storage. Store basic extension settings
22
 *
23
 * @package        iPublikuj:Permissions!
24
 * @subpackage     common
25
 *
26
 * @author         Adam Kadlec <[email protected]>
27
 */
28
class Configuration
29
{
30
	/**
31
	 * Implement nette smart magic
32
	 */
33
	use Nette\SmartObject;
34
35
	/**
36
	 * @var string|NULL
37
	 */
38
	private $redirectUrl;
39
40
	/**
41
	 * @var Application\LinkGenerator
42
	 */
43
	private $linkGenerator;
44
45
	/**
46
	 * @param string|NULL $redirectUrl
47
	 * @param Application\LinkGenerator $linkGenerator
48
	 */
49
	public function __construct(string $redirectUrl = NULL, Application\LinkGenerator $linkGenerator)
50
	{
51
		$this->redirectUrl = $redirectUrl;
52
		$this->linkGenerator = $linkGenerator;
53
	}
54
55
	/**
56
	 * Build the URL for redirection if is set
57
	 *
58
	 * @param array $params
59
	 *
60
	 * @return string|NULL
61
	 *
62
	 * @throws Application\UI\InvalidLinkException
63
	 */
64
	public function getRedirectUrl(array $params = [])
65
	{
66
		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...
67
			return $this->linkGenerator->link($this->redirectUrl, $params);
68
		}
69
70
		return NULL;
71
	}
72
}
73