Passed
Push — develop ( f56b73...2ea827 )
by Richard
03:42
created

LsfRepeatingFieldset::response()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Riclep\StoryblokForms\Blocks;
4
5
use Riclep\StoryblokForms\Traits\ToJson;
6
7
class LsfRepeatingFieldset extends LsfFieldset
8
{
9
	use ToJson;
10
11
	public function response($input) {
12
		return [
13
			'label' => $this->label,
0 ignored issues
show
Bug Best Practice introduced by
The property label does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
14
			'response' => collect($input)->map(function ($repeatedFields) {
15
				return $this->fields->map(function ($field) use ($repeatedFields) {
0 ignored issues
show
Bug Best Practice introduced by
The property fields does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method map() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
				return $this->fields->/** @scrutinizer ignore-call */ map(function ($field) use ($repeatedFields) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
					// Handle empty radio buttons sending nothing in POST request
17
					if ($field instanceof \Riclep\StoryblokForms\Blocks\LsfRadioButton) {
18
						if (!array_key_exists($field->name, $repeatedFields)) {
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Riclep\StoryblokForms\Blocks\LsfRadioButton. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
							$repeatedFields[$field->name] = null;
20
						}
21
					}
22
23
					return $field->response($repeatedFields[$field->name]);
24
				});
25
			})
26
		];
27
	}
28
}