Passed
Push — develop ( d74ec0...dc3999 )
by Richard
03:13
created

LsfRepeatingFieldset::addToJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Riclep\StoryblokForms\Blocks;
4
5
class LsfRepeatingFieldset extends LsfFieldset
6
{
7
	protected $type = 'repeating-fieldset';
8
9
	protected function addToJson() {
10
		$json['min'] = $this->min;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.
Loading history...
Bug Best Practice introduced by
The property min does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
11
		$json['max'] = $this->max;
0 ignored issues
show
Bug Best Practice introduced by
The property max does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
12
13
		return $json;
14
	}
15
16
	public function response($input) {
17
		return [
18
			'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...
19
			'response' => collect($input)->map(function ($repeatedFields) {
20
				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

20
				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...
21
22
					// Handle empty radio buttons and uncreated repeats (no fields made)
23
					//if ($field instanceof \Riclep\StoryblokForms\Blocks\LsfRadioButton) {
24
						if (!array_key_exists($field->name, $repeatedFields)) {
25
							$repeatedFields[$field->name] = null;
26
						}
27
					//}
28
29
					return $field->response($repeatedFields[$field->name]);
30
				})->toArray();
31
			})->toArray(),
32
			'type' => $this->type,
33
		];
34
	}
35
}