| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 50 | public function testParseAndDump($file, $expectedDump) |
||
| 51 | { |
||
| 52 | $compiler = new Compiler(); |
||
| 53 | |||
| 54 | $fileParser = new FileParser( |
||
| 55 | (new ParserFactory())->create( |
||
| 56 | ParserFactory::PREFER_PHP7, |
||
| 57 | new \PhpParser\Lexer\Emulative( |
||
| 58 | array( |
||
| 59 | 'usedAttributes' => array( |
||
| 60 | 'comments', |
||
| 61 | 'startLine', |
||
| 62 | 'endLine', |
||
| 63 | 'startTokenPos', |
||
| 64 | 'endTokenPos' |
||
| 65 | ) |
||
| 66 | ) |
||
| 67 | ) |
||
| 68 | ), |
||
| 69 | $compiler |
||
| 70 | ); |
||
| 71 | |||
| 72 | $em = EventManager::getInstance(); |
||
| 73 | |||
| 74 | $bufferOutput = new \Symfony\Component\Console\Output\BufferedOutput(); |
||
| 75 | $context = new Context( |
||
| 76 | $bufferOutput, |
||
| 77 | $application = new Application(), |
||
| 78 | $em |
||
| 79 | ); |
||
| 80 | $application->compiler = $compiler; |
||
| 81 | |||
| 82 | $fileParser->parserFile($file, $context); |
||
| 83 | |||
| 84 | $em->listen(Compiler\Event\ExpressionBeforeCompile::EVENT_NAME) |
||
| 85 | ->handler( |
||
| 86 | new ExpressionListener( |
||
| 87 | [ |
||
| 88 | Node\Expr\FuncCall::class => [ |
||
| 89 | new AnalyzerPass\Expression\FunctionCall\AliasCheck(), |
||
| 90 | new AnalyzerPass\Expression\FunctionCall\DebugCode(), |
||
| 91 | new AnalyzerPass\Expression\FunctionCall\RandomApiMigration(), |
||
| 92 | new AnalyzerPass\Expression\FunctionCall\UseCast(), |
||
| 93 | new AnalyzerPass\Expression\FunctionCall\DeprecatedIniOptions(), |
||
| 94 | ], |
||
| 95 | Node\Expr\Array_::class => [ |
||
| 96 | new AnalyzerPass\Expression\ArrayShortDefinition() |
||
| 97 | ] |
||
| 98 | ] |
||
| 99 | ) |
||
| 100 | ) |
||
| 101 | ->method('beforeCompile'); |
||
| 102 | |||
| 103 | $em->listen(Compiler\Event\StatementBeforeCompile::EVENT_NAME) |
||
| 104 | ->handler( |
||
| 105 | new StatementListener( |
||
| 106 | [ |
||
| 107 | Node\Stmt\ClassMethod::class => [ |
||
| 108 | new AnalyzerPass\Statement\MethodCannotReturn() |
||
| 109 | ] |
||
| 110 | ] |
||
| 111 | ) |
||
| 112 | ) |
||
| 113 | ->method('beforeCompile'); |
||
| 114 | |||
| 115 | $compiler->compile($context); |
||
| 116 | |||
| 117 | self::assertSame( |
||
| 118 | json_encode($application->getIssuesCollector()->getIssues()), |
||
| 119 | trim($expectedDump) |
||
| 120 | ); |
||
| 121 | } |
||
| 122 | } |
||
| 123 |