Passed
Push — develop ( 2ea827...ee0fc4 )
by Richard
03:14
created

Input   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 74
rs 10
c 1
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A getInputNameAttribute() 0 10 3
A validationRules() 0 2 1
A errorMessages() 0 2 1
A loopKey() 0 4 1
A getInputDotNameAttribute() 0 10 1
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
	public function getInputDotNameAttribute() {
48
		return str_replace([
49
			'[]',
50
			'[',
51
			']'
52
		], [
53
			'.*',
54
			'.',
55
			''
56
		], $this->input_name);
0 ignored issues
show
Bug Best Practice introduced by
The property input_name does not exist on Riclep\StoryblokForms\Input. Since you implemented __get, consider adding a @property annotation.
Loading history...
57
	}
58
59
60
	public function loopKey($key) {
61
		$this->key = $key;
62
63
		return $this;
64
	}
65
66
67
	/**
68
	 * All the Validation rules for this Input
69
	 *
70
	 * @return mixed
71
	 */
72
	public function validationRules() {
73
		return $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

73
		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...
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...
74
	}
75
76
	/**
77
	 * All the error messages for this Input
78
	 *
79
	 * @return mixed
80
	 */
81
	public function errorMessages() {
82
		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...
83
	}
84
}