| Conditions | 4 |
| Paths | 3 |
| Total Lines | 53 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 96 | public function testValid(array $input, array $pollData): void { |
||
| 97 | $expectedShareCount = count($pollData['expectedShares']['user']) |
||
| 98 | + count($pollData['expectedShares']['group']) |
||
| 99 | + count($pollData['expectedShares']['email']); |
||
| 100 | $expectedInvitationCount = count($pollData['expectedInvitations']['user']) |
||
| 101 | + count($pollData['expectedInvitations']['group']) |
||
| 102 | + count($pollData['expectedInvitations']['email']); |
||
| 103 | |||
| 104 | $expectedInvitationShareTokens = []; |
||
| 105 | foreach ($pollData['expectedInvitations'] as $type => $shares) { |
||
| 106 | foreach ($shares as $userId) { |
||
| 107 | $expectedInvitationShareTokens[] = $this->getShareToken($pollData['pollId'], $type, $userId); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->pollMapper |
||
| 112 | ->expects($this->once()) |
||
| 113 | ->method('find') |
||
| 114 | ->with($pollData['pollId']) |
||
| 115 | ->willReturnCallback([$this, 'createPollMock']); |
||
| 116 | |||
| 117 | $this->shareService |
||
| 118 | ->expects($this->exactly($expectedShareCount)) |
||
| 119 | ->method('add') |
||
| 120 | ->with($pollData['pollId'], $this->logicalOr(User::TYPE, Group::TYPE, Email::TYPE), $this->anything()) |
||
| 121 | ->willReturnCallback(function (int $pollId, string $type, string $userId = '') use ($pollData): Share { |
||
| 122 | $userIdConstraint = $this->logicalOr(...$pollData['expectedShares'][$type] ?? []); |
||
| 123 | $userIdConstraint->evaluate($userId); |
||
| 124 | |||
| 125 | if (in_array($userId, $pollData['initialShares'][$type] ?? [])) { |
||
| 126 | throw new ShareAlreadyExistsException(); |
||
| 127 | } |
||
| 128 | |||
| 129 | return $this->createShareMock($pollId, $type, $userId); |
||
| 130 | }); |
||
| 131 | |||
| 132 | $this->shareService |
||
| 133 | ->expects($this->exactly($expectedInvitationCount)) |
||
| 134 | ->method('sendInvitation') |
||
| 135 | ->with($this->logicalOr(...$expectedInvitationShareTokens)); |
||
| 136 | |||
| 137 | $command = new Add( |
||
| 138 | $this->pollMapper, |
||
| 139 | $this->shareMapper, |
||
| 140 | $this->shareService, |
||
| 141 | $this->userManager, |
||
| 142 | $this->groupManager |
||
| 143 | ); |
||
| 144 | |||
| 145 | $tester = new CommandTester($command); |
||
| 146 | $tester->execute($input); |
||
| 147 | |||
| 148 | $this->assertEquals("Users successfully invited to poll.\n", $tester->getDisplay()); |
||
| 149 | } |
||
| 207 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.