HasNames   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 22
c 2
b 1
f 0
dl 0
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInputNameAttribute() 0 11 3
A getInputJsonDotNameAttribute() 0 11 1
A getInputDotNameAttribute() 0 11 1
1
<?php
2
3
namespace Riclep\StoryblokForms\Traits;
4
5
trait HasNames
6
{
7
	// TODO - these methods should be FullName not Name.... keep name untouched
8
9
	/**
10
	 * @property-read $input_name
11
	 *
12
	 * @return string
13
	 */
14
	public function getInputNameAttribute(): string
15
	{
16
		if ($this->isRepeating) {
17
			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

17
			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

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