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