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

RegistrationForm   B

Complexity

Total Complexity 33

Size/Duplication

Total Lines 441
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 0
Metric Value
dl 0
loc 441
rs 8.6166
c 0
b 0
f 0
wmc 33
lcom 1
cbo 15

26 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A render() 0 11 1
A setDefaults() 0 6 1
B createComponentRegistrationForm() 0 86 1
A processForm() 0 7 1
B buildProgramSwitcher() 0 25 3
A buildMealSwitcher() 0 14 2
A getProvinceModel() 0 4 1
A setProvinceModel() 0 6 1
A getProgramModel() 0 4 1
A setProgramModel() 0 6 1
A getBlockModel() 0 4 1
A setBlockModel() 0 6 1
A getMeetingModel() 0 4 1
A setMeetingModel() 0 6 1
A getMealFields() 0 4 1
A setMealField() 0 8 2
A getProgramFields() 0 4 1
A setProgramField() 0 6 1
A setProgramFields() 0 11 2
A setMealFields() 0 10 2
A fetchProgramBlocks() 0 4 1
A fetchMeals() 0 4 1
A getUserService() 0 4 1
A setUserService() 0 6 1
A filterFilledCapacity() 0 13 2
1
<?php
2
3
namespace App\Components\Forms;
4
5
use DateTime;
6
use App\Components\BaseControl;
7
use App\Models\ProvinceModel;
8
use App\Models\ProgramModel;
9
use App\Models\BlockModel;
10
use App\Models\MealModel;
11
use App\Models\MeetingModel;
12
use Nette\Application\UI\Form;
13
use App\Services\SkautIS\UserService;
14
15
class RegistrationForm extends BaseForm
16
{
17
18
	const TEMPLATE_NAME = 'RegistrationForm';
19
20
	const MESSAGE_REQUIRED = 'Hodnota musí být vyplněna!';
21
	const MESSAGE_MAX_LENGTH = '%label nesmí mít více jak %d znaků!';
22
23
	/**
24
	 * @var Closure
25
	 */
26
	public $onRegistrationSave;
27
28
	/**
29
	 * @var ProvinceModel
30
	 */
31
	protected $provinceModel;
32
33
	/**
34
	 * @var ProgramModel
35
	 */
36
	protected $programModel;
37
38
	/**
39
	 * @var BlockModel
40
	 */
41
	protected $blockModel;
42
43
	/**
44
	 * @var  MeetingModel
45
	 */
46
	protected $meetingModel;
47
48
	/**
49
	 * @var array
50
	 */
51
	protected $mealFields = [];
52
53
	/**
54
	 * @var array
55
	 */
56
	protected $programFields = [];
57
58
	/**
59
	 * @var UserService
60
	 */
61
	protected $userService;
62
63
	/**
64
	 * @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...
65
	 */
66
	public function __construct(
67
		ProvinceModel $province,
68
		ProgramModel $program,
69
		BlockModel $block,
70
		MeetingModel $meeting,
71
		UserService $user
72
	) {
73
		$this->setProvinceModel($province);
74
		$this->setProgramModel($program);
75
		$this->setBlockModel($block);
76
		$this->setMeetingModel($meeting);
77
		$this->setUserService($user);
78
	}
79
80
	/**
81
	 * @return void
82
	 */
83
	public function render()
84
	{
85
		$this->setMealFields();
86
		$this->setProgramFields();
87
88
		$template = $this->getTemplate();
89
		$template->setFile($this->buildTemplatePath());
90
		$template->meals = $this->getMealFields();
0 ignored issues
show
Bug introduced by
Accessing meals 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...
91
		$template->programs = $this->getProgramFields();
0 ignored issues
show
Bug introduced by
Accessing programs 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...
92
		$template->render();
93
	}
94
95
	/**
96
	 * @param  array $defaults
97
	 * @return RegistrationForm
98
	 */
99
	public function setDefaults(array $defaults = []): RegistrationForm
100
	{
101
		$this['registrationForm']->setDefaults($defaults);
102
103
		return $this;
104
	}
105
106
	/**
107
	 * @return Form
108
	 */
109
	public function createComponentRegistrationForm(): Form
110
	{
111
		$provinces = $this->getProvinceModel()->all();
112
113
		$form = new Form;
114
115
		$form->addText('name', 'Jméno:')
116
			->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...
117
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
118
			->getLabelPrototype()->setAttribute('class', 'required');
119
		$form->addText('surname', 'Příjmení:')
120
			->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...
121
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
122
			->getLabelPrototype()->setAttribute('class', 'required');
123
		$form->addText('nick', 'Přezdívka:')
124
			->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...
125
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
126
			->getLabelPrototype()->setAttribute('class', 'required');
127
		$form->addEmail('email', 'E-mail:')
128
			->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...
129
			->getLabelPrototype()->setAttribute('class', 'required');
130
		$form->addTbDatePicker('birthday', 'Datum narození:', null, 16)
131
			->setRequired(static::MESSAGE_REQUIRED)
132
			->setFormat('d. m. Y')
133
			->setAttribute('placeholder', 'dd. mm. rrrr')
134
			->getLabelPrototype()->setAttribute('class', 'required');
135
		$form->addText('street', 'Ulice:')
136
			->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...
137
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
138
			->getLabelPrototype()->setAttribute('class', 'required');
139
		$form->addText('city', 'Město:')
140
			->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...
141
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64)
142
			->getLabelPrototype()->setAttribute('class', 'required');
143
		$form->addText('postal_code', 'PSČ:')
144
			->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...
145
			->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}')
146
			->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...
147
			->getLabelPrototype()->setAttribute('class', 'required');
148
		$form->addText('group_num', 'Číslo středika/přístavu:')
149
			->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...
150
			->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}')
151
			->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...
152
			->getLabelPrototype()->setAttribute('class', 'required');
153
		$form->addText('group_name', 'Název střediska/přístavu:')
154
			->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...
155
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50)
156
			->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...
157
			->getLabelPrototype()->setAttribute('class', 'required');
158
		$form->addText('troop_name', 'Název oddílu:')
159
			->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...
160
			->addCondition(Form::FILLED, true)
161
				->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50);
162
163
		$form->addSelect('province', 'Kraj:', $provinces)
164
			->setPrompt('zvolte kraj');
165
166
		$form = $this->buildMealSwitcher($form);
167
168
		$form->addTextArea('arrival', 'Informace o příjezdu:')
169
			->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...
170
		$form->addTextArea('departure', 'Informace o odjezdu:')
171
			->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...
172
		$form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:');
173
		$form->addTextArea('question', 'Vaše nabídka:')
174
			->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...
175
		$form->addTextArea('question2', 'Počet a typy lodí:')
176
			->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...
177
178
		$form = $this->buildProgramSwitcher($form);
179
180
		$form->addHidden('mid', $this->getMeetingId());
181
		$form->addHidden('bill', 0);
182
		$form->addHidden('cost', $this->getMeetingModel()->getPrice('cost'));
183
184
		$form->addSubmit('save', 'Uložit')
185
			->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...
186
		$form->addSubmit('reset', 'storno')
187
			->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...
188
189
		$form = $this->setupRendering($form);
190
191
		$form->onSuccess[] = [$this, 'processForm'];
192
193
		return $form;
194
	}
195
196
	/**
197
	 * @param  Form $form
198
	 * @return void
199
	 */
200
	public function processForm(Form $form)
201
	{
202
		$registration = $form->getValues();
203
		$registration['meeting'] = $this->getMeetingId();
204
205
		$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...
206
	}
207
208
	/**
209
	 * @param  Form   $form
210
	 * @return Form
211
	 */
212
	protected function buildProgramSwitcher(Form $form): Form
213
	{
214
		$programBlocks = $this->fetchProgramBlocks();
215
216
		foreach ($programBlocks as $block) {
217
218
			$programsInBlock = $this->getProgramModel()->findByBlockId($block->id);
219
220
			$programs = [
221
				0 => 'Nebudu přítomen'
222
			];
223
224
			foreach ($programsInBlock as $program) {
225
				$programs[$program->id] = $program->name;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Nette\Database\IRow 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...
Bug introduced by
Accessing name on the interface Nette\Database\IRow 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...
226
			}
227
228
			$form->addRadioList(
229
				'blck_' . $block->id, $block->day . ', ' . $block->from .' - ' . $block->to .' : ' . $block->name,
230
				$programs
231
			)->setDefaultValue(0)
232
			->setDisabled($this->filterFilledCapacity($programs));
0 ignored issues
show
Documentation introduced by
$this->filterFilledCapacity($programs) is of type array, 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...
233
		}
234
235
		return $form;
236
	}
237
238
	/**
239
	 * @param  Form   $form
240
	 * @return Form
241
	 */
242
	protected function buildMealSwitcher(Form $form): Form
243
	{
244
		$yesNoArray = [
245
			'ne'  => 'ne',
246
			'ano' => 'ano',
247
		];
248
249
		foreach ($this->fetchMeals() as $name => $label) {
250
			$this->setMealField($name);
251
			$form->addSelect($name, $label . ':', $yesNoArray);
252
		}
253
254
		return $form;
255
	}
256
257
	/**
258
	 * @return ProvinceModel
259
	 */
260
	protected function getProvinceModel(): ProvinceModel
261
	{
262
		return $this->provinceModel;
263
	}
264
265
	/**
266
	 * @param  ProvinceModel $model
267
	 * @return RegistrationFormFactory
268
	 */
269
	protected function setProvinceModel(ProvinceModel $model): RegistrationForm
270
	{
271
		$this->provinceModel = $model;
272
273
		return $this;
274
	}
275
276
	/**
277
	 * @return ProgramModel
278
	 */
279
	protected function getProgramModel(): ProgramModel
280
	{
281
		return $this->programModel;
282
	}
283
284
	/**
285
	 * @param  ProgramModel $model
286
	 * @return RegistrationFormFactory
287
	 */
288
	protected function setProgramModel(ProgramModel $model): RegistrationForm
289
	{
290
		$this->programModel = $model;
291
292
		return $this;
293
	}
294
295
	/**
296
	 * @return BlockModel
297
	 */
298
	protected function getBlockModel(): BlockModel
299
	{
300
		return $this->blockModel;
301
	}
302
303
	/**
304
	 * @param  BlockModel $model
305
	 * @return RegistrationForm
306
	 */
307
	protected function setBlockModel(BlockModel $model): RegistrationForm
308
	{
309
		$this->blockModel = $model;
310
311
		return $this;
312
	}
313
314
	/**
315
	 * @return MeetingModel
316
	 */
317
	protected function getMeetingModel(): MeetingModel
318
	{
319
		return $this->meetingModel;
320
	}
321
322
	/**
323
	 * @param  MeetingModel $model
324
	 * @return RegistrationForm
325
	 */
326
	protected function setMeetingModel(MeetingModel $model): RegistrationForm
327
	{
328
		$this->meetingModel = $model;
329
330
		return $this;
331
	}
332
333
	/**
334
	 * @return array
335
	 */
336
	protected function getMealFields(): array
337
	{
338
		return $this->mealFields;
339
	}
340
341
	/**
342
	 * @param  string $meal
343
	 * @return RegistrationForm
344
	 */
345
	protected function setMealField(string $meal): RegistrationForm
346
	{
347
		if(!in_array($meal, $this->mealFields)) {
348
			$this->mealFields[] = $meal;
349
		}
350
351
		return $this;
352
	}
353
354
	/**
355
	 * @return array
356
	 */
357
	protected function getProgramFields(): array
358
	{
359
		return $this->programFields;
360
	}
361
362
	/**
363
	 * @param  string $program
364
	 * @return RegistrationForm
365
	 */
366
	protected function setProgramField(string $program): RegistrationForm
367
	{
368
		$this->programFields[] = $program;
369
370
		return $this;
371
	}
372
373
	/**
374
	 * @return RegistrationForm
375
	 */
376
	protected function setProgramFields(): RegistrationForm
377
	{
378
		$programBlocks = $this->fetchProgramBlocks();
379
380
		foreach ($programBlocks as $block) {
381
			$programFieldName = 'blck_' . $block->id;
382
			$this->setProgramField($programFieldName);
383
		}
384
385
		return $this;
386
	}
387
388
	/**
389
	 * @return  RegistrationForm
390
	 */
391
	protected function setMealFields(): RegistrationForm
392
	{
393
		$meals = $this->fetchMeals();
394
395
		foreach ($meals as $name => $label) {
396
			$this->setMealField($name);
397
		}
398
399
		return $this;
400
	}
401
402
	/**
403
	 * @return Row
404
	 */
405
	protected function fetchProgramBlocks()
406
	{
407
		return $this->getBlockModel()->getProgramBlocks($this->getMeetingId());
408
	}
409
410
	/**
411
	 * @return array
412
	 */
413
	protected function fetchMeals()
414
	{
415
		return MealModel::$meals;
416
	}
417
418
	/**
419
	 * @return UserService
420
	 */
421
	protected function getUserService()
422
	{
423
		return $this->userService;
424
	}
425
426
	/**
427
	 * @param  UserService $service
428
	 * @return $this
429
	 */
430
	protected function setUserService(UserService $service)
431
	{
432
		$this->userService = $service;
433
434
		return $this;
435
	}
436
437
	/**
438
	 * @param  array  $programs
439
	 * @return array
440
	 */
441
	protected function filterFilledCapacity(array $programs = []): array
442
	{
443
		return array_keys(
444
			array_filter($programs, function($name, $id) {
445
				if ($id) {
446
					$visitorsOnProgram = $this->getProgramModel()->countProgramVisitors($id);
447
					$programCapacity = $this->getProgramModel()->findByProgramId($id)->capacity;
448
449
					return $visitorsOnProgram >= $programCapacity;
450
				}
451
			}, ARRAY_FILTER_USE_BOTH)
452
		);
453
	}
454
455
}
456