RequiredTrait::hasConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace FMUP\Config;
3
4
/**
5
 * Class RequiredTrait
6
 * @package FMUP\Config
7
 */
8 View Code Duplication
trait RequiredTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    private $config;
11
12
    /**
13
     * Define config
14
     * @param ConfigInterface|null $configInterface
15
     * @return $this
16
     */
17 2
    public function setConfig(ConfigInterface $configInterface)
18
    {
19 2
        $this->config = $configInterface;
20 2
        return $this;
21
    }
22
23
    /**
24
     * Retrieve defined config
25
     * @return ConfigInterface
26
     * @throws Exception if config is not defined
27
     */
28 2
    public function getConfig()
29
    {
30 2
        if (!$this->hasConfig()) {
31 1
            throw new Exception('Config must be defined');
32
        }
33 1
        return $this->config;
34
    }
35
36
    /**
37
     * Check if config exists
38
     * @return bool
39
     */
40 2
    public function hasConfig()
41
    {
42 2
        return (bool)$this->config;
43
    }
44
}
45