Passed
Push — main ( f9bc30...9f095f )
by Sammy
01:20
created

Configuration::hasClassNameModifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace HexMakina\LeMarchand;
4
5
class Configuration
6
{
7
8
    public const RX_SETTINGS = '/^settings\./';
9
10
    public const RX_MVC = '/(Models|Controllers)\\\([a-zA-Z]+)(::class|::new)?/';
11
12
    public const RX_INTERFACE = '/([a-zA-Z]+)Interface$/';
13
14
15
    private $lament;
16
17
    public function __construct($configuration_string)
18
    {
19
        $this->lament = $configuration_string;
20
    }
21
22
    public function isSettings()
23
    {
24
        return preg_match(self::RX_SETTINGS, $this->lament) === 1;
25
    }
26
27
    public function isInterface()
28
    {
29
        return preg_match(self::RX_INTERFACE, $this->lament) === 1;
30
    }
31
32
    public function isModelOrController()
33
    {
34
        return preg_match(self::RX_MVC, $this->lament) === 1;
35
    }
36
37
    public function hasClassNameModifier()
38
    {
39
        return strpos($this->lament, '::class') !== false;
40
    }
41
42
    public function hasNewInstanceModifier()
43
    {
44
        return strpos($this->lament, '::new') !== false;
45
    }
46
47
    public function getModelOrControllerName()
48
    {
49
        preg_match(self::RX_MVC, $this->lament, $m);
50
        return $m[1] . '\\' . $m[2];
51
    }
52
}
53