|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016, 2015 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\Definition\AST; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Factory for AST nodes. |
|
15
|
|
|
*/ |
|
16
|
|
|
class Factory extends Node { |
|
17
|
|
|
/** |
|
18
|
|
|
* @param Line[] $lines |
|
19
|
|
|
* @return Root |
|
20
|
|
|
*/ |
|
21
|
|
|
public function root(array $lines) { |
|
22
|
|
|
return new Root($lines); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $content |
|
27
|
|
|
* @return Explanation |
|
28
|
|
|
*/ |
|
29
|
|
|
public function explanation($content) { |
|
30
|
|
|
return new Explanation($content); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $name |
|
35
|
|
|
* @return Name |
|
36
|
|
|
*/ |
|
37
|
|
|
public function name($name) { |
|
38
|
|
|
return new Name($name); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $atom |
|
43
|
|
|
* @return Name |
|
44
|
|
|
*/ |
|
45
|
|
|
public function atom($atom) { |
|
46
|
|
|
return new Atom($atom); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $string |
|
51
|
|
|
* @return StringValue |
|
52
|
|
|
*/ |
|
53
|
|
|
public function string_value($string) { |
|
54
|
|
|
return new StringValue($string); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param Definition $left |
|
59
|
|
|
* @param Atom $id |
|
60
|
|
|
* @param Parameter[] $parameters |
|
61
|
|
|
* @return Property |
|
62
|
|
|
*/ |
|
63
|
|
|
public function property(Definition $left, Atom $id, array $parameters) { |
|
64
|
|
|
return new Property($left, $id, $parameters); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param Definition $left |
|
69
|
|
|
* @param Definition $right |
|
70
|
|
|
* @return Except |
|
71
|
|
|
*/ |
|
72
|
|
|
public function except(Definition $left, Definition $right) { |
|
73
|
|
|
return new Except($left, $right); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param Definition[] $definitions |
|
78
|
|
|
* @return Any |
|
79
|
|
|
* @return Any |
|
80
|
|
|
*/ |
|
81
|
|
|
public function any(array $definitions) { |
|
82
|
|
|
return new Any($definitions); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Name $name |
|
87
|
|
|
* @param Definition $definition |
|
88
|
|
|
* @return Assignment |
|
89
|
|
|
*/ |
|
90
|
|
|
public function assignment(Name $name, Definition $definition) { |
|
91
|
|
|
return new Assignment($name, $definition); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return Qualifier |
|
96
|
|
|
*/ |
|
97
|
|
|
public function must() { |
|
98
|
|
|
return new Qualifier(Qualifier::MUST); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return Qualifier |
|
103
|
|
|
*/ |
|
104
|
|
|
public function cannot() { |
|
105
|
|
|
return new Qualifier(Qualifier::CANNOT); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return Qualifier |
|
110
|
|
|
*/ |
|
111
|
|
|
public function only_X_can() { |
|
112
|
|
|
return new Qualifier(Qualifier::ONLY_X_CAN); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param Definition $left |
|
|
|
|
|
|
117
|
|
|
* @param Qualifier $qualifier |
|
118
|
|
|
* @param Atom $id |
|
|
|
|
|
|
119
|
|
|
* @param Parameter[] $parameters |
|
|
|
|
|
|
120
|
|
|
* @return Property |
|
121
|
|
|
*/ |
|
122
|
|
|
public function rule(Qualifier $qualifier, Definition $definition) { |
|
123
|
|
|
return new Rule($qualifier, $definition); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
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.