Completed
Push — master ( dca6dc...178b4a )
by Richard
06:29
created

Engine::run_indexing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 7
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
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 5
    public function __construct(Log $log, Config $config, DBFactory $db_factory, IndexerFactory $indexer_factory, AnalyzerFactory $analyzer_factory) {
48 5
        $this->log = $log;
49 5
        $this->config = $config;
50 5
        $this->db_factory = $db_factory;
51 5
        $this->indexer_factory = $indexer_factory;
52 5
        $this->analyzer_factory = $analyzer_factory;
53 5
    }
54
55
    /**
56
     * Run the analysis.
57
     * 
58
     * @return null
59
     */
60 4
    public function run() {
61 4
        $path = $this->database_path();
62 4
        if (!$this->db_factory->index_db_exists($path)) {
63 3
            $db = $this->db_factory->build_index_db($path);
64 3
            $this->run_indexing($db);
65 3
        }
66
        else {
67 1
            $db = $this->db_factory->load_index_db($path);
68
        }
69 4
        $this->run_analysis($db);
70 4
    }
71
72 4
    protected function database_path() {
73 4
        return $this->config->project_storage()."/index.sqlite";
74
    }
75
76 3
    protected function run_indexing($db) {
77 3
        $indexer = $this->indexer_factory->build($db);
78 3
        $indexer->index_directory
79 3
            ( $this->config->project_root()
80 3
            , $this->config->analysis_ignore()
81 3
            );
82 3
    }
83
84 4
    protected function run_analysis($db) {
85 4
        $analyzer = $this->analyzer_factory->build($db);
86 4
        $analyzer->run();
87 4
    }
88
}
89