Completed
Push — master ( fea2cb...118c60 )
by Litera
21s
created

ABlocksByDayControl   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 10 1
A createComponentPrograms() 0 4 1
A setProgramsControl() 0 6 1
A getBlockModel() 0 4 1
A setBlockModel() 0 6 1
1
<?php
2
3
namespace App\Components;
4
5
use App\Models\BlockModel;
6
7
abstract class ABlocksByDayControl extends BaseControl implements IBlocksByDayControl
8
{
9
10
	const TEMPLATE_NAME = '';
11
12
	/**
13
	 * @var ProgramsControl
14
	 */
15
	private $programsControl;
16
17
	/**
18
	 * @var BlockModel
19
	 */
20
	private $blockModel;
21
22
	/**
23
	 * @param  string $day
24
	 * @return void
25
	 */
26
	public function render($day)
27
	{
28
		$this->getBlockModel()->setMeetingId($this->getMeetingId());
29
		$blocks = $this->getBlockModel()->findByDay($day);
30
31
		$template = $this->getTemplate();
32
		$template->setFile($this->buildTemplatePath());
33
		$template->blocks = $blocks;
0 ignored issues
show
Bug introduced by
Accessing blocks 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->render();
35
	}
36
37
	/**
38
	 * @return ProgramsControl
39
	 */
40
	protected function createComponentPrograms()
41
	{
42
		return $this->programsControl;
43
	}
44
45
	/**
46
	 * @param  IProgramsControl $control
47
	 * @return $this
48
	 */
49
	protected function setProgramsControl(IProgramsControl $control): IBlocksByDayControl
50
	{
51
		$this->programsControl = $control;
0 ignored issues
show
Documentation Bug introduced by
$control is of type object<App\Components\IProgramsControl>, but the property $programsControl was declared to be of type object<App\Components\ProgramsControl>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
52
53
		return $this;
54
	}
55
56
	/**
57
	 * @return BlockModel
58
	 */
59
	protected function getBlockModel(): BlockModel
60
	{
61
		return  $this->blockModel;
62
	}
63
64
	/**
65
	 * @param  BlockModel $model
66
	 * @return $this
67
	 */
68
	protected function setBlockModel(BlockModel $model): IBlocksByDayControl
69
	{
70
		$this->blockModel = $model;
71
72
		return $this;
73
	}
74
75
}
76