ConfigureMenuListener::onMenuConfigure()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 39
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 39
rs 8.5806
c 2
b 0
f 1
cc 4
eloc 20
nc 4
nop 1
1
<?php
2
3
namespace Vivait\AuthBundle\EventListener;
4
5
use Symfony\Component\Security\Core\SecurityContext;
6
use Vivait\BootstrapBundle\Event\ConfigureMenuEvent;
7
8
class ConfigureMenuListener {
9
	/**
10
	 * @var SecurityContext
11
	 */
12
	private $security_context;
13
14
	/**
15
	 * @var int
16
	 */
17
	private $license_warning;
18
19
	function __construct(SecurityContext $security_context, $license_warning = 7) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
		$this->security_context = $security_context;
21
		$this->license_warning  = intval($license_warning);
22
	}
23
24
	/**
25
	 * @param ConfigureMenuEvent $event
26
	 */
27
	public function onMenuConfigure(ConfigureMenuEvent $event) {
28
		$menu  = $event->getMenu();
29
		$token = $this->security_context->getToken();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Securi...rityContext::getToken() has been deprecated with message: since version 2.6, to be removed in 3.0. Use TokenStorageInterface::getToken() instead. {@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
30
31
		$root = $menu->addChild('Auth Menu', [
32
			'navbar' => true,
33
		]);
34
35
		if ($token === null) {
36
			return;
37
		}
38
39
		/* @var $user \Vivait\AuthBundle\Entity\User */
40
		$user = $token->getUser();
41
42
		if ($user) {
43
			if ($user->getLicensedUntil() > new \DateTime('+' . $this->license_warning . ' days')) {
44
				$licensing = $root->addChild('Licensing Warning', [
45
					'dropdown' => true,
46
					'icon'     => 'warning-sign',
47
					'label'    => '',
48
					'pull-right' => true
49
				]);
50
51
				$licensing->setAttribute('class', $licensing->getAttribute('class') .' menu-danger');
52
53
				$licensing->addChild('This product will expire soon', [
54
					'dropdown-header' => true
55
				]);
56
				$licensing->addChild('Licensed until '. $user->getLicensedUntil()->format('d M Y H:i'), [
57
					'dropdown-header' => true
58
				]);
59
			}
60
61
//			$menu->addChild('Tenants', array('route' => 'vivait_auth_tenant'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
//			$menu->addChild('Groups', array('route' => 'vivait_auth_group'));
63
//			$menu->addChild('Users', array('route' => 'vivait_auth_user'));
64
		}
65
	}
66
}