Completed
Push — master ( cc2765...340ff8 )
by Richard
08:19
created

Entities   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
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 91
    public function __construct($name= null) {
17 91
        if ($name === null) {
18 25
            $name = ucfirst($this->id());
19 25
        }
20 91
        parent::__construct($name);
21 91
    }
22
23
    /**
24
     * Get an id for the type of entity.
25
     *
26
     * This must return a string without whitespaces.
27
     *
28
     * @return  string
29
     */
30
    abstract public function id();
31
32
    /**
33
     * @inheritdocs
34
     */
35 124
    public function meaning() {
36 124
        return $this->id();
37
    }
38
39
    /**
40
     * @inheritdocs
41
     */
42 44
    public function compile(ExpressionBuilder $builder, $table_name, $negate = false) {
43 44
        return $this->eq_op
44 44
            ( $builder
45 44
            , "$table_name.type"
46 44
            , $builder->literal($this->id())
47 44
            , $negate);
48
    }
49
50 49
    protected function eq_op(ExpressionBuilder $builder, $l, $r, $negate) {
51 49
        if (!$negate) {
52 45
            return $builder->eq($l, $r);
53
        }
54
        else {
55 18
            return $builder->neq($l, $r);
56
        }
57
    }
58
}
59
60