1212 * to [email protected] so I can send you a copy immediately. 1313 */
1414
15+ use Assert \Assertion ;
16+ use Assert \AssertionFailedException ;
17+
1518/**
1619 * Class MethodDocGenerator.
1720 */
@@ -30,50 +33,50 @@ public function generateChainDocs()
3033
3134 /**
3235 * @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
3639 *
3740 * @return array
3841 *
39- * @throws \Assert\ AssertionFailedException
42+ * @throws AssertionFailedException
4043 */
4144 private function generateMethodDocs ($ methods , $ format , $ skipParameterTest , $ prefix = '' )
4245 {
4346 $ lines = [];
44- \ asort ($ methods );
47+ asort ($ methods );
4548 foreach ($ methods as $ method ) {
4649 $ 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 ());
5053
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 ' ], '(){} ' ));
5356 }
5457
5558 $ parameters = [];
5659
5760 foreach ($ method ->getParameters () as $ parameterIndex => $ methodParameter ) {
5861 if (
59- (\ is_bool ($ skipParameterTest ) && $ skipParameterTest ) ||
60- (\ is_callable ($ skipParameterTest ) && $ skipParameterTest ($ methodParameter ))
62+ (is_bool ($ skipParameterTest ) && $ skipParameterTest ) ||
63+ (is_callable ($ skipParameterTest ) && $ skipParameterTest ($ methodParameter ))
6164 ) {
6265 continue ;
6366 }
6467
6568 $ parameter = '$ ' .$ methodParameter ->getName ();
6669
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 ;
6871
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 );
7174 if (isset ($ matches ['type ' ])) {
7275 $ type = (
7376 $ methodParameter ->isOptional () &&
7477 null == $ methodParameter ->getDefaultValue ()
7578 )
76- ? \ str_replace (['|null ' , 'null| ' ], '' , $ matches ['type ' ])
79+ ? str_replace (['|null ' , 'null| ' ], '' , $ matches ['type ' ])
7780 : $ matches ['type ' ];
7881 }
7982 }
@@ -82,21 +85,21 @@ private function generateMethodDocs($methods, $format, $skipParameterTest, $pref
8285 $ type .= '|null ' ;
8386 }
8487
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 );
8790
8891 if ($ methodParameter ->isOptional ()) {
8992 if (null === $ methodParameter ->getDefaultValue ()) {
9093 $ parameter .= ' = null ' ;
9194 } else {
92- $ parameter .= \ sprintf (' = \'%s \'' , $ methodParameter ->getDefaultValue ());
95+ $ parameter .= sprintf (' = \'%s \'' , $ methodParameter ->getDefaultValue ());
9396 }
9497 }
9598
9699 $ parameters [] = $ parameter ;
97100 }
98101
99- $ lines [] = \ sprintf ($ format , $ methodName , \ implode (', ' , $ parameters ), $ shortDescription );
102+ $ lines [] = sprintf ($ format , $ methodName , implode (', ' , $ parameters ), $ shortDescription );
100103 }
101104
102105 return $ lines ;
@@ -109,14 +112,14 @@ private function gatherAssertions()
109112 {
110113 $ reflClass = new ReflectionClass ('Assert\Assertion ' );
111114
112- return \ array_filter (
115+ return array_filter (
113116 $ reflClass ->getMethods (ReflectionMethod::IS_STATIC ),
114117 function (ReflectionMethod $ reflMethod ) {
115118 if ($ reflMethod ->isProtected ()) {
116119 return false ;
117120 }
118121
119- if (\ in_array ($ reflMethod ->getName (), ['__callStatic ' , 'createException ' , 'stringify ' ])) {
122+ if (in_array ($ reflMethod ->getName (), ['__callStatic ' , 'createException ' , 'stringify ' ])) {
120123 return false ;
121124 }
122125
@@ -126,33 +129,33 @@ function (ReflectionMethod $reflMethod) {
126129 }
127130
128131 /**
129- * @param string $phpFile
132+ * @param string $phpFile
130133 * @param string[] $lines
131- * @param string $fileType
134+ * @param string $fileType
132135 */
133136 private function generateFile ($ phpFile , $ lines , $ fileType )
134137 {
135- $ phpFile = \ realpath ($ phpFile );
136- $ fileContent = \ file_get_contents ($ phpFile );
138+ $ phpFile = realpath ($ phpFile );
139+ $ fileContent = file_get_contents ($ phpFile );
137140
138141 switch ($ fileType ) {
139142 case 'class ' :
140- $ fileContent = \ preg_replace (
143+ $ fileContent = preg_replace (
141144 '`\* @method.*? \*/\nclass `sim ' ,
142- \ sprintf ("%s \n */ \nclass " , \ trim (\ implode ("\n" , $ lines ))),
145+ sprintf ("%s \n */ \nclass " , trim (implode ("\n" , $ lines ))),
143146 $ fileContent
144147 );
145148 break ;
146149 case 'readme ' :
147- $ fileContent = \ preg_replace (
150+ $ fileContent = preg_replace (
148151 '/```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 )),
150153 $ fileContent
151154 );
152155 break ;
153156 }
154157
155- $ writtenBytes = \ file_put_contents ($ phpFile , $ fileContent );
158+ $ writtenBytes = file_put_contents ($ phpFile , $ fileContent );
156159
157160 if (false !== $ writtenBytes ) {
158161 echo 'Generated ' .$ phpFile .'. ' .PHP_EOL ;
@@ -166,7 +169,7 @@ public function generateAssertionDocs()
166169 return false ;
167170 };
168171
169- $ docs = \ array_merge (
172+ $ docs = array_merge (
170173 $ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method static bool %s(%s) %s for all values. ' , $ skipParameterTest , 'all ' ),
171174 $ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method static bool %s(%s) %s or that the value is null. ' , $ skipParameterTest , 'nullOr ' )
172175 );
@@ -178,7 +181,7 @@ public function generateReadMe()
178181 {
179182 $ mdFile = __DIR__ .'/../README.md ' ;
180183 $ skipParameterTest = function (ReflectionParameter $ parameter ) {
181- return \ in_array ($ parameter ->getName (), ['message ' , 'propertyPath ' , 'encoding ' ]);
184+ return in_array ($ parameter ->getName (), ['message ' , 'propertyPath ' , 'encoding ' ]);
182185 };
183186
184187 $ docs = $ this ->generateMethodDocs ($ this ->gatherAssertions (), 'Assertion::%s(%s); ' , $ skipParameterTest );
@@ -193,7 +196,7 @@ public function generateLazyAssertionDocs()
193196 return 0 === $ parameter ->getPosition ();
194197 };
195198
196- $ docs = \ array_merge (
199+ $ docs = array_merge (
197200 $ this ->generateMethodDocs ($ this ->gatherAssertions (), ' * @method $this %s(%s) %s. ' , $ skipParameterTest ),
198201 $ this ->generateMethodDocs ($ this ->gatherAssertionChainSwitches (), ' * @method $this %s(%s) %s. ' , false )
199202 );
@@ -208,14 +211,14 @@ private function gatherAssertionChainSwitches()
208211 {
209212 $ reflClass = new ReflectionClass ('Assert\AssertionChain ' );
210213
211- return \ array_filter (
214+ return array_filter (
212215 $ reflClass ->getMethods (ReflectionMethod::IS_PUBLIC ),
213216 function (ReflectionMethod $ reflMethod ) {
214217 if (!$ reflMethod ->isPublic ()) {
215218 return false ;
216219 }
217220
218- if (\ in_array ($ reflMethod ->getName (), ['__construct ' , '__call ' , 'setAssertionClassName ' ])) {
221+ if (in_array ($ reflMethod ->getName (), ['__construct ' , '__call ' , 'setAssertionClassName ' ])) {
219222 return false ;
220223 }
221224
0 commit comments