Completed
Push — master ( 118c60...254398 )
by Litera
03:47
created

RegistrationForm::buildProgramSwitcher()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 3
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Components\Forms;
4
5
use App\Models\ProvinceModel;
6
use App\Repositories\ProgramRepository;
7
use App\Models\BlockModel;
8
use App\Models\MeetingModel;
9
use Nette\Application\UI\Form;
10
use App\Services\SkautIS\UserService;
11
12
class RegistrationForm extends VisitorForm
13
{
14
15
	const TEMPLATE_NAME = 'RegistrationForm';
16
17
	/**
18
	 * @var Closure
19
	 */
20
	public $onRegistrationSave;
21
22
	/**
23
	 * @var UserService
24
	 */
25
	protected $userService;
26
27
	/**
28
	 * @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...
29
	 */
30 View Code Duplication
	public function __construct(
0 ignored issues
show
Duplication introduced by
This method 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...
31
		ProvinceModel $province,
32
		ProgramRepository $program,
33
		BlockModel $block,
34
		MeetingModel $meeting,
35
		UserService $user
36
	) {
37
		$this->setProvinceModel($province);
38
		$this->setProgramRepository($program);
39
		$this->setBlockModel($block);
40
		$this->setMeetingModel($meeting);
41
		$this->setUserService($user);
42
	}
43
44
	/**
45
	 * @param  array $defaults
46
	 * @return self
47
	 */
48
	public function setDefaults($defaults): BaseForm
49
	{
50
		$this['registrationForm']->setDefaults($defaults);
51
52
		return $this;
53
	}
54
55
	/**
56
	 * @return Form
57
	 */
58
	public function createComponentRegistrationForm(): Form
59
	{
60
		$provinces = $this->getProvinceModel()->all();
61
62
		$form = new Form;
63
64
		$form->addText('name', 'Jméno:')
65
			->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...
66
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
67
			->getLabelPrototype()->setAttribute('class', 'required');
68
		$form->addText('surname', 'Příjmení:')
69
			->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...
70
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
71
			->getLabelPrototype()->setAttribute('class', 'required');
72
		$form->addText('nick', 'Přezdívka:')
73
			->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...
74
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
75
			->getLabelPrototype()->setAttribute('class', 'required');
76
		$form->addEmail('email', 'E-mail:')
77
			->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...
78
			->getLabelPrototype()->setAttribute('class', 'required');
79
		$form->addTbDatePicker('birthday', 'Datum narození:', null, 16)
80
			->setRequired(static::MESSAGE_REQUIRED)
81
			->setFormat('d. m. Y')
82
			->setAttribute('placeholder', 'dd. mm. rrrr')
83
			->getLabelPrototype()->setAttribute('class', 'required');
84
		$form->addText('street', 'Ulice:')
85
			->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...
86
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
87
			->getLabelPrototype()->setAttribute('class', 'required');
88
		$form->addText('city', 'Město:')
89
			->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...
90
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64)
91
			->getLabelPrototype()->setAttribute('class', 'required');
92
		$form->addText('postal_code', 'PSČ:')
93
			->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...
94
			->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}')
95
			->setAttribute('placeholder', '12345')
0 ignored issues
show
Documentation introduced by
'12345' 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...
96
			->getLabelPrototype()->setAttribute('class', 'required');
97
		$form->addText('group_num', 'Číslo středika/přístavu:')
98
			->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...
99
			->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnn.nn!', '[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}')
100
			->setAttribute('placeholder', '214.02')
0 ignored issues
show
Documentation introduced by
'214.02' 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...
101
			->getLabelPrototype()->setAttribute('class', 'required');
102
		$form->addText('group_name', 'Název střediska/přístavu:')
103
			->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...
104
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50)
105
			->setAttribute('placeholder', '2. přístav Poutníci Kolín')
0 ignored issues
show
Documentation introduced by
'2. přístav Poutníci Kolín' 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...
106
			->getLabelPrototype()->setAttribute('class', 'required');
107
		$form->addText('troop_name', 'Název oddílu:')
108
			->setAttribute('placeholder', '22. oddíl Galeje')
0 ignored issues
show
Documentation introduced by
'22. oddíl Galeje' 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...
109
			->addCondition(Form::FILLED, true)
110
				->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50);
111
112
		$form->addSelect('province', 'Kraj:', $provinces)
113
			->setPrompt('zvolte kraj');
114
115
		$form = $this->buildMealSwitcher($form);
116
117
		$form->addTextArea('arrival', 'Informace o příjezdu:')
118
			->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) přijedete na místo srazu.');
0 ignored issues
show
Documentation introduced by
'Napište, prosím, stru...edete na místo srazu.' 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...
119
		$form->addTextArea('departure', 'Informace o odjezdu:')
120
			->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) sraz opustíte.');
0 ignored issues
show
Documentation introduced by
'Napište, prosím, stru...žně) sraz opustíte.' 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...
121
		$form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:');
122
		$form->addTextArea('question', 'Vaše nabídka:')
123
			->setAttribute('placeholder', 'Vaše nabídka na sdílení dobré praxe (co u vás umíte dobře a jste ochotni se o to podělit)');
0 ignored issues
show
Documentation introduced by
'Vaše nabídka na sdíl...otni se o to podělit)' 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...
124
		$form->addTextArea('question2', 'Počet a typy lodí:')
125
			->setAttribute('placeholder', 'Počet a typy lodí, které sebou přivezete (vyplňte pokud ano)');
0 ignored issues
show
Documentation introduced by
'Počet a typy lodí, kt...e (vyplňte pokud ano)' 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...
126
127
		$form = $this->buildProgramSwitcher($form);
128
129
		$form->addHidden('mid', $this->getMeetingId());
130
		$form->addHidden('bill', 0);
131
		$form->addHidden('cost', $this->getMeetingModel()->getPrice('cost'));
132
133
		$form->addSubmit('save', 'Uložit')
134
			->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...
135
		$form->addSubmit('reset', 'storno')
136
			->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...
137
138
		$form = $this->setupRendering($form);
139
140
		$form->onSuccess[] = [$this, 'processForm'];
141
142
		return $form;
143
	}
144
145
	/**
146
	 * @param  Form $form
147
	 * @return void
148
	 */
149
	public function processForm(Form $form)
150
	{
151
		$registration = $form->getValues();
152
		$registration['meeting'] = $this->getMeetingId();
153
154
		$this->onRegistrationSave($this, $registration);
0 ignored issues
show
Documentation Bug introduced by
The method onRegistrationSave does not exist on object<App\Components\Forms\RegistrationForm>? 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...
155
	}
156
157
	/**
158
	 * @return UserService
159
	 */
160
	protected function getUserService()
161
	{
162
		return $this->userService;
163
	}
164
165
	/**
166
	 * @param  UserService $service
167
	 * @return $this
168
	 */
169
	protected function setUserService(UserService $service)
170
	{
171
		$this->userService = $service;
172
173
		return $this;
174
	}
175
176
}
177