Completed
Push — master ( 4a7f1b...1a5eaf )
by Richard
05:32
created

Schema::fluid_interface()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 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 licence along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Rules;
12
13
use Lechimp\Dicto\Definition as Def;
14
use Lechimp\Dicto\Variables as Vars;
15
use Lechimp\Dicto\Indexer\ListenerRegistry;
16
use Lechimp\Dicto\Analysis\Query;
17
use Lechimp\Dicto\Analysis\Violation;
18
use Lechimp\Dicto\Variables\Variable;
19
use Doctrine\DBAL\Driver\Statement;
20
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
21
22
/**
23
 * This is what every rule needs to define.
24
 */
25
abstract class Schema {
26
    /**
27
     * Get the name of the relation.
28
     *
29
     * This must return a string without whitespaces.
30
     *
31
     * @return  string
32
     */
33
    abstract public function name(); 
34
35
    /**
36
     * Get the name where _ is replace by space.
37
     *
38
     * @return string
39
     */
40 4
    public function printable_name() {
41 4
        return str_replace("_", " ", $this->name());
42
    }
43
44
    /**
45
     * Get the Fluid interface that should be returned on using the
46
     * schema.
47
     *
48
     * @param   Def\RT    $rt
49
     * @param   string                  $name
50
     * @param   string                  $mode
51
     * @param   array                   $arguments
52
     * @return  Def\Fluid\Base|null
53
     */
54
    abstract public function fluid_interface(Def\RT $rt, $name, $mode, array $arguments);
55
56
    /**
57
     * Check the arguments given in the fluid interface on using the schema.
58
     *
59
     * @param   array   $arguments
60
     * @throws  \InvalidArgumentException   if $arguments are not ok
61
     * @return  null
62
     */
63
    abstract public function check_arguments(array $arguments);
64
65
    /**
66
     * Get a pretty printed version of the rules.
67
     *
68
     * @param   Rule    $rule
69
     * @return  string
70
     */
71
    abstract public function pprint(Rule $rule);
72
73
    /**
74
     * Compile a given rule into an sql statement using a query interface.
75
     *
76
     * @param   Query       $query
77
     * @param   Rule        $rule
78
     * @return  Statement
79
     */
80
    abstract public function compile(Query $query, Rule $rule);
81
82
    /**
83
     * Turn a query result into a violation. Could be used 
84
     *
85
     * @param   Rule    $rule
86
     * @param   array   $row
87
     * @return  Violation
88
     */
89 2
    public function to_violation(Rule $rule, array $row) {
90
        return new Violation
91 2
            ( $rule
92 2
            , $row["file"]
93 2
            , (int)$row["line"]
94 2
            , $row["source"]
95 2
            );
96
    }
97
98
    /**
99
     * Register listeners to the indexer that are required to detect information
100
     * for the rule.
101
     *
102
     * @param   ListenerRegistry $registry
103
     * @return  null
104
     */
105
    abstract public function register_listeners(ListenerRegistry $registry);
106
}
107