LsfRepeatingFieldset   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
eloc 16
c 3
b 1
f 0
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addToJson() 0 7 2
A response() 0 18 3
1
<?php
2
3
namespace Riclep\StoryblokForms\Blocks;
4
5
class LsfRepeatingFieldset extends LsfFieldset
6
{
7
	protected string $type = 'repeating-fieldset';
8
9
	/**
10
	 * Add additional data for the Repeating Fieldset for VueJS
11
	 *
12
	 * @return array
13
	 */
14
	protected function addToJson(): array
15
	{
16
		$json['min'] = $this->min;
0 ignored issues
show
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...
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...
17
		$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...
18
		$json['item_name'] = $this->item_name ?: 'Item';
0 ignored issues
show
Bug Best Practice introduced by
The property item_name does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
20
		return $json;
21
	}
22
23
	/**
24
	 * Returns the Fieldset’s response after the form has been submitted and validated
25
	 *
26
	 * @param $input
27
	 * @return array
28
	 */
29
	public function response($input): array
30
	{
31
		return [
32
			'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...
33
			'name' => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
			'item_name' => $this->item_name === '' ? $this->item_name : 'Item',
0 ignored issues
show
Bug Best Practice introduced by
The property item_name does not exist on Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
			'response' => collect($input)->map(fn($repeatedFields) => $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

35
			'response' => collect($input)->map(fn($repeatedFields) => $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...
36
37
				// Handle empty radio buttons and uncreated repeats (no fields made)
38
				//if ($field instanceof \Riclep\StoryblokForms\Blocks\LsfRadioButton) {
39
					if (!array_key_exists($field->name, $repeatedFields)) {
40
						$repeatedFields[$field->name] = null;
41
					}
42
				//}
43
44
				return $field->response($repeatedFields[$field->name]);
45
			})->keyBy('name')->toArray())->toArray(),
46
			'type' => $this->type,
47
		];
48
	}
49
}