| Conditions | 7 |
| Paths | 10 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 39 | public function load(ObjectManager $manager) : void |
||
| 40 | { |
||
| 41 | $i = 0; |
||
| 42 | while ($i < $this->amount()) { |
||
| 43 | $userId = $this->getRandomUserByIndex($i); |
||
| 44 | |||
| 45 | $this->queryBus()->handle( |
||
| 46 | new FilterProjectsQuery( |
||
| 47 | $userId, |
||
| 48 | 0, |
||
| 49 | 1 |
||
| 50 | ), |
||
| 51 | $projects |
||
| 52 | ); |
||
| 53 | |||
| 54 | foreach ($projects as $project) { |
||
| 55 | $this->queryBus()->handle( |
||
| 56 | new OrganizationOfIdQuery( |
||
| 57 | $project['organization_id'], |
||
| 58 | $userId |
||
| 59 | ), |
||
| 60 | $organization |
||
| 61 | ); |
||
| 62 | |||
| 63 | $parent = 40 === $i || 70 === $i ? $this->fakeIds()[10] : null; |
||
| 64 | |||
| 65 | $this->commandBus()->handle( |
||
| 66 | new CreateTaskCommand( |
||
| 67 | 'Task ' . $i, |
||
| 68 | 'The description of the task ' . $i, |
||
| 69 | $userId, |
||
| 70 | $organization['owners'][0]['id'], |
||
| 71 | $this->taskPriority($i), |
||
| 72 | $project['id'], |
||
| 73 | $parent, |
||
| 74 | $this->fakeIds()[$i] |
||
| 75 | ) |
||
| 76 | ); |
||
| 77 | |||
| 78 | if (130 === $i || 340 === $i) { |
||
| 79 | $this->commandBus()->handle( |
||
| 80 | new ChangeTaskProgressCommand( |
||
| 81 | $this->fakeIds()[$i], |
||
| 82 | 'doing', |
||
| 83 | $userId |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 88 | ++$i; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 100 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.