Total Complexity | 1 |
Total Lines | 33 |
Duplicated Lines | 48.48 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
9 | class EventDispatcherAwarenessTest extends TestCase |
||
10 | { |
||
11 | /** |
||
12 | * @test |
||
13 | */ |
||
14 | View Code Duplication | public function using_a_event_dispatcher(): void |
|
|
|||
15 | { |
||
16 | $instance = $this->eventDispatcherAwareInstance(); |
||
17 | $dispatcher = new EventDispatcher(); |
||
18 | $instance->useEventDispatcher($dispatcher); |
||
19 | |||
20 | $this->assertSame($dispatcher, $instance->eventDispatcher()); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @test |
||
25 | */ |
||
26 | View Code Duplication | public function when_no_dispatcher_is_provided_a_dispatcher_is_created(): void |
|
27 | { |
||
28 | $instance = $this->eventDispatcherAwareInstance(); |
||
29 | |||
30 | $eventDispatcher = $instance->eventDispatcher(); |
||
31 | $this->assertInstanceOf(EventDispatcher::class, $eventDispatcher); |
||
32 | $this->assertSame($eventDispatcher, $instance->eventDispatcher()); |
||
33 | } |
||
34 | |||
35 | private function eventDispatcherAwareInstance(): EventDispatcherAware |
||
41 | } |
||
42 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.