Test Failed
Pull Request — master (#125)
by Litera
08:49
created

AnnotationForm::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Components\Forms;
4
5
use App\Services\AnnotationService;
6
use App\Models\MeetingModel;
7
use Nette\Application\UI\Form;
8
9
class AnnotationForm extends BaseForm
10
{
11
12
	const TEMPLATE_NAME = 'AnnotationForm';
13
14
	const MESSAGE_REQUIRED = 'Hodnota musí být vyplněna!';
15
	const MESSAGE_MAX_LENGTH = '%label nesmí mít více jak %d znaků!';
16
17
	/**
18
	 * @var Closure
19
	 */
20
	public $onAnnotationSave;
21
22
	/**
23
	 * @var AnnotationService
24
	 */
25
	protected $annotationService;
26
27
	/**
28
	 * @var  MeetingModel
29
	 */
30
	protected $meetingModel;
31
32
	/**
33
	 * @param ProvinceModel $model
0 ignored issues
show
Bug introduced by
There is no parameter named $model. 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...
34
	 */
35
	public function __construct(
36
		AnnotationService $annotation,
37
		MeetingModel $meeting
38
	) {
39
		$this->setAnnotationService($annotation);
40
		$this->setMeetingModel($meeting);
41
	}
42
43
	/**
44
	 * @return void
45
	 */
46
	public function render()
47
	{
48
		$template = $this->getTemplate();
49
		$template->setFile($this->buildTemplatePath());
50
		$template->render();
51
	}
52
53
	/**
54
	 * @param  array $defaults
55
	 * @return AnnotationForm
56
	 */
57
	public function setDefaults(array $defaults = []): AnnotationForm
58
	{
59
		$this['annotationForm']->setDefaults($defaults);
60
61
		return $this;
62
	}
63
64
	/**
65
	 * @return Form
66
	 */
67
	public function createComponentAnnotationForm(): Form
68
	{
69
		$form = new Form;
70
71
		$form->addText('name', 'Název:')
72
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

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...
73
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
74
			->getLabelPrototype()->setAttribute('class', 'required');
75
		$form->addTextArea('description', 'Popis:')
76
			->setAttribute('placeholder', 'Doplň, prosím, popis Tvého programu (bude se zobrazovat účastníkům na webu při výběru programu).');
0 ignored issues
show
Documentation introduced by
'Doplň, prosím, popis ... is of type string, but the function expects a boolean.

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...
77
		$form->addTextArea('material', 'Materiál:')
78
			->setAttribute('placeholder', 'Doplň, prosím, vybavení, které budeš potřebovat na Tvůj program a které máme zajistit.');
0 ignored issues
show
Documentation introduced by
'Doplň, prosím, vybave...které máme zajistit.' is of type string, but the function expects a boolean.

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...
79
		$form->addText('tutor', 'Lektor:');
80
		$form->addEmail('email', 'E-mail:');
81
		$form->addText('capacity', 'Kapacita:');
82
83
		$form->addHidden('guid');
84
85
		$form->addSubmit('save', 'Uložit')
86
			->setAttribute('class', 'btn-primary');
0 ignored issues
show
Documentation introduced by
'btn-primary' is of type string, but the function expects a boolean.

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...
87
		$form->addSubmit('reset', 'storno')
88
			->setAttribute('class', 'btn-reset');
0 ignored issues
show
Documentation introduced by
'btn-reset' is of type string, but the function expects a boolean.

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...
89
90
		$form = $this->setupRendering($form);
91
92
		$form->onSuccess[] = [$this, 'processForm'];
93
94
		return $form;
95
	}
96
97
	/**
98
	 * @param  Form $form
99
	 * @return void
100
	 */
101
	public function processForm(Form $form)
102
	{
103
		$annotation = $form->getValues();
104
105
		$this->onAnnotationSave($this, $annotation);
0 ignored issues
show
Documentation Bug introduced by
The method onAnnotationSave does not exist on object<App\Components\Forms\AnnotationForm>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
106
	}
107
108
	/**
109
	 * @return MeetingModel
110
	 */
111
	protected function getMeetingModel(): MeetingModel
112
	{
113
		return $this->meetingModel;
114
	}
115
116
	/**
117
	 * @param  MeetingModel $model
118
	 * @return self
119
	 */
120
	protected function setMeetingModel(MeetingModel $model): self
121
	{
122
		$this->meetingModel = $model;
123
124
		return $this;
125
	}
126
127
	/**
128
	 * @return AnnotationService
129
	 */
130
	public function getAnnotationService(): AnnotationService
131
	{
132
		return $this->annotationService;
133
	}
134
135
	/**
136
	 * @param AnnotationService $annotationService
137
	 *
138
	 * @return self
139
	 */
140
	public function setAnnotationService(AnnotationService $annotationService): self
141
	{
142
		$this->annotationService = $annotationService;
143
144
		return $this;
145
	}
146
147
}
148