Passed
Push — develop ( bd344d...2cd0ec )
by Richard
03:46
created

ToJson   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 14 3
1
<?php
2
3
namespace Riclep\StoryblokForms\Traits;
4
5
use Riclep\StoryblokForms\MultiInput;
6
7
trait ToJson
8
{
9
	public function jsonSerialize(): mixed
10
	{
11
		$rules = $this->validationRules();
0 ignored issues
show
Bug introduced by
It seems like validationRules() 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

11
		/** @scrutinizer ignore-call */ 
12
  $rules = $this->validationRules();
Loading history...
12
13
		$content = $this->content();
0 ignored issues
show
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

13
		/** @scrutinizer ignore-call */ 
14
  $content = $this->content();
Loading history...
14
		$content['validators'] = $rules ? $rules[array_key_first($rules)] : [];
15
16
		if ($this instanceof MultiInput) {
17
			$content['options'] = $this->options();
18
		}
19
20
		return collect([
21
			'component' => $this->component(),
0 ignored issues
show
Bug introduced by
It seems like component() 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

21
			'component' => $this->/** @scrutinizer ignore-call */ component(),
Loading history...
22
			'content' => $content,
23
		]);
24
	}
25
}