| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 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 |
||
| 65 | public function testShouldReturnErrorIfThereIsFilesWithWrongStyle() |
||
| 66 | { |
||
| 67 | $kernel = $this->getMock(\StdClass::class); |
||
| 68 | |||
| 69 | /* @var \Behat\Gherkin\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */ |
||
| 70 | $parser = $this->getMockBuilder(Parser::class) |
||
| 71 | ->disableOriginalConstructor() |
||
| 72 | ->getMock(); |
||
| 73 | |||
| 74 | /* @var \Behat\Gherkin\Node\FeatureNode|\PHPUnit_Framework_MockObject_MockObject $feature */ |
||
| 75 | $feature = $this->getMockBuilder(FeatureNode::class) |
||
| 76 | ->disableOriginalConstructor() |
||
| 77 | ->getMock(); |
||
| 78 | |||
| 79 | $feature->expects($this->once()) |
||
|
1 ignored issue
–
show
|
|||
| 80 | ->method('hasTags') |
||
| 81 | ->willReturn(true); |
||
| 82 | |||
| 83 | $feature->expects($this->once()) |
||
| 84 | ->method('getTags') |
||
| 85 | ->willReturn( |
||
| 86 | ['users', 'another-feature', 'another-tag'] |
||
| 87 | ); |
||
| 88 | |||
| 89 | $feature->expects($this->once()) |
||
| 90 | ->method('getTitle') |
||
| 91 | ->willReturn( |
||
| 92 | 'User registration' |
||
| 93 | ); |
||
| 94 | |||
| 95 | $feature->expects($this->once()) |
||
| 96 | ->method('getDescription') |
||
| 97 | ->willReturn( |
||
| 98 | "In order to order products\n" . |
||
| 99 | "As a visitor\n" . |
||
| 100 | "I need to be able to create an account in the store" |
||
| 101 | ); |
||
| 102 | |||
| 103 | $feature->expects($this->once()) |
||
| 104 | ->method('hasBackground') |
||
| 105 | ->willReturn(true); |
||
| 106 | |||
| 107 | $feature->expects($this->once()) |
||
| 108 | ->method('getBackground') |
||
| 109 | ->willReturn($this->getBackground()); |
||
| 110 | |||
| 111 | $feature->expects($this->once()) |
||
| 112 | ->method('hasScenarios') |
||
| 113 | ->willReturn(false); |
||
| 114 | |||
| 115 | $parser->expects($this->once()) |
||
|
1 ignored issue
–
show
|
|||
| 116 | ->method('parse') |
||
| 117 | ->willReturn($feature); |
||
| 118 | |||
| 119 | $application = new Application($kernel); |
||
| 120 | $application->add(new CheckGherkinCodeStyle(null, $parser)); |
||
| 121 | |||
| 122 | $command = $application->find('kawaii:gherkin:check'); |
||
| 123 | $commandTester = new CommandTester($command); |
||
| 124 | $commandTester->execute( |
||
| 125 | [ |
||
| 126 | 'directory' => __DIR__ . '/../assets/', |
||
| 127 | ] |
||
| 128 | ); |
||
| 129 | |||
| 130 | $this->assertRegExp('/Wrong style/', $commandTester->getDisplay()); |
||
| 131 | $this->assertNotRegExp('/I need to be able to create an account in the store/', $commandTester->getDisplay()); |
||
| 132 | } |
||
| 133 | |||
| 162 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: