Completed
Pull Request — devel (#146)
by Litera
24:35 queued 19:02
created

NavbarRightControl::setUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Components;
4
5
use Nette\Security\User;
6
7
class NavbarRightControl extends BaseControl
8
{
9
10
	const TEMPLATE_NAME = 'NavbarRight';
11
12
	/**
13
	 * @var User
14
	 */
15
	private $user;
16
17
	/**
18
	 * @param User $user
19
	 */
20
	public function __construct(User $user)
21
	{
22
		$this->setUser($user);
23
	}
24
25
	/**
26
	 * @return void
27
	 */
28
	public function render($backlink)
29
	{
30
		$template = $this->getTemplate();
31
		$template->setFile(__DIR__ . './templates/'.self::TEMPLATE_NAME.'.'.self::TEMPLATE_EXT);
32
		$template->user = $this->getUser();
0 ignored issues
show
Bug introduced by
Accessing user on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
33
		$template->page = $this->getPresenter()->getName();
0 ignored issues
show
Bug introduced by
Accessing page on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
34
		$template->backlink = $backlink;
0 ignored issues
show
Bug introduced by
Accessing backlink on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
35
		$template->render();
36
	}
37
38
	/**
39
	 * @return User
40
	 */
41
	protected function getUser(): User
42
	{
43
		return $this->user;
44
	}
45
46
	/**
47
	 * @param  User $user
48
	 * @return $this
49
	 */
50
	protected function setUser(User $user): self
51
	{
52
		$this->user = $user;
53
54
		return $this;
55
	}
56
57
}
58