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

PublicProgramDetailControl   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A render() 8 8 1
A getProgramModel() 4 4 1
A setProgramModel() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Components;
4
5
use App\Models\ProgramModel;
6
7 View Code Duplication
class PublicProgramDetailControl extends BaseControl
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
10
	const TEMPLATE_NAME = 'PublicProgramDetail';
11
12
	/**
13
	 * @var ProgramModel
14
	 */
15
	private $programModel;
16
17
	/**
18
	 * @param ProgramModel $model
19
	 */
20
	public function __construct(ProgramModel $model)
21
	{
22
		$this->setProgramModel($model);
23
	}
24
25
	/**
26
	 * @return void
27
	 */
28
	public function render($programId)
29
	{
30
		$template = $this->getTemplate();
31
		$template->setFile($this->buildTemplatePath());
32
		$template->visitorsOnProgram = $this->getProgramModel()->countProgramVisitors($programId);
0 ignored issues
show
Bug introduced by
Accessing visitorsOnProgram 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->program = $this->getProgramModel()->find($programId);
0 ignored issues
show
Bug introduced by
Accessing program 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 ProgramModel
39
	 */
40
	public function getProgramModel(): ProgramModel
41
	{
42
		return $this->programModel;
43
	}
44
45
	/**
46
	 * @param ProgramModel $programModel
47
	 * @return self
48
	 */
49
	public function setProgramModel(ProgramModel $programModel): self
50
	{
51
		$this->programModel = $programModel;
52
53
		return $this;
54
	}
55
56
}
57