| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 26 |
| 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 |
||
| 79 | public function testCommand() |
||
| 80 | { |
||
| 81 | $this->task1->shouldReceive('getDescription')->andReturn('A first description.'); |
||
| 82 | $this->task1->shouldReceive('getParameterDefinition')->andReturn( |
||
| 83 | [ |
||
| 84 | ['name' => 'option1', 'default' => null, 'description' => '', 'required' => false], |
||
| 85 | [ |
||
| 86 | 'name' => 'option2', |
||
| 87 | 'default' => 'bldr!', |
||
| 88 | 'description' => 'Option 2 description', |
||
| 89 | 'required' => true |
||
| 90 | ], |
||
| 91 | ['name' => 'option3', 'default' => true, 'description' => '', 'required' => false], |
||
| 92 | ] |
||
| 93 | ); |
||
| 94 | |||
| 95 | $this->task2->shouldReceive('getDescription')->andReturnNull(); |
||
| 96 | |||
| 97 | $application = new MockApplication(); |
||
| 98 | $application->add($this->command); |
||
| 99 | |||
| 100 | $tester = new CommandTester($application->find('task:info')); |
||
| 101 | $tester->execute(['task' => 'Name 1']); |
||
| 102 | |||
| 103 | $this->assertEquals( |
||
| 104 | <<<EOO |
||
| 105 | |||
| 106 | Task Name: Name 1 |
||
| 107 | Task Description: A first description. |
||
| 108 | |||
| 109 | Options: |
||
| 110 | +---------+----------------------+----------+---------+ |
||
| 111 | | Option | Description | Required | Default | |
||
| 112 | +---------+----------------------+----------+---------+ |
||
| 113 | | option1 | No Description | No | null | |
||
| 114 | | option2 | Option 2 description | Yes | "bldr!" | |
||
| 115 | | option3 | No Description | No | true | |
||
| 116 | +---------+----------------------+----------+---------+ |
||
| 117 | |||
| 118 | EOO |
||
| 119 | , |
||
| 120 | $tester->getDisplay() |
||
| 121 | ); |
||
| 122 | |||
| 123 | $tester = new CommandTester($application->find('task:info')); |
||
| 124 | $tester->execute(['task' => 'Name 2']); |
||
| 125 | |||
| 126 | $this->assertEquals( |
||
| 127 | <<<EOO |
||
| 128 | |||
| 129 | Task Name: Name 2 |
||
| 130 | |||
| 131 | EOO |
||
| 132 | , |
||
| 133 | $tester->getDisplay() |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | } |
||
| 137 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: