|
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\Graph; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Factory for Predicates on Nodes. |
|
15
|
|
|
*/ |
|
16
|
|
|
class PredicateFactory { |
|
17
|
|
|
/** |
|
18
|
|
|
* A predicate that is always true. |
|
19
|
|
|
* |
|
20
|
|
|
* @return Predicate |
|
21
|
|
|
*/ |
|
22
|
19 |
|
public function _true() { |
|
23
|
19 |
|
return new Predicate\_True(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* A predicate that is always false. |
|
28
|
|
|
* |
|
29
|
|
|
* @return Predicate |
|
30
|
|
|
*/ |
|
31
|
12 |
|
public function _false() { |
|
32
|
12 |
|
return new Predicate\_False(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Connect some predicates with AND. |
|
37
|
|
|
* |
|
38
|
|
|
* @param Predicate[] $predicates |
|
39
|
|
|
* @return Predicate |
|
40
|
|
|
*/ |
|
41
|
32 |
|
public function _and(array $predicates) { |
|
42
|
32 |
|
return new Predicate\_And($predicates); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Connect some predicates with OR. |
|
47
|
|
|
* |
|
48
|
|
|
* @param Predicate[] $predicates |
|
49
|
|
|
* @return Predicate |
|
50
|
|
|
*/ |
|
51
|
39 |
|
public function _or(array $predicates) { |
|
52
|
39 |
|
return new Predicate\_Or($predicates); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* A negated predicate. |
|
57
|
|
|
* |
|
58
|
|
|
* @param Predicate $predicate |
|
59
|
|
|
* @return Predicate |
|
60
|
|
|
*/ |
|
61
|
10 |
|
public function _not(Predicate $predicate) { |
|
62
|
10 |
|
return new Predicate\_Not($predicate); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Is true when the node has the given type. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $type |
|
69
|
|
|
* @return Predicate |
|
70
|
|
|
*/ |
|
71
|
41 |
|
public function _type_is($type) { |
|
72
|
41 |
|
return new Predicate\_TypeIs($type); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* A predicate about some property. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* @return PropertyPredicate |
|
80
|
|
|
*/ |
|
81
|
30 |
|
public function _property($name) { |
|
82
|
30 |
|
return new PropertyPredicateFactory($name); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* A custom predicate. |
|
87
|
|
|
* |
|
88
|
|
|
* @param \Closure $predicate Entity -> bool |
|
|
|
|
|
|
89
|
|
|
* @return Predicate |
|
90
|
|
|
*/ |
|
91
|
39 |
|
public function _custom(\Closure $closure) { |
|
92
|
39 |
|
return new Predicate\_Custom($closure); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.