Code Duplication    Length = 36-37 lines in 2 locations

src/Config/OptionalTrait.php 1 location

@@ 8-43 (lines=36) @@
5
 * Class OptionalTrait
6
 * @package FMUP\Config
7
 */
8
trait OptionalTrait
9
{
10
    private $config;
11
12
    /**
13
     * Define config
14
     * @param ConfigInterface|null $configInterface
15
     * @return $this
16
     */
17
    public function setConfig(ConfigInterface $configInterface = null)
18
    {
19
        $this->config = $configInterface;
20
        return $this;
21
    }
22
23
    /**
24
     * Retrieve defined config
25
     * @return ConfigInterface
26
     */
27
    public function getConfig()
28
    {
29
        if (!$this->hasConfig()) {
30
            $this->config = new \FMUP\Config();
31
        }
32
        return $this->config;
33
    }
34
35
    /**
36
     * Check if config exists
37
     * @return bool
38
     */
39
    public function hasConfig()
40
    {
41
        return (bool)$this->config;
42
    }
43
}
44

src/Config/RequiredTrait.php 1 location

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