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

InitTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 29
ccs 12
cts 15
cp 0.8
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 2
A doInit() 0 3 1
A initVariablesFromConfig() 0 8 5
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