1 | <?php |
||
17 | class Analyzer implements AnalyzerInterface |
||
18 | { |
||
19 | /** |
||
20 | * cauditor JSON filename. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $json = 'cauditor.json'; |
||
25 | |||
26 | /** |
||
27 | * @var Config |
||
28 | */ |
||
29 | protected $config; |
||
30 | |||
31 | /** |
||
32 | * @param Config $config |
||
33 | */ |
||
34 | public function __construct(Config $config) |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function execute() |
||
43 | { |
||
44 | // all paths in build_path are relative to project root, which may not |
||
45 | // be where this code is run from, so prepend the project root! |
||
46 | $buildPath = $this->config['path'].DIRECTORY_SEPARATOR.$this->config['build_path']; |
||
47 | |||
48 | exec('mkdir -p '.$buildPath, $output, $result); |
||
49 | if ($result !== 0) { |
||
50 | throw new Exception('Unable to create build directory.'); |
||
51 | } |
||
52 | |||
53 | // let pdepend generate all metrics we'll need |
||
54 | set_error_handler(array($this, 'warningHandler'), E_WARNING); |
||
55 | $path = $buildPath.DIRECTORY_SEPARATOR.$this->json; |
||
56 | $this->pdepend($path); |
||
57 | restore_error_handler(); |
||
58 | |||
59 | // if we expect these json files to be loaded client-side to render |
||
60 | // the charts, might as well assume it'll fit in this machine's |
||
61 | // memory to submit it to our API ;) |
||
62 | $json = file_get_contents($path); |
||
63 | |||
64 | return json_decode($json, true); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Runs pdepend to generate the metrics. |
||
69 | * |
||
70 | * @param string $path |
||
71 | * |
||
72 | * @throws Exception |
||
73 | */ |
||
74 | protected function pdepend($path) |
||
98 | |||
99 | /** |
||
100 | * @param int $errno |
||
101 | * @param string $errstr |
||
102 | * @param string $errfile |
||
103 | * @param string $errline |
||
104 | * @param array $errcontext |
||
105 | * @throws Exception |
||
106 | */ |
||
107 | protected function warningHandler($errno, $errstr, $errfile, $errline, array $errcontext) { |
||
117 | } |
||
118 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.