Completed
Push — master ( 496f6c...fa7820 )
by Iurii
01:48
created

Main   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hookCliRouteList() 0 5 1
A getRoutes() 0 19 2
1
<?php
2
3
/**
4
 * @package CLI
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2018, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\cli;
11
12
/**
13
 * Main class for CLI module
14
 */
15
class Main
16
{
17
18
    /**
19
     * Implements hook "cli.route.list"
20
     * @param mixed $routes
21
     */
22
    public function hookCliRouteList(array &$routes)
23
    {
24
        $custom = $this->getRoutes();
25
        $routes = array_merge($routes, $custom);
26
    }
27
28
    /**
29
     * Returns an array of supported command routes
30
     * @return array
31
     */
32
    public function getRoutes()
33
    {
34
        $list = array();
35
36
        foreach (glob(__DIR__ . '/config/*.php') as $file) {
37
38
            $command = pathinfo($file, PATHINFO_FILENAME);
39
            $list[$command] = gplcart_config_get($file);
40
41
            $parts = explode('-', $command);
42
            $method = array_pop($parts);
43
            $class_name = implode('', $parts);
44
45
            $list[$command]['handlers']['controller'] = array(
46
                "gplcart\\modules\\cli\\controllers\\$class_name", "cmd$method$class_name");
47
        }
48
49
        return $list;
50
    }
51
52
}
53