AnnotationPresenter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A injectAnnotationFormFactory() 0 4 1
A renderEdit() 0 13 1
B createComponentAnnotationForm() 0 25 2
A getAnnotationService() 0 4 1
A setAnnotationService() 0 6 1
A getMeetingModel() 0 4 1
A setMeetingModel() 0 6 1
1
<?php
2
3
namespace App\Presenters;
4
5
use App\Components\Forms\AnnotationForm;
6
use App\Components\Forms\Factories\IAnnotationFormFactory;
7
use App\Models\MeetingModel;
8
use App\Services\AnnotationService;
9
use \Exception;
10
11
class AnnotationPresenter extends BasePresenter
12
{
13
14
	/**
15
	 * @var IAnnotationFormFactory
16
	 */
17
	private $annotationFormFactory;
18
19
	/**
20
	 * @var AnnotationService
21
	 */
22
	private $annotationService;
23
24
	/**
25
	 * @var MeetingModel
26
	 */
27
	private $meetingModel;
28
29
	/**
30
	 * @param AnnotationService $service
31
	 * @param MeetingModel $model
32
	 */
33
	public function __construct(AnnotationService $service, MeetingModel $model)
34
	{
35
		$this->setAnnotationService($service);
36
		$this->setMeetingModel($model);
37
	}
38
39
	/**
40
	 * @param  IAnnotationFormFactory $factory
41
	 */
42
	public function injectAnnotationFormFactory(IAnnotationFormFactory $factory)
43
	{
44
		$this->annotationFormFactory = $factory;
45
	}
46
47
	/**
48
	 * @param  string $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
49
	 * @param  string $type
50
	 */
51
	public function renderEdit(string $guid, string $type)
52
	{
53
		$template = $this->getTemplate();
54
55
		$annotation = $this->getAnnotationService()->findByType($guid, $type);
56
57
		$template->guid = $guid;
0 ignored issues
show
Bug introduced by
Accessing guid 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...
58
		$template->annotation = $annotation;
0 ignored issues
show
Bug introduced by
Accessing annotation 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...
59
		$template->meeting = $this->getMeetingModel()->find($this->getMeetingId());
0 ignored issues
show
Bug introduced by
Accessing meeting 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...
60
		$template->program = $this->getAnnotationService()->findParentProgram($annotation);
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...
Documentation introduced by
$annotation is of type object<Nette\Database\Table\IRow>|false, but the function expects a object<Nette\Database\Table\ActiveRow>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
62
		$this['annotationForm']->setDefaults($annotation->toArray());
63
	}
64
65
	/**
66
	 * @return AnnotationFormControl
67
	 */
68
	protected function createComponentAnnotationForm(): AnnotationForm
69
	{
70
		$control = $this->annotationFormFactory->create();
71
		$control->setMeetingId($this->getMeetingId());
72
		$type = $this->getParameter('type');
73
		$control->onAnnotationSave[] = function(AnnotationForm $control, $annotation) use ($type) {
74
			try {
75
				$result = $this->getAnnotationService()->updateByType($type, $annotation);
76
77
				$this->logInfo('Modification of annotation id %s with data %s successfull, result: %s',	[
78
					$annotation->guid,
79
					json_encode($annotation),
80
					json_encode($result),
81
				]);
82
83
				$this->flashSuccess('Položka byla úspěšně upravena');
84
			} catch(Exception $e) {
85
				$this->logError("Modification of annotation id {$annotation->guid} failed, result: {$e->getMessage()}");
86
87
				$this->flashError("Modification of annotation id {$annotation->guid} failed, result: {$e->getMessage()}");
88
			}
89
		};
90
91
		return $control;
92
	}
93
94
	/**
95
	 * @return AnnotationService
96
	 */
97
	public function getAnnotationService(): AnnotationService
98
	{
99
		return $this->annotationService;
100
	}
101
102
	/**
103
	 * @param AnnotationService $annotationService
104
	 *
105
	 * @return self
106
	 */
107
	public function setAnnotationService(AnnotationService $annotationService): self
108
	{
109
		$this->annotationService = $annotationService;
110
111
		return $this;
112
	}
113
114
	/**
115
	 * @return MeetingModel
116
	 */
117
	public function getMeetingModel(): MeetingModel
118
	{
119
		return $this->meetingModel;
120
	}
121
122
	/**
123
	 * @param MeetingModel $meetingModel
124
	 *
125
	 * @return self
126
	 */
127
	public function setMeetingModel(MeetingModel $meetingModel): self
128
	{
129
		$this->meetingModel = $meetingModel;
130
131
		return $this;
132
	}
133
134
}
135