Passed
Push — develop ( 10fa5a...842b91 )
by Richard
03:29
created

LsfSelect::errorMessages()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 17
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\MultiInput;
7
8
class LsfSelect extends MultiInput
9
{
10
	/**
11
	 * @var string
12
	 */
13
	protected $optionsName = 'options';
14
15
	protected $type = 'multi-input';
16
17
18
	/**
19
	 * All the error messages for this Input
20
	 *
21
	 * @return mixed
22
	 */
23
	public function errorMessages() {
24
		$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

24
		/** @scrutinizer ignore-call */ 
25
  $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\LsfSelect. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
26
		/**
27
		 * Rewrite required to required_if for items inside conditional selects
28
		 */
29
		if ($this->parent() instanceof LsfConditionalSelect) {
30
			foreach ($messages as $key => $rule) {
31
				if (Str::endsWith($key, 'required')) {
32
					$messages[$key . '_if'] = $messages[$key];
33
34
					unset($messages[$key]);
35
				}
36
			}
37
		}
38
39
		return $messages;
40
	}
41
}