Failed Conditions
Push — master ( 0469de...12f4fc )
by Jonathan
02:19
created

EventDispatcher::dispatchVersionEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 4
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations;
6
7
use Doctrine\Common\EventArgs;
8
use Doctrine\Common\EventManager;
9
use Doctrine\Migrations\Configuration\Configuration;
10
use Doctrine\Migrations\Event\MigrationsEventArgs;
11
use Doctrine\Migrations\Event\MigrationsVersionEventArgs;
12
13
/**
14
 * @internal
15
 */
16
final class EventDispatcher
17
{
18
    /** @var Configuration */
19
    private $configuration;
20
21
    /** @var EventManager */
22
    private $eventManager;
23
24 52
    public function __construct(Configuration $configuration, EventManager $eventManager)
25
    {
26 52
        $this->configuration = $configuration;
27 52
        $this->eventManager  = $eventManager;
28 52
    }
29
30 26
    public function dispatchMigrationEvent(string $eventName, string $direction, bool $dryRun) : void
31
    {
32 26
        $event = $this->createMigrationEventArgs($direction, $dryRun);
33
34 26
        $this->dispatchEvent($eventName, $event);
35 26
    }
36
37 51
    public function dispatchVersionEvent(
38
        Version $version,
39
        string $eventName,
40
        string $direction,
41
        bool $dryRun
42
    ) : void {
43 51
        $event = $this->createMigrationsVersionEventArgs(
44 51
            $version,
45 51
            $direction,
46 51
            $dryRun
47
        );
48
49 51
        $this->dispatchEvent($eventName, $event);
50 51
    }
51
52 52
    public function dispatchEvent(string $eventName, ?EventArgs $args = null) : void
53
    {
54 52
        $this->eventManager->dispatchEvent($eventName, $args);
55 52
    }
56
57 26
    private function createMigrationEventArgs(string $direction, bool $dryRun) : MigrationsEventArgs
58
    {
59 26
        return new MigrationsEventArgs($this->configuration, $direction, $dryRun);
60
    }
61
62 51
    private function createMigrationsVersionEventArgs(
63
        Version $version,
64
        string $direction,
65
        bool $dryRun
66
    ) : MigrationsVersionEventArgs {
67 51
        return new MigrationsVersionEventArgs(
68 51
            $version,
69 51
            $this->configuration,
70 51
            $direction,
71 51
            $dryRun
72
        );
73
    }
74
}
75