| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| 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 |
||
| 47 | public function testSendEmail(): void |
||
| 48 | { |
||
| 49 | $message = new Message(); |
||
| 50 | $message->setBody([ |
||
| 51 | 'subject' => 'subject', |
||
| 52 | 'from' => [ |
||
| 53 | 'email' => '[email protected]', |
||
| 54 | 'name' => 'nameFrom', |
||
| 55 | ], |
||
| 56 | 'to' => [ |
||
| 57 | '[email protected]', |
||
| 58 | '[email protected]' => 'nameTo2', |
||
| 59 | ], |
||
| 60 | 'replyTo' => [ |
||
| 61 | '[email protected]', |
||
| 62 | '[email protected]' => 'nameReplyTo2', |
||
| 63 | ], |
||
| 64 | 'returnPath' => [ |
||
| 65 | 'email' => '[email protected]', |
||
| 66 | ], |
||
| 67 | 'cc' => [ |
||
| 68 | '[email protected]', |
||
| 69 | '[email protected]' => 'nameCc2', |
||
| 70 | ], |
||
| 71 | 'bcc' => [ |
||
| 72 | '[email protected]', |
||
| 73 | '[email protected]' => 'nameBcc2', |
||
| 74 | ], |
||
| 75 | 'message' => [ |
||
| 76 | 'text' => 'message text', |
||
| 77 | 'html' => 'message html', |
||
| 78 | ], |
||
| 79 | 'attachment' => [ |
||
| 80 | 'file' => 'path to file', |
||
| 81 | 'name' => 'file name', |
||
| 82 | ], |
||
| 83 | ]); |
||
| 84 | |||
| 85 | $mail = $this->createMock('Swift_Message'); |
||
| 86 | $mail->expects($this->once())->method('setSubject')->with($this->equalTo('subject'))->willReturnSelf(); |
||
| 87 | $mail->expects($this->once())->method('setFrom')->with($this->equalTo(['[email protected]' => 'nameFrom']))->willReturnSelf(); |
||
| 88 | $mail->expects($this->once())->method('setTo')->with($this->equalTo(['[email protected]', '[email protected]' => 'nameTo2']))->willReturnSelf(); |
||
| 89 | $mail->expects($this->once())->method('setReplyTo')->with($this->equalTo(['[email protected]', '[email protected]' => 'nameReplyTo2']))->willReturnSelf(); |
||
| 90 | $mail->expects($this->once())->method('setReturnPath')->with($this->equalTo(['email' => '[email protected]']))->willReturnSelf(); |
||
| 91 | $mail->expects($this->once()) |
||
| 92 | ->method('setCc') |
||
| 93 | ->with($this->equalTo(['[email protected]', '[email protected]' => 'nameCc2'])) |
||
| 94 | ->willReturnSelf(); |
||
| 95 | $mail->expects($this->once()) |
||
| 96 | ->method('setBcc') |
||
| 97 | ->with($this->equalTo(['[email protected]', '[email protected]' => 'nameBcc2'])) |
||
| 98 | ->willReturnSelf(); |
||
| 99 | $mail->expects($this->exactly(2)) |
||
| 100 | ->method('addPart') |
||
| 101 | ->withConsecutive( |
||
| 102 | [$this->equalTo('message text'), $this->equalTo('text/plain')], |
||
| 103 | [$this->equalTo('message html'), $this->equalTo('text/html')] |
||
| 104 | ) |
||
| 105 | ->willReturnSelf(); |
||
| 106 | $mail->expects($this->once()) |
||
| 107 | ->method('attach') |
||
| 108 | ->willReturnSelf(); |
||
| 109 | |||
| 110 | $this->mailer->expects($this->once())->method('createMessage')->willReturn($mail); |
||
|
|
|||
| 111 | |||
| 112 | $method = new \ReflectionMethod($this->consumer, 'sendEmail'); |
||
| 113 | $method->setAccessible(true); |
||
| 114 | |||
| 115 | $method->invoke($this->consumer, $message); |
||
| 116 | } |
||
| 117 | } |
||
| 118 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.