MealControl::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 4
loc 4
rs 10
1
<?php
2
3
namespace App\Components;
4
5
use App\Models\ExportModel;
6
7 View Code Duplication
class MealControl 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 = 'Meal';
11
12
	/**
13
	 * @var ExportModel
14
	 */
15
	private $exportModel;
16
17
	/**
18
	 * @param ExportModel $model
19
	 */
20
	public function __construct(ExportModel $model)
21
	{
22
		$this->setExportModel($model);
23
	}
24
25
	/**
26
	 * @param  string $mealColumn
27
	 * @param  string $mealName
28
	 * @return void
29
	 */
30
	public function render($mealColumn, $mealName)
31
	{
32
		$template = $this->getTemplate();
33
		$template->setFile($this->buildTemplatePath());
34
		$template->mealCount = $this->getExportModel()->getMealCount($mealColumn);
0 ignored issues
show
Bug introduced by
Accessing mealCount 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->mealName = $mealName;
0 ignored issues
show
Bug introduced by
Accessing mealName 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...
36
		$template->render();
37
	}
38
39
	/**
40
	 * @return ExportModel
41
	 */
42
	protected function getExportModel()
43
	{
44
		return $this->exportModel->setMeetingId($this->getMeetingId());
45
	}
46
47
	/**
48
	 * @param  ExportModel $model
49
	 * @return $this
50
	 */
51
	protected function setExportModel(ExportModel $model)
52
	{
53
		$this->exportModel = $model;
54
55
		return $this;
56
	}
57
58
}
59