Module::prepare()   C
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 32
Code Lines 19

Duplication

Lines 6
Ratio 18.75 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 19
nc 7
nop 0
dl 6
loc 32
rs 6.7272
c 2
b 0
f 0
1
<?php declare(strict_types=1);
2
namespace samson\activerecord;
3
4
use samsonframework\core\CompressInterface;
5
use samson\core\CompressableExternalModule;
6
7
class Module extends CompressableExternalModule implements CompressInterface
0 ignored issues
show
Deprecated Code introduced by
The class samson\core\CompressableExternalModule has been deprecated with message: Just implement samsonframework\core\CompressInterface

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
8
{
9
    /** Database table prefix */
10
    public $prefix;
11
    /** Database name */
12
    public $name;
13
    /** Login */
14
    public $login = 'root';
15
    /** Password */
16
    public $pwd;
17
    /** Host */
18
    public $host = '127.0.0.1';
19
    /** @var string Port number */
20
    public $port = '';
21
    public $relations = array();
22
23
    /* Array of additional relations to set */
24
    /**
25
     * Идентификатор модуля
26
     * @var string
27
     */
28
    protected $id = 'activerecord';
29
30
    /** @see \samson\core\CompressableExternalModule::beforeCompress() */
31
    public function beforeCompress(& $obj = null, array & $code = null)
32
    {
33
34
    }
35
36
    /** @see \samson\core\CompressableExternalModule::afterCompress() */
37
    public function afterCompress(& $obj = null, array & $code = null)
38
    {
39
        // Iterate through generated php code
40
        $files = array();
41
        foreach (\samson\core\File::dir($this->cache_path . 'metadata', 'php', '', $files, 1) as $file) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
42
43
            // No namespace for global function file
44
            $ns = strpos($file, 'func') === false ? __NAMESPACE__ : '';
45
46
            // Compress generated php code
47
            $obj->compress_php($file, $this, $code, $ns);
48
        }
49
50
        // Iterate through generated php code
51
        $files = array();
52
        foreach (\samson\core\File::dir($this->cache_path . 'relations', 'php', '', $files, 1) as $file) {
53
            // No namespace for global function file
54
            $ns = strpos($file, 'func') === false ? __NAMESPACE__ : '';
55
56
            // Compress generated php code
57
            $obj->compress_php($file, $this, $code, $ns);
58
        }
59
    }
60
61
    /** @see \samson\core\ExternalModule::prepare() */
62
    public function prepare()
63
    {
64
        // Set table prefix
65
        dbMySQLConnector::$prefix = $this->prefix;
66
67
        // Connect to database
68
        //db()->connect($this->name, $this->login, $this->pwd, $this->host, $this->port);
69
70
        // Create specific relations
71
        foreach ($this->relations as $args) {
72
            switch (sizeof($args)) {
73
                case 2:
74
                    new TableRelation($args[0], $args[1]);
75
                    break;
76
                case 3:
77
                    new TableRelation($args[0], $args[1], $args[2]);
78
                    break;
79
                case 4:
80
                    new TableRelation($args[0], $args[1], $args[2], $args[3]);
81
                    break;
82 View Code Duplication
                case 5:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
83
                    new TableRelation($args[0], $args[1], $args[2], $args[3], $args[4]);
84
                    break;
85 View Code Duplication
                case 6:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
86
                    new TableRelation($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
87
                    break;
88
            }
89
        }
90
91
        // Generate db table classes
92
        //db()->generate(false, $this->cache_path);
93
    }
94
95
    //[PHPCOMPRESSOR(remove,start)]
96
    public function relations()
97
    {
98
        //db()->relations($this->cache_path);
99
    }
100
101
    //[PHPCOMPRESSOR(remove,end)]
102
103
    /** @see \samson\core\ExternalModule::init() */
104
    public function init(array $params = array())
105
    {
106
        parent::init($params);
107
108
        // Set table prefix
109
        dbMySQLConnector::$prefix = $this->prefix;
110
111
        //db()->connect($this->name, $this->login, $this->pwd, $this->host, $this->port);
112
    }
113
}
114