Passed
Push — master ( 859573...a81ea2 )
by Gabriel
03:21
created

InitTrait::doInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 2
    public function init()
16
    {
17 2
        if ($this->init === true) {
18
            return;
19
        }
20 2
        $this->doInit();
21 2
        $this->init = true;
22 2
    }
23
24 2
    protected function doInit()
25
    {
26 2
        $this->initVariablesFromConfig();
27 2
    }
28
29 2
    protected function initVariablesFromConfig()
30
    {
31 2
        $configKey = 'media-library.contraints.' . $this->getName();
0 ignored issues
show
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

31
        $configKey = 'media-library.contraints.' . $this->/** @scrutinizer ignore-call */ getName();
Loading history...
32
33 2
        if (function_exists('config') && function_exists('app') && app()->has('config')) {
34 2
            if (config()->has($configKey)) {
35
                $variables = config()->get($configKey);
36
                $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

36
                $this->/** @scrutinizer ignore-call */ 
37
                       applyVariables($variables);
Loading history...
37
            }
38
        }
39 2
    }
40
}
41