UserCallable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 8 2
1
<?php
2
/**
3
 * UserCallable.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:DoctrineBlameable!
9
 * @subpackage     Security
10
 * @since          1.0.0
11
 *
12
 * @date           05.01.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\DoctrineBlameable\Security;
18
19
use Nette\Security as NS;
20
21
/**
22
 * Doctrine blameable default user callable
23
 *
24
 * @package        iPublikuj:DoctrineBlameable!
25
 * @subpackage     Security
26
 *
27
 * @author         Adam Kadlec <[email protected]>
28
 */
29
final class UserCallable
30
{
31
	/**
32
	 * @var NS\User
33
	 */
34
	private $user;
35
36
	/**
37
	 * @param NS\User $user
38
	 */
39
	public function __construct(NS\User $user)
40
	{
41
		$this->user = $user;
42
	}
43
44
	/**
45
	 * @return mixed
46
	 */
47
	public function __invoke()
48
	{
49
		if ($this->user->isLoggedIn()) {
50
			return $this->user->getId();
51
		}
52
53
		return NULL;
54
	}
55
}
56