Completed
Push — master ( 14f560...15f305 )
by
unknown
08:01
created

Module::requireClasses()   C

Complexity

Conditions 12
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 14
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 23
rs 5.2987

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace samsonphp\core\loader\module;
4
5
use samsonframework\container\ContainerConfigurableInterface;
6
7
/**
8
 * Class Module
9
 *
10
 * @package samsonphp\core\loader\module
11
 */
12
class Module
13
{
14
    /** @var string Interface which mark as class configure the module */
15
    public static $containerConfigurableInterface = ContainerConfigurableInterface::class;
16
17
    /** @var string Module name */
18
    public $name;
19
    /** @var string Module class name */
20
    public $className;
21
    /** @var string Module path name */
22
    public $pathName;
23
    /** @var string Module path */
24
    public $path;
25
    /** @var array List of classes */
26
    public $classes = [];
27
    /** @var bool Is module has custom dependency injection configurator */
28
    public $isContainerConfigurable = false;
29
    /** @var string Configure dependency injection class */
30
    public $containerConfigurableClassName;
31
    public $composerParameters;
32
33
    public function __construct($name, $path, $classes)
34
    {
35
        $this->name = $name;
36
        $this->path = $path;
37
        $this->classes = $classes;
38
39
//        $this->requireClasses();
40
//        $this->checkIsContainerConfigurable();
41
    }
42
43
    /**
44
     * Require module classes
45
     */
46
    protected function requireClasses()
47
    {
48
        foreach ($this->classes as $classPath => $className) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
49
50
            $className = '\\' . ltrim($className, '\\');
51
//            if (preg_match('/dbQuery/', $className)) {
52
//                trace('sdf');
53
//            }
54
            if (file_exists($classPath)
55
                && !preg_match('/\/api\/generated\//', $className)
56
                && !preg_match('/activerecord\/dbQuery/', $className)
57
                && !preg_match('/samson\/activerecord\//', $className)
58
                && !preg_match('/Field.php$/', $classPath)
59
                && !preg_match('/Navigation.php$/', $classPath)
60
                && !preg_match('/TableVirtualCollection.php$/', $classPath)
61
                && !preg_match('/TableVirtualEntity.php$/', $classPath)
62
                && !preg_match('/TableVirtualQuery.php$/', $classPath)
63
                && !class_exists($className)
64
            ) {
65
                require_once($classPath);
66
            }
67
        }
68
    }
69
70
    /**
71
     * Check if class configures the container
72
     */
73
    public function checkIsContainerConfigurable()
74
    {
75
        // Find class with correct interface
76
        foreach ($this->classes as $classPath => $className) {
77
            $reflectionClass = new \ReflectionClass($className);
78
            // If class implements correct interface then it is container configurable
79
            if (in_array($this::$containerConfigurableInterface, $reflectionClass->getInterfaceNames(), true)) {
80
                $this->isContainerConfigurable = true;
81
                $this->containerConfigurableClassName = $className;
82
            }
83
        }
84
    }
85
}
86