Completed
Push — master ( 1f981d...cc2765 )
by Richard
06:42
created

Entities   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 4
Metric Value
wmc 4
c 6
b 0
f 4
lcom 1
cbo 2
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
id() 0 1 ?
A meaning() 0 3 1
A compile() 0 7 1
A eq_op() 0 8 2
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\Variables;
12
13
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
14
15
abstract class Entities extends Variable {
16
    /**
17
     * Get an id for the type of entity.
18
     *
19
     * This must return a string without whitespaces.
20
     *
21
     * @return  string
22
     */
23
    abstract public function id();
24
25
    /**
26
     * @inheritdocs
27
     */
28 122
    public function meaning() {
29 122
        return $this->id();
30
    }
31
32
    /**
33
     * @inheritdocs
34
     */
35 44
    public function compile(ExpressionBuilder $builder, $table_name, $negate = false) {
36 44
        return $this->eq_op
37 44
            ( $builder
38 44
            , "$table_name.type"
39 44
            , $builder->literal($this->id())
40 44
            , $negate);
41
    }
42
43 49
    protected function eq_op(ExpressionBuilder $builder, $l, $r, $negate) {
44 49
        if (!$negate) {
45 45
            return $builder->eq($l, $r);
46
        }
47
        else {
48 18
            return $builder->neq($l, $r);
49
        }
50
    }
51
}
52
53