Passed
Pull Request — 2.x (#1308)
by Harings
07:04
created

TwillBlock::getBlockClassForName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace A17\Twill\Helpers;
4
5
use A17\Twill\Models\Block;
6
use Illuminate\Support\Str;
7
8
abstract class TwillBlock
9
{
10
    /**
11
     * @var array
12
     *
13
     * The validation rules for this block.
14
     */
15
    protected $rules = [];
16
17
    /**
18
     * @var array
19
     *
20
     * The validation rules for this block.
21
     */
22
    protected $rulesForTranslatedFields = [];
23
24
    public function __construct()
25
    {
26
    }
27
28
    public function getData(Block $block, array $data): array
0 ignored issues
show
Unused Code introduced by
The parameter $block is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public function getData(/** @scrutinizer ignore-unused */ Block $block, array $data): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        return $data;
31
    }
32
33
    public function getRules(): array
34
    {
35
        return $this->rules;
36
    }
37
38
    public function getRulesForTranslatedFields(): array
39
    {
40
        return $this->rulesForTranslatedFields;
41
    }
42
43
    public static function getBlockClassForName(string $name): ?TwillBlock
44
    {
45
        $transformed = Str::studly($name) . 'Block';
46
        $className = "\App\Twill\Block\\$transformed";
47
        if (class_exists($className)) {
48
            return new $className();
49
        }
50
51
        return null;
52
    }
53
54
    public static function getBlockClassForView(string $view): ?TwillBlock
55
    {
56
        $exploded = explode('.', $view);
57
58
        return self::getBlockClassForName(array_pop($exploded));
59
    }
60
}
61