Completed
Push — master ( 8d2de8...1ce70a )
by Litera
17s
created

RegistrationForm::setupRendering()   D

Complexity

Conditions 10
Paths 5

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
cc 10
eloc 26
nc 5
nop 1
rs 4.8196

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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