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

CategoryStylesControl::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Components;
4
5
use App\Services\CategoryService;
6
7 View Code Duplication
class CategoryStylesControl 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 = 'CategoryStyles';
11
12
	/**
13
	 * @var CategoryService
14
	 */
15
	private $categoryService;
16
17
	/**
18
	 * @param CategoryService $service
19
	 */
20
	public function __construct(CategoryService $service)
21
	{
22
		$this->setCategoryService($service);
23
	}
24
25
	public function render()
26
	{
27
		$template = $this->getTemplate();
28
		$template->setFile($this->buildTemplatePath());
29
		$template->categories = $this->getCategoryService()->all();
0 ignored issues
show
Bug introduced by
Accessing categories 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...
30
		$template->render();
31
	}
32
33
	/**
34
	 * @return CategoryService
35
	 */
36
	protected function getCategoryService()
37
	{
38
		return $this->categoryService;
39
	}
40
41
	/**
42
	 * @param  CategoryService $service
43
	 * @return self
44
	 */
45
	protected function setCategoryService(CategoryService $service): self
46
	{
47
		$this->categoryService = $service;
48
49
		return $this;
50
	}
51
52
}
53