12
12
* to kontakt@beberlei.de so I can send you a copy immediately.
13
13
*/
14
14
15
+ use Assert \Assertion ;
16
+ use Assert \AssertionFailedException ;
17
+
15
18
/**
16
19
* Class MethodDocGenerator.
17
20
*/
@@ -30,50 +33,50 @@ public function generateChainDocs()
30
33
31
34
/**
32
35
* @param ReflectionMethod[] $methods
33
- * @param string $format
34
- * @param callable|false $skipParameterTest
35
- * @param string $prefix
36
+ * @param string $format
37
+ * @param callable|false $skipParameterTest
38
+ * @param string $prefix
36
39
*
37
40
* @return array
38
41
*
39
- * @throws \Assert\ AssertionFailedException
42
+ * @throws AssertionFailedException
40
43
*/
41
44
private function generateMethodDocs ($ methods , $ format , $ skipParameterTest , $ prefix = '' )
42
45
{
43
46
$ lines = [];
44
- \ asort ($ methods );
47
+ asort ($ methods );
45
48
foreach ($ methods as $ method ) {
46
49
$ doc = $ method ->getDocComment ();
47
- list (, $ descriptionLine ) = \ explode ("\n" , $ doc );
48
- $ shortDescription = \ trim (\ substr ($ descriptionLine , 7 ), '. ' );
49
- $ methodName = $ prefix .($ prefix ? \ ucfirst ($ method ->getName ()) : $ method ->getName ());
50
+ list (, $ descriptionLine ) = explode ("\n" , $ doc );
51
+ $ shortDescription = trim (substr ($ descriptionLine , 7 ), '. ' );
52
+ $ methodName = $ prefix .($ prefix ? ucfirst ($ method ->getName ()) : $ method ->getName ());
50
53
51
- if (\ preg_match ('`\* This is an alias of {@see (?P<aliasOf>[^\s\}]++)`sim ' , $ doc , $ aliasMatch )) {
52
- $ shortDescription .= \ sprintf ('. This is an alias of Assertion::%s() ' , \ trim ($ aliasMatch ['aliasOf ' ], '(){} ' ));
54
+ if (preg_match ('`\* This is an alias of {@see (?P<aliasOf>[^\s\}]++)`sim ' , $ doc , $ aliasMatch )) {
55
+ $ shortDescription .= sprintf ('. This is an alias of Assertion::%s() ' , trim ($ aliasMatch ['aliasOf ' ], '(){} ' ));
53
56
}
54
57
55
58
$ parameters = [];
56
59
57
60
foreach ($ method ->getParameters () as $ parameterIndex => $ methodParameter ) {
58
61
if (
59
- (\ is_bool ($ skipParameterTest ) && $ skipParameterTest ) ||
60
- (\ is_callable ($ skipParameterTest ) && $ skipParameterTest ($ methodParameter ))
62
+ (is_bool ($ skipParameterTest ) && $ skipParameterTest ) ||
63
+ (is_callable ($ skipParameterTest ) && $ skipParameterTest ($ methodParameter ))
61
64
) {
62
65
continue ;
63
66
}
64
67
65
68
$ parameter = '$ ' .$ methodParameter ->getName ();
66
69
67
- $ type = \ version_compare (PHP_VERSION , '7.0.0 ' ) >= 0 ? $ methodParameter ->getType () : null ;
70
+ $ type = version_compare (PHP_VERSION , '7.0.0 ' ) >= 0 ? $ methodParameter ->getType () : null ;
68
71
69
- if (\ is_null ($ type )) {
70
- \ preg_match (\ sprintf ('`\* @param (?P<type>[^ ]++) +\%s\b`sim ' , $ parameter ), $ doc , $ matches );
72
+ if (is_null ($ type )) {
73
+ preg_match (sprintf ('`\* @param (?P<type>[^ ]++) +\%s\b`sim ' , $ parameter ), $ doc , $ matches );
71
74
if (isset ($ matches ['type ' ])) {
72
75
$ type = (
73
76
$ methodParameter ->isOptional () &&
74
77
null == $ methodParameter ->getDefaultValue ()
75
78
)
76
- ? \ str_replace (['|null ' , 'null| ' ], '' , $ matches ['type ' ])
79
+ ? str_replace (['|null ' , 'null| ' ], '' , $ matches ['type ' ])
77
80
: $ matches ['type ' ];
78
81
}
79
82
}
@@ -82,21 +85,21 @@ private function generateMethodDocs($methods, $format, $skipParameterTest, $pref
82
85
$ type .= '|null ' ;
83
86
}
84
87
85
- \ Assert \ Assertion::notEmpty ($ type , \ sprintf ('No type defined for %s in %s ' , $ parameter , $ methodName ));
86
- $ parameter = \ sprintf ('%s %s ' , $ type , $ parameter );
88
+ Assertion::notEmpty ($ type , sprintf ('No type defined for %s in %s ' , $ parameter , $ methodName ));
89
+ $ parameter = sprintf ('%s %s ' , $ type , $ parameter );
87
90
88
91
if ($ methodParameter ->isOptional ()) {
89
92
if (null === $ methodParameter ->getDefaultValue ()) {
90
93
$ parameter .= ' = null ' ;
91
94
} else {
92
- $ parameter .= \ sprintf (' = \'%s \'' , $ methodParameter ->getDefaultValue ());
95
+ $ parameter .= sprintf (' = \'%s \'' , $ methodParameter ->getDefaultValue ());
93
96
}
94
97
}
95
98
96
99
$ parameters [] = $ parameter ;
97
100
}
98
101
99
- $ lines [] = \ sprintf ($ format , $ methodName , \ implode (', ' , $ parameters ), $ shortDescription );
102
+ $ lines [] = sprintf ($ format , $ methodName , implode (', ' , $ parameters ), $ shortDescription );
100
103
}
101
104
102
105
return $ lines ;
@@ -109,14 +112,14 @@ private function gatherAssertions()
109
112
{
110
113
$ reflClass = new ReflectionClass ('Assert\Assertion ' );
111
114
112
- return \ array_filter (
115
+ return array_filter (
113
116
$ reflClass ->getMethods (ReflectionMethod::IS_STATIC ),
114
117
function (ReflectionMethod $ reflMethod ) {
115
118
if ($ reflMethod ->isProtected ()) {
116
119
return false ;
117
120
}
118
121
119
- if (\ in_array ($ reflMethod ->getName (), ['__callStatic ' , 'createException ' , 'stringify ' ])) {
122
+ if (in_array ($ reflMethod ->getName (), ['__callStatic ' , 'createException ' , 'stringify ' ])) {
120
123
return false ;
121
124
}
122
125
@@ -126,33 +129,33 @@ function (ReflectionMethod $reflMethod) {
126
129
}
127
130
128
131
/**
129
- * @param string $phpFile
132
+ * @param string $phpFile
130
133
* @param string[] $lines
131
- * @param string $fileType
134
+ * @param string $fileType
132
135
*/
133
136
private function generateFile ($ phpFile , $ lines , $ fileType )
134
137
{
135
- $ phpFile = \ realpath ($ phpFile );
136
- $ fileContent = \ file_get_contents ($ phpFile );
138
+ $ phpFile = realpath ($ phpFile );
139
+ $ fileContent = file_get_contents ($ phpFile );
137
140
138
141
switch ($ fileType ) {
139
142
case 'class ' :
140
- $ fileContent = \ preg_replace (
143
+ $ fileContent = preg_replace (
141
144
'`\* @method.*? \*/\nclass `sim ' ,
142
- \ sprintf ("%s \n */ \nclass " , \ trim (\ implode ("\n" , $ lines ))),
145
+ sprintf ("%s \n */ \nclass " , trim (implode ("\n" , $ lines ))),
143
146
$ fileContent
144
147
);
145
148
break ;
146
149
case 'readme ' :
147
- $ fileContent = \ preg_replace (
150
+ $ fileContent = preg_replace (
148
151
'/```php\n<\?php\nuse Assert \\\Assertion;\n\nAssertion::.*?```/sim ' ,
149
- \ sprintf ("```php \n<?php \nuse Assert \\Assertion; \n\n%s \n\n``` " , \ implode ("\n" , $ lines )),
152
+ sprintf ("```php \n<?php \nuse Assert \\Assertion; \n\n%s \n\n``` " , implode ("\n" , $ lines )),
150
153
$ fileContent
151
154
);
152
155
break ;
153
156
}
154
157
155
- $ writtenBytes = \ file_put_contents ($ phpFile , $ fileContent );
158
+ $ writtenBytes = file_put_contents ($ phpFile , $ fileContent );
156
159
157
160
if (false !== $ writtenBytes ) {
158
161
echo 'Generated ' .$ phpFile .'. ' .PHP_EOL ;
@@ -166,7 +169,7 @@ public function generateAssertionDocs()
166
169
return false ;
167
170
};
168
171
169
- $ docs = \ array_merge (
172
+ $ docs = array_merge (
170
173
$ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method static bool %s(%s) %s for all values. ' , $ skipParameterTest , 'all ' ),
171
174
$ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method static bool %s(%s) %s or that the value is null. ' , $ skipParameterTest , 'nullOr ' )
172
175
);
@@ -178,7 +181,7 @@ public function generateReadMe()
178
181
{
179
182
$ mdFile = __DIR__ .'/../README.md ' ;
180
183
$ skipParameterTest = function (ReflectionParameter $ parameter ) {
181
- return \ in_array ($ parameter ->getName (), ['message ' , 'propertyPath ' , 'encoding ' ]);
184
+ return in_array ($ parameter ->getName (), ['message ' , 'propertyPath ' , 'encoding ' ]);
182
185
};
183
186
184
187
$ docs = $ this ->generateMethodDocs ($ this ->gatherAssertions (), 'Assertion::%s(%s); ' , $ skipParameterTest );
@@ -193,7 +196,7 @@ public function generateLazyAssertionDocs()
193
196
return 0 === $ parameter ->getPosition ();
194
197
};
195
198
196
- $ docs = \ array_merge (
199
+ $ docs = array_merge (
197
200
$ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method $this %s(%s) %s. ' , $ skipParameterTest ),
198
201
$ this ->generateMethodDocs ($ this ->gatherAssertionChainSwitches (), ' * @method $this %s(%s) %s. ' , false )
199
202
);
@@ -208,14 +211,14 @@ private function gatherAssertionChainSwitches()
208
211
{
209
212
$ reflClass = new ReflectionClass ('Assert\AssertionChain ' );
210
213
211
- return \ array_filter (
214
+ return array_filter (
212
215
$ reflClass ->getMethods (ReflectionMethod::IS_PUBLIC ),
213
216
function (ReflectionMethod $ reflMethod ) {
214
217
if (!$ reflMethod ->isPublic ()) {
215
218
return false ;
216
219
}
217
220
218
- if (\ in_array ($ reflMethod ->getName (), ['__construct ' , '__call ' , 'setAssertionClassName ' ])) {
221
+ if (in_array ($ reflMethod ->getName (), ['__construct ' , '__call ' , 'setAssertionClassName ' ])) {
219
222
return false ;
220
223
}
221
224
0 commit comments