1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Richard Klees <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This software is licensed under The MIT License. You should have received |
8
|
|
|
* a copy of the license along with the code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\App; |
12
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Indexer\IndexerFactory; |
14
|
|
|
use Lechimp\Dicto\Analysis\AnalyzerFactory; |
15
|
|
|
use Doctrine\DBAL\DriverManager; |
16
|
|
|
use Psr\Log\LoggerInterface as Log; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The Engine of the App drives the analysis process. |
20
|
|
|
*/ |
21
|
|
|
class Engine { |
22
|
|
|
/** |
23
|
|
|
* @var Log |
24
|
|
|
*/ |
25
|
|
|
protected $log; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Config |
29
|
|
|
*/ |
30
|
|
|
protected $config; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var DBFactory |
34
|
|
|
*/ |
35
|
|
|
protected $db_factory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var IndexerFactory |
39
|
|
|
*/ |
40
|
|
|
protected $indexer_factory; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var AnalyzerFactory |
44
|
|
|
*/ |
45
|
|
|
protected $analyzer_factory; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var SourceStatus |
49
|
|
|
*/ |
50
|
|
|
protected $source_status; |
51
|
|
|
|
52
|
5 |
|
public function __construct( Log $log |
53
|
|
|
, Config $config |
54
|
|
|
, DBFactory $db_factory |
55
|
|
|
, IndexerFactory $indexer_factory |
56
|
|
|
, AnalyzerFactory $analyzer_factory |
57
|
|
|
, SourceStatus $source_status |
58
|
|
|
) { |
59
|
5 |
|
$this->log = $log; |
60
|
5 |
|
$this->config = $config; |
61
|
5 |
|
$this->db_factory = $db_factory; |
62
|
5 |
|
$this->indexer_factory = $indexer_factory; |
63
|
5 |
|
$this->analyzer_factory = $analyzer_factory; |
64
|
5 |
|
$this->source_status = $source_status; |
65
|
5 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Run the analysis. |
69
|
|
|
* |
70
|
|
|
* @return null |
71
|
|
|
*/ |
72
|
4 |
|
public function run() { |
73
|
4 |
|
$index_db_path = $this->index_database_path(); |
74
|
4 |
|
if (!$this->db_factory->index_db_exists($index_db_path)) { |
75
|
3 |
|
$index_db = $this->db_factory->build_index_db($index_db_path); |
76
|
3 |
|
$this->run_indexing($index_db); |
77
|
3 |
|
} |
78
|
|
|
else { |
79
|
1 |
|
$index_db = $this->db_factory->load_index_db($index_db_path); |
80
|
|
|
} |
81
|
4 |
|
$this->run_analysis($index_db); |
82
|
4 |
|
} |
83
|
|
|
|
84
|
4 |
|
protected function index_database_path() { |
85
|
4 |
|
$commit_hash = $this->source_status->commit_hash(); |
86
|
4 |
|
return $this->config->project_storage()."/$commit_hash.sqlite"; |
87
|
|
|
} |
88
|
|
|
|
89
|
4 |
|
protected function result_database_path() { |
90
|
4 |
|
return $this->config->project_storage()."/results.sqlite"; |
91
|
|
|
} |
92
|
|
|
|
93
|
3 |
|
protected function run_indexing($db) { |
94
|
3 |
|
$indexer = $this->indexer_factory->build($db); |
95
|
3 |
|
$indexer->index_directory |
96
|
3 |
|
( $this->config->project_root() |
97
|
3 |
|
, $this->config->analysis_ignore() |
98
|
3 |
|
); |
99
|
3 |
|
} |
100
|
|
|
|
101
|
4 |
|
protected function run_analysis($index_db) { |
102
|
4 |
|
$commit_hash = $this->source_status->commit_hash(); |
103
|
4 |
|
$result_db = $this->db_factory->get_result_db($this->result_database_path()); |
104
|
4 |
|
$result_db->begin_new_run($commit_hash); |
105
|
4 |
|
$analyzer = $this->analyzer_factory->build($index_db, $result_db); |
106
|
4 |
|
$analyzer->run(); |
107
|
4 |
|
} |
108
|
|
|
} |
109
|
|
|
|