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