Passed
Push — develop ( 5fc47b...df6c69 )
by Richard
14:20
created

HasNames::getInputDotNameAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
c 1
b 1
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
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_dot_name
26
	 *
27
	 * @return mixed|string
28
	 */
29
	public function getInputDotNameAttribute() {
30
		return str_replace([
31
			'[]',
32
			'[',
33
			']'
34
		], [
35
			'.*',
36
			'.',
37
			''
38
		], $this->input_name);
39
	}
40
41
	/**
42
	 * @property-read $input_dot_name
43
	 *
44
	 * @return mixed|string
45
	 */
46
	public function getInputJsonDotNameAttribute() {
47
		return str_replace([
48
			'[]',
49
			'[',
50
			']'
51
		], [
52
			'.*',
53
			'.',
54
			''
55
		], $this->input_name);
56
	}
57
}