Passed
Push — master ( 3295fe...37d5c2 )
by Richard
04:14 queued 14s
created

CssClasses::isLayout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
7
use Illuminate\Support\Str;
8
use Riclep\Storyblok\Block;
9
10
trait CssClasses
11
{
12
	public function cssClassWithParent()
13
	{
14
		return $this->component() . '@' . $this->getAncestorComponent(1);
0 ignored issues
show
Bug introduced by
It seems like getAncestorComponent() 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->component() . '@' . $this->/** @scrutinizer ignore-call */ getAncestorComponent(1);
Loading history...
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

14
		return $this->/** @scrutinizer ignore-call */ component() . '@' . $this->getAncestorComponent(1);
Loading history...
15
	}
16
17
	public function cssClassWithLayout()
18
	{
19
		if ($layout = $this->getLayout()) {
20
			return $this->component() . '@' . $layout;
21
		}
22
23
		return $this->component();
24
	}
25
26
27
	public function cssClass()
28
	{
29
		return $this->component();
30
	}
31
32
	public function isLayout()
33
	{
34
		return $this->layoutCheck($this->component());
35
	}
36
37
	public function getLayout()
38
	{
39
		$path = $this->componentPath();
0 ignored issues
show
Bug introduced by
It seems like componentPath() 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

39
		/** @scrutinizer ignore-call */ 
40
  $path = $this->componentPath();
Loading history...
40
		array_pop($path);
41
		$path = array_reverse($path);
42
43
		foreach ($path as $ancestor) {
44
			if ($this->layoutCheck($ancestor)) {
45
				return $ancestor;
46
			}
47
		}
48
49
		return null;
50
	}
51
52
	private function layoutCheck($componentName) {
53
		return Str::startsWith($componentName, 'layout_');
54
	}
55
}