Passed
Push — develop ( dc3999...d76358 )
by Richard
03:42
created

LsfInput   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validationRules() 0 23 5
A response() 0 5 1
1
<?php
2
3
namespace Riclep\StoryblokForms\Blocks;
4
5
use Riclep\StoryblokForms\Input;
6
7
class LsfInput extends Input
8
{
9
	// Interface this....
10
11
	protected $type = 'input';
12
13
	/**
14
	 * All the Validation rules for this Input
15
	 *
16
	 * @return mixed
17
	 */
18
	public function validationRules() {
19
		$rules = $this->validators->validationRules();
0 ignored issues
show
Bug introduced by
The method validationRules() 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

19
		/** @scrutinizer ignore-call */ 
20
  $rules = $this->validators->validationRules();

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