Passed
Push — develop ( f56b73...2ea827 )
by Richard
03:42
created

Input::validationRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Riclep\StoryblokForms;
4
5
use Riclep\StoryblokForms\Blocks\LsfFieldset;
6
use Riclep\StoryblokForms\Blocks\LsfRepeatingFieldset;
7
use Riclep\StoryblokForms\Traits\ToJson;
8
9
class Input extends \Riclep\Storyblok\Block
10
{
11
	use ToJson;
12
13
	protected $inFieldSet = false;
14
	protected $isRepeating = false;
15
	protected $key;
16
17
	/**
18
	 * @var string[] All the Validators for this Input
19
	 */
20
	protected $_casts = ['validators' => Validators::class];
21
22
	public function __construct($content, $parent = null)
23
	{
24
		parent::__construct($content, $parent);
25
26
		if ($this->parent() instanceof LsfFieldset) {
27
			$this->inFieldSet = true;
28
		}
29
30
		if ($this->parent() instanceof LsfRepeatingFieldset) {
31
			$this->isRepeating = true;
32
		}
33
	}
34
35
	public function getInputNameAttribute() {
36
		if ($this->isRepeating) {
37
			return $this->parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']';
38
		}
39
40
		if ($this->inFieldSet) {
41
			return $this->parent()->input_name . '[' . $this->content()['name'] . ']';
42
		}
43
44
		return $this->content()['name'];
45
	}
46
47
48
	public function loopKey($key) {
49
		$this->key = $key;
50
51
		return $this;
52
	}
53
54
55
	/**
56
	 * All the Validation rules for this Input
57
	 *
58
	 * @return mixed
59
	 */
60
	public function validationRules() {
61
		return $this->validators->validationRules();
0 ignored issues
show
Bug Best Practice introduced by
The property validators does not exist on Riclep\StoryblokForms\Input. Since you implemented __get, consider adding a @property annotation.
Loading history...
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

61
		return $this->validators->/** @scrutinizer ignore-call */ 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...
62
	}
63
64
	/**
65
	 * All the error messages for this Input
66
	 *
67
	 * @return mixed
68
	 */
69
	public function errorMessages() {
70
		return $this->validators->errorMessages();
0 ignored issues
show
Bug Best Practice introduced by
The property validators does not exist on Riclep\StoryblokForms\Input. Since you implemented __get, consider adding a @property annotation.
Loading history...
71
	}
72
}