HasChildClasses   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getChildClassName() 0 15 5
1
<?php
2
3
4
namespace Riclep\Storyblok\Traits;
5
6
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Str;
9
10
trait HasChildClasses
11
{
12
	/**
13
	 * A general method for finding child classes such as nested Blocks and Fields.
14
	 * Tries to match them based on their type and name
15
	 *
16
	 * @param $type
17
	 * @param $name
18
	 * @return string|null
19
	 */
20
	public function getChildClassName($type, $name): ?string
21
	{
22
		foreach (Arr::wrap(config('storyblok.component_class_namespace')) as $namespace) {
23
			if (class_exists($namespace . Str::pluralStudly($type) . '\\' . Str::studly($name))) {
24
				return $namespace . Str::pluralStudly($type) . '\\' . Str::studly($name);
25
			}
26
		}
27
28
		foreach (Arr::wrap(config('storyblok.component_class_namespace')) as $namespace) {
29
			if (class_exists($namespace . Str::studly($type))) {
30
				return $namespace . Str::studly($type);
31
			}
32
		}
33
34
		return null;
35
	}
36
}