EventDispatcherAwarenessTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 48.48 %

Importance

Changes 0
Metric Value
wmc 1
dl 16
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A eventDispatcherAwareInstance() 0 6 1
A using_a_event_dispatcher() 8 8 1
A when_no_dispatcher_is_provided_a_dispatcher_is_created() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
declare(strict_types=1);
4
5
namespace League\Event;
6
7
use PHPUnit\Framework\TestCase;
8
9
class EventDispatcherAwarenessTest extends TestCase
10
{
11
    /**
12
     * @test
13
     */
14 View Code Duplication
    public function using_a_event_dispatcher(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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
36
    {
37
        return new class() implements EventDispatcherAware {
38
            use EventDispatcherAwareBehavior;
39
        };
40
    }
41
}
42