CommandLineRunner   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 61
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A autoload() 0 7 2
A run() 0 15 4
A getTargets() 0 4 1
A preload() 0 8 2
1
<?php
2
3
/**
4
* @package   s9e\SourceOptimizer
5
* @copyright Copyright (c) 2014-2018 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\SourceOptimizer;
9
10
class CommandLineRunner
11
{
12
	/**
13
	* Ensure that all the required files are loaded
14
	*
15
	* @return void
16
	*/
17
	public static function autoload()
18
	{
19
		if (!class_exists(__NAMESPACE__ . '\\Optimizer'))
20
		{
21
			self::preload(__DIR__);
22
		}
23
	}
24
25
	/**
26
	* Run the command-line program
27
	*
28
	* @return void
29
	*/
30
	public static function run()
31
	{
32
		self::autoload();
33
		$optimizer = new Optimizer;
34
		foreach (self::getTargets() as $path)
35
		{
36
			if (!file_exists($path))
37
			{
38
				echo "$path not found\n";
39
				continue;
40
			}
41
			$methodName = (is_dir($path)) ? 'optimizeDir' : 'optimizeFile';
42
			$optimizer->$methodName($path);
43
		}
44
	}
45
46
	/**
47
	* Get the list of targets from command-line
48
	*
49
	* @return string[]
50
	*/
51
	protected static function getTargets()
52
	{
53
		return array_slice($_SERVER['argv'], 1);
54
	}
55
56
	/**
57
	* Preload all PHP files from given dir
58
	*
59
	* @param  string $dir Path to the dir
60
	* @return void
61
	*/
62
	protected static function preload($dir)
63
	{
64
		foreach (glob($dir . '/[A-Z]*.php') as $path)
65
		{
66
			include_once $path;
67
		}
68
		array_map(__METHOD__, glob($dir . '/*', GLOB_ONLYDIR));
69
	}
70
}