| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Code Lines | 40 |
| 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 |
||
| 73 | public function testComposeTriggersEvents() |
||
| 74 | { |
||
| 75 | $renderer = $this->prophesize(RendererInterface::class); |
||
| 76 | $renderer->render(Argument::type(ModelInterface::class)) |
||
| 77 | ->willReturn('MAIL_BODY'); |
||
| 78 | |||
| 79 | $service = new Composer($renderer->reveal()); |
||
| 80 | $em = $service->getEventManager(); |
||
| 81 | |||
| 82 | $listener = function ($event) { |
||
| 83 | $this->assertInstanceof( |
||
| 84 | ComposerEvent::class, |
||
| 85 | $event, |
||
| 86 | 'Failed asserting event instance of ' . get_class($event) . ' is of type ' . ComposerEvent::class |
||
| 87 | ); |
||
| 88 | $this->composeEventsTriggered[] = $event->getName(); |
||
| 89 | }; |
||
| 90 | |||
| 91 | $em->attach( |
||
| 92 | ComposerEvent::EVENT_COMPOSE_PRE, |
||
| 93 | $listener |
||
| 94 | ); |
||
| 95 | $em->attach( |
||
| 96 | ComposerEvent::EVENT_HEADERS_PRE, |
||
| 97 | $listener |
||
| 98 | ); |
||
| 99 | $em->attach( |
||
| 100 | ComposerEvent::EVENT_HEADERS_POST, |
||
| 101 | $listener |
||
| 102 | ); |
||
| 103 | $em->attach( |
||
| 104 | ComposerEvent::EVENT_HTML_BODY_PRE, |
||
| 105 | $listener |
||
| 106 | ); |
||
| 107 | $em->attach( |
||
| 108 | ComposerEvent::EVENT_HTML_BODY_POST, |
||
| 109 | $listener |
||
| 110 | ); |
||
| 111 | $em->attach( |
||
| 112 | ComposerEvent::EVENT_COMPOSE_POST, |
||
| 113 | $listener |
||
| 114 | ); |
||
| 115 | |||
| 116 | |||
| 117 | $template = new HtmlTemplate(); |
||
| 118 | $service->compose([], $template, new ViewModel()); |
||
| 119 | |||
| 120 | $this->assertEquals( |
||
| 121 | [ |
||
| 122 | ComposerEvent::EVENT_COMPOSE_PRE, |
||
| 123 | ComposerEvent::EVENT_HEADERS_PRE, |
||
| 124 | ComposerEvent::EVENT_HEADERS_POST, |
||
| 125 | ComposerEvent::EVENT_HTML_BODY_PRE, |
||
| 126 | ComposerEvent::EVENT_HTML_BODY_POST, |
||
| 127 | ComposerEvent::EVENT_COMPOSE_POST, |
||
| 128 | ], |
||
| 129 | $this->composeEventsTriggered |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | |||
| 168 |