LsfInput::errorMessages()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 4
nc 2
nop 0
1
<?php
2
3
namespace Riclep\StoryblokForms\Blocks;
4
5
use Illuminate\Support\Str;
6
use Riclep\StoryblokForms\Input;
7
8
class LsfInput extends Input
9
{
10
	// Interface this....
11
12
	protected string $type = 'input';
13
14
	/**
15
	 * All the Validation rules for this Input
16
	 *
17
	 * @return mixed
18
	 */
19
	public function errorMessages(): mixed
20
	{
21
		$messages = $this->validators->errorMessages();
0 ignored issues
show
Bug introduced by
The method errorMessages() 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

21
		/** @scrutinizer ignore-call */ 
22
  $messages = $this->validators->errorMessages();

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...
Bug Best Practice introduced by
The property validators does not exist on Riclep\StoryblokForms\Blocks\LsfInput. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
23
		/**
24
		 * Rewrite required to required_if for items inside conditional selects
25
		 */
26
		if ($this->parent() instanceof LsfConditionalSelect) {
27
			foreach ($messages as $key => $rule) {
28
				if (Str::endsWith($key, 'required')) {
29
					$messages[$key . '_if'] = $messages[$key];
30
31
					unset($messages[$key]);
32
				}
33
			}
34
		}
35
36
		return $messages;
37
	}
38
39
	/**
40
	 * Returns the Input’s response after the form has been submitted and validated
41
	 *
42
	 * @param $input
43
	 * @return array
44
	 */
45
	public function response($input): array
46
	{
47
		return [
48
			'label' => $this->label,
0 ignored issues
show
Bug Best Practice introduced by
The property label does not exist on Riclep\StoryblokForms\Blocks\LsfInput. Since you implemented __get, consider adding a @property annotation.
Loading history...
49
			'name' => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Riclep\StoryblokForms\Blocks\LsfInput. Since you implemented __get, consider adding a @property annotation.
Loading history...
50
			'response' => $input,
51
			'type' => $this->type,
52
		];
53
	}
54
}