Passed
Push — develop ( 90a1cd...5fc47b )
by Richard
03:25
created

HasNames::getInputJsonNameAttribute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Riclep\StoryblokForms\Traits;
4
5
trait HasNames
6
{
7
	/**
8
	 * @property-read $input_name
9
	 *
10
	 * @return mixed|string
11
	 */
12
	public function getInputNameAttribute() {
13
		if ($this->isRepeating) {
14
			return $this->parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']';
0 ignored issues
show
Bug introduced by
It seems like parent() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
			return $this->/** @scrutinizer ignore-call */ parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']';
Loading history...
Bug introduced by
It seems like content() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
			return $this->parent()->input_name . '[' . $this->key . '][' . $this->/** @scrutinizer ignore-call */ content()['name'] . ']';
Loading history...
15
		}
16
17
		if ($this->inFieldSet) {
18
			return $this->parent()->input_name . '[' . $this->content()['name'] . ']';
19
		}
20
21
		return $this->content()['name'];
22
	}
23
24
	/**
25
	 * @property-read $input_name
26
	 *
27
	 * @return mixed|string
28
	 */
29
	public function getInputJsonNameAttribute() {
30
		if ($this->isRepeating) {
31
			return $this->parent()->input_name . '[' . $this->key . '][' . $this->content()['name'] . ']';
32
		}
33
34
		if ($this->inFieldSet) {
35
			return $this->parent()->name . '[' . $this->content()['name'] . ']';
36
		}
37
38
		return $this->content()['name'];
39
	}
40
41
	/**
42
	 * @property-read $input_dot_name
43
	 *
44
	 * @return mixed|string
45
	 */
46
	public function getInputDotNameAttribute() {
47
		return str_replace([
48
			'[]',
49
			'[',
50
			']'
51
		], [
52
			'.*',
53
			'.',
54
			''
55
		], $this->input_name);
56
	}
57
58
	/**
59
	 * @property-read $input_dot_name
60
	 *
61
	 * @return mixed|string
62
	 */
63
	public function getInputJsonDotNameAttribute() {
64
		return str_replace([
65
			'[]',
66
			'[',
67
			']'
68
		], [
69
			'.*',
70
			'.',
71
			''
72
		], $this->input_json_name);
73
	}
74
}