DotShell   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 71
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A main() 0 3 1
A _generatePng() 0 8 2
B generate() 0 35 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 */
4
5
App::uses('String', 'Utility');
6
7
/**
8
 * Dot Shell Class
9
 *
10
 * Simple dot generation of PNG files from state-machine
11
 */
12
class DotShell extends Shell {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
14
	public $Model;
15
16
/**
17
 * DotShell::main()
18
 *
19
 * @return void
20
 */
21
	public function main() {
22
		$this->out('Hello world.');
23
	}
24
25
/**
26
 * This function generates a png file from a given dot. A dot can be generated wit *toDot functions
27
 *
28
 * @param string $dot The contents for graphviz
29
 * @param string $destFile Name with full path to where file is to be created
30
 * @return bool|string Returns whatever shell_exec returns
31
 */
32
	protected function _generatePng($dot, $destFile) {
33
		if (!isset($dot)) {
34
			return false;
35
		}
36
		$dotExec = "echo '%s' | dot -Tpng -o%s";
37
		$command = sprintf($dotExec, $dot, $destFile);
38
		return shell_exec($command);
39
	}
40
41
/**
42
 * DotShell::generate()
43
 *
44
 * @return void
45
 */
46
	public function generate() {
47
		$this->out('Generate files');
48
		switch ($this->args[1]) {
49
			case 'all':
50
				$this->out('Load Model:' . $this->args[0]);
51
				$this->loadModel($this->args[0]);
52
				$this->Model = new $this->args[0](1);
53
54
				$rolesForPopping = $this->Model->roles;
55
				$timesToPop = count($rolesForPopping);
56
				do {
57
					$dot = $this->Model->createDotFileForRoles($rolesForPopping, array(
58
						'color' => 'lightgrey',
59
						'activeColor' => 'green'
60
					));
61
					$this->_generatePng($dot, TMP . implode('_', $this->Model->getAllRoles($rolesForPopping)) . '_' . $this->args[2]);
62
					array_pop($rolesForPopping);
63
					$timesToPop--;
64
				} while ($timesToPop > 0);
65
66
				foreach ($this->Model->roles as $role => $options) {
67
					$dot = $this->Model->createDotFileForRoles(array($role => $this->Model->roles[$role]), array(
68
						'color' => 'lightgrey',
69
						'activeColor' => 'green'
70
					));
71
					$this->_generatePng($dot, TMP . $role . '_' . $this->args[2]);
72
				}
73
				# code...
74
				break;
75
76
			default:
77
				# code...
78
				break;
79
		}
80
	}
81
82
}
83
84