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

TwillBlock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 51
rs 10
c 2
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRules() 0 3 1
A getRulesForTranslatedFields() 0 3 1
A getBlockClassForView() 0 5 1
A getData() 0 3 1
A __construct() 0 2 1
A getBlockClassForName() 0 9 2
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