Completed
Push — master ( a94ac3...322d21 )
by Richard
05:34
created

Analyzer::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 5
Bugs 0 Features 2
Metric Value
c 5
b 0
f 2
dl 0
loc 13
ccs 13
cts 13
cp 1
rs 9.4285
cc 3
eloc 10
nc 3
nop 0
crap 3
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 *
5
 * Copyright (c) 2016, 2015 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received
8
 * a copy of the licence along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Analysis;
12
13
use Lechimp\Dicto\Rules\Ruleset;
14
use Lechimp\Dicto\Variables\Variable;
15
use Psr\Log\LoggerInterface as Log;
16
17
/**
18
 * Performs the actual analysis of a ruleset over a query-object
19
 * using a specific rules to sql compiler.
20
 */
21
class Analyzer {
22
    /**
23
     * @var Log
24
     */
25
    protected $log;
26
27
    /**
28
     * @var Ruleset
29
     */
30
    protected $ruleset;
31
32
    /**
33
     * @var Query
34
     */
35
    protected $query;
36
37
    /**
38
     * @var ReportGenerator
39
     */
40
    protected $generator;
41
42 3
    public function __construct
43
                        ( Log $log
44
                        , Ruleset $ruleset
45
                        , Query $query
46
                        , ReportGenerator $generator
47
                        ) {
48 3
        $this->log = $log;
49 3
        $this->ruleset = $ruleset;
50 3
        $this->query = $query;
51 3
        $this->generator = $generator;
52 3
    }
53
54
    /**
55
     * Run the analysis.
56
     *
57
     * @return  null
58
     */
59 3
    public function run() {
60 3
        $this->generator->begin_ruleset($this->ruleset);
61 3
        foreach ($this->ruleset->rules() as $rule) {
62 3
            $this->log->info("checking: ".$rule->pprint());
63 3
            $this->generator->begin_rule($rule);
64 3
            $stmt = $rule->compile($this->query);
65 3
            while ($row = $stmt->fetch()) {
66 2
                $this->generator->report_violation($rule->to_violation($row));
67 2
            }
68 3
            $this->generator->end_rule($rule);
69 3
        }
70 3
        $this->generator->end_ruleset($this->ruleset);
71 3
    }
72
} 
73