command   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 31
dl 0
loc 47
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A clean_argv() 0 7 2
B go() 0 31 10
1
<?php
2
3
/**
4
 * © 2018 - Phoponent
5
 * Author: Nicolas Choquet
6
 * Email: [email protected]
7
 * LICENSE GPL ( GNU General Public License )
8
 */
9
10
namespace phoponent\framework\static_classe;
11
12
use Exception;
13
use phoponent\framework\command\help;
14
use phoponent\framework\traits\static_class;
15
16
class command {
17
	use static_class;
18
19
	private static function clean_argv($argv) {
20
		unset($argv[0]);
21
		$argv_tmp = [];
22
		foreach ($argv as $item) {
23
			$argv_tmp[] = $item;
24
		}
25
		return $argv_tmp;
26
	}
27
28
	/**
29
	 * @param $argv
30
	 * @throws Exception
31
	 */
32
	public static function go($argv) {
33
		$argv = self::clean_argv($argv);
34
		if(empty($argv) || (!empty($argv) && $argv[0] === '-h') || (!empty($argv) && $argv[0] === '--help')) {
35
			$argv = self::clean_argv($argv);
36
			if(is_file("phoponent/commands/help.php")) {
37
				require_once "phoponent/commands/help.php";
38
			}
39
			else {
40
				throw new Exception("command help not found !");
41
			}
42
			$command = new help($argv);
43
			$command->execute();
44
			return;
45
		}
46
		$command = explode(':', $argv[0]);
47
		$command_class = $command[0];
48
		$command_method = isset($command[1]) ? $command[1] : null;
49
		$argv = self::clean_argv($argv);
50
		if(is_file("phoponent/commands/{$command_class}.php")) {
51
			require_once "phoponent/commands/{$command_class}.php";
52
		}
53
		else {
54
			throw new Exception("command {$command_class} not found !");
55
		}
56
		$command_class = "\\phoponent\\framework\\command\\{$command_class}";
57
		$command_obj = new $command_class($argv);
58
		if($command_method) {
59
            $command_obj->execute($command_method);
60
        }
61
        else {
62
            $command_obj->execute();
63
        }
64
	}
65
}