Passed
Push — develop ( e66b52...83bea4 )
by Richard
03:56
created

LsfInput::validationRules()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
rs 9.6111
cc 5
nc 3
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 $type = 'input';
13
14
	/**
15
	 * All the Validation rules for this Input
16
	 *
17
	 * @return mixed
18
	 */
19
	public function errorMessages() {
20
		$messages = $this->validators->errorMessages();
0 ignored issues
show
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...
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

20
		/** @scrutinizer ignore-call */ 
21
  $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...
21
22
		/**
23
		 * Rewrite required to required_if for items inside conditional selects
24
		 */
25
		if ($this->parent() instanceof LsfConditionalSelect) {
26
			foreach ($messages as $key => $rule) {
27
				if (Str::endsWith($key, 'required')) {
28
					$messages[$key . '_if'] = $messages[$key];
29
30
					unset($messages[$key]);
31
				}
32
			}
33
		}
34
35
		return $messages;
36
	}
37
38
	/**
39
	 * Returns the Input’s response after the form has been submitted and validated
40
	 *
41
	 * @param $input
42
	 * @return mixed
43
	 */
44
	public function response($input) {
45
		return [
46
			'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...
47
			'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...
48
			'response' => $input,
49
			'type' => $this->type,
50
		];
51
	}
52
}