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

Entities::eq_op()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 4
crap 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