InitTrait::initVariablesFromConfig()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6.0208

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 11
nc 4
nop 0
dl 0
loc 15
ccs 11
cts 12
cp 0.9167
crap 6.0208
rs 9.2222
c 1
b 0
f 1
1
<?php
2
3
namespace ByTIC\MediaLibrary\Validation\Constraints\Traits;
4
5
/**
6
 * Trait InitTrait.
7
 */
8
trait InitTrait
9
{
10
    /**
11
     * @var bool
12
     */
13
    protected $init = false;
14
15 4
    public function init()
16
    {
17 4
        if ($this->init === true) {
18
            return;
19
        }
20 4
        $this->doInit();
21 4
        $this->init = true;
22 4
    }
23
24 4
    protected function doInit()
25
    {
26 4
        $this->initVariablesFromConfig();
27 4
    }
28
29 4
    protected function initVariablesFromConfig()
30
    {
31 4
        if (!function_exists('config')
32 4
            || !function_exists('app')
33 4
            || !app()->has('config')) {
34
            return;
35
        }
36
37 4
        $tries = [$this->getName(), $this->generateName()];
0 ignored issues
show
Bug introduced by
It seems like generateName() 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

37
        $tries = [$this->getName(), $this->/** @scrutinizer ignore-call */ generateName()];
Loading history...
Bug introduced by
It seems like getName() 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

37
        $tries = [$this->/** @scrutinizer ignore-call */ getName(), $this->generateName()];
Loading history...
38 4
        foreach ($tries as $name) {
39 4
            $configKey = 'media-library.contraints.' . $name;
40 4
            if (config()->has($configKey)) {
41 1
                $variables = config()->get($configKey);
42 1
                $this->applyVariables($variables);
0 ignored issues
show
Bug introduced by
It seems like applyVariables() 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

42
                $this->/** @scrutinizer ignore-call */ 
43
                       applyVariables($variables);
Loading history...
43 1
                return;
44
            }
45
        }
46 3
    }
47
}
48