| Conditions | 4 |
| Paths | 6 |
| Total Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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, $analyzer, $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 | $context = new Context( |
||
| 73 | new \Symfony\Component\Console\Output\NullOutput(), |
||
| 74 | $application = new Application(), |
||
| 75 | $this->getEventManager($analyzer) |
||
| 76 | ); |
||
| 77 | $application->compiler = $compiler; |
||
| 78 | |||
| 79 | $fileParser->parserFile($file, $context); |
||
| 80 | |||
| 81 | $compiler->compile($context); |
||
| 82 | |||
| 83 | $expectedArray = json_decode($expectedDump, true); |
||
| 84 | $expectedType = $expectedArray[0]["type"]; |
||
| 85 | $issues = array_map( |
||
| 86 | // @todo Remove after moving all notices on Issue(s) |
||
| 87 | function (Issue $issue) { |
||
| 88 | $location = $issue->getLocation(); |
||
| 89 | |||
| 90 | return [ |
||
| 91 | 'type' => $issue->getCheckName(), |
||
| 92 | 'message' => $issue->getDescription(), |
||
| 93 | 'file' => $location->getFileName(), |
||
| 94 | 'line' => $location->getLineStart(), |
||
| 95 | ]; |
||
| 96 | }, |
||
| 97 | $application->getIssuesCollector()->getIssues() |
||
| 98 | ); |
||
| 99 | |||
| 100 | foreach ($expectedArray as $check) { |
||
| 101 | self::assertContains($check, $issues, $file); // every expected Issue is in the collector |
||
| 102 | } |
||
| 103 | |||
| 104 | foreach ($issues as $check) { |
||
| 105 | if ($check["type"] == $expectedType) { |
||
| 106 | self::assertContains($check, $expectedArray, $file); // there is no other issue in the collector with the same type |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 167 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.