|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Inspector\Application\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Inspector\Analysis\Analyzer; |
|
6
|
|
|
use Inspector\Analysis\Result\AnalysisResult; |
|
7
|
|
|
use Inspector\Filesystem\CodeScanner; |
|
8
|
|
|
use Inspector\Analysis\Feedback\FeedbackInterface; |
|
9
|
|
|
use Inspector\Foundation\AbstractService as Service; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Kabir Baidhya |
|
13
|
|
|
*/ |
|
14
|
|
|
class AnalyzerService extends Service |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Analyzer |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $analyzer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var CodeScanner |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $scanner; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var FeedbackInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $feedback; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var ReportService |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $reportService; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param Analyzer $analyzer |
|
39
|
|
|
* @param CodeScanner $scanner |
|
40
|
|
|
* @param FeedbackInterface $feedback |
|
41
|
|
|
* @param ReportService $reportService |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
Analyzer $analyzer, |
|
45
|
|
|
CodeScanner $scanner, |
|
46
|
|
|
FeedbackInterface $feedback, |
|
47
|
|
|
ReportService $reportService |
|
48
|
|
|
) { |
|
49
|
|
|
$this->analyzer = $analyzer; |
|
50
|
|
|
$this->scanner = $scanner; |
|
51
|
|
|
$this->feedback = $feedback; |
|
52
|
|
|
$this->reportService = $reportService; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $path |
|
57
|
|
|
* @param array $options |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function analyze($path, array $options) |
|
61
|
|
|
{ |
|
62
|
|
|
$path = realpath($path); |
|
63
|
|
|
$source = $this->scanner->scan($path); |
|
64
|
|
|
|
|
65
|
|
|
$rawResult = $this->analyzer->analyze($source, $options); |
|
66
|
|
|
$result = $this->process($rawResult); |
|
67
|
|
|
|
|
68
|
|
|
if ($options['generate-report'] === true) { |
|
69
|
|
|
$reportPath = $options['path']; |
|
70
|
|
|
$report = $this->reportService->generateReport(compact('result', 'path'), $reportPath); |
|
71
|
|
|
|
|
72
|
|
|
return sprintf('<info>Report generated to</info> %s ', $report['path']); |
|
73
|
|
|
} else { |
|
74
|
|
|
$feedback = $this->feedback->generate($result, [ |
|
75
|
|
|
'basePath' => $path |
|
76
|
|
|
]); |
|
77
|
|
|
|
|
78
|
|
|
return $feedback; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Process raw analysis raw result |
|
84
|
|
|
* |
|
85
|
|
|
* @param array $rawResult |
|
86
|
|
|
* @return AnalysisResult |
|
87
|
|
|
*/ |
|
88
|
|
|
public function process(array $rawResult) |
|
89
|
|
|
{ |
|
90
|
|
|
foreach ($rawResult as &$file) { |
|
|
|
|
|
|
91
|
|
|
// $file-> |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return new AnalysisResult($rawResult); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
This check looks for
foreachloops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.Consider removing the loop.