|
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\Variables; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\DBAL\Query\Expression\ExpressionBuilder; |
|
14
|
|
|
|
|
15
|
|
|
class LanguageConstruct extends Entities { |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $construct_name; |
|
20
|
|
|
|
|
21
|
99 |
|
public function __construct($name, $construct_name) { |
|
22
|
99 |
|
parent::__construct($name); |
|
23
|
99 |
|
assert('is_string($construct_name)'); |
|
24
|
|
|
// TODO: Restrict the possible construct_names (like @, unset, echo, ...) |
|
|
|
|
|
|
25
|
99 |
|
$this->construct_name = $construct_name; |
|
26
|
99 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
8 |
|
public function construct_name() { |
|
32
|
8 |
|
return $this->construct_name; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function id() { |
|
39
|
1 |
|
return Variable::LANGUAGE_CONSTRUCT_TYPE; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @inheritdocs |
|
44
|
|
|
*/ |
|
45
|
7 |
|
public function compile(ExpressionBuilder $builder, $table_name, $negate = false) { |
|
46
|
7 |
|
$type_expr = $this->eq_op |
|
47
|
7 |
|
( $builder |
|
48
|
7 |
|
, "$table_name.type" |
|
49
|
7 |
|
, $builder->literal(Variable::LANGUAGE_CONSTRUCT_TYPE) |
|
50
|
7 |
|
, $negate |
|
51
|
7 |
|
); |
|
52
|
7 |
|
$name_expr = $this->eq_op |
|
53
|
7 |
|
( $builder |
|
54
|
7 |
|
, "$table_name.name" |
|
55
|
7 |
|
, $builder->literal($this->construct_name()) |
|
56
|
7 |
|
, $negate |
|
57
|
7 |
|
); |
|
58
|
|
|
|
|
59
|
|
|
// normal case : language construct and name matches |
|
60
|
7 |
|
if (!$negate) { |
|
61
|
7 |
|
return $builder->andX($type_expr, $name_expr); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
// negated case: not (language construct and name matches) |
|
64
|
|
|
// = not language construct or not name matches |
|
65
|
|
|
else { |
|
66
|
|
|
return $builder->orX($type_expr, $name_expr); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.