EventDispatcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 60
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A dispatchMigrationEvent() 0 9 1
A dispatchVersionEvent() 0 12 1
A dispatchEvent() 0 4 1
A createMigrationEventArgs() 0 6 1
A createMigrationsVersionEventArgs() 0 10 1
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\DBAL\Connection;
10
use Doctrine\Migrations\Event\MigrationsEventArgs;
11
use Doctrine\Migrations\Event\MigrationsVersionEventArgs;
12
use Doctrine\Migrations\Metadata\MigrationPlan;
13
use Doctrine\Migrations\Metadata\MigrationPlanList;
14
15
/**
16
 * The EventDispatcher class is responsible for dispatching events internally that a user can listen for.
17
 *
18
 * @internal
19
 */
20
final class EventDispatcher
21
{
22
    /** @var EventManager */
23
    private $eventManager;
24
25
    /** @var Connection */
26
    private $connection;
27
28 17
    public function __construct(Connection $connection, EventManager $eventManager)
29
    {
30 17
        $this->eventManager = $eventManager;
31 17
        $this->connection   = $connection;
32 17
    }
33
34 4
    public function dispatchMigrationEvent(
35
        string $eventName,
36
        MigrationPlanList $migrationsPlan,
37
        MigratorConfiguration $migratorConfiguration
38
    ) : void {
39 4
        $event = $this->createMigrationEventArgs($migrationsPlan, $migratorConfiguration);
40
41 4
        $this->dispatchEvent($eventName, $event);
42 4
    }
43
44 15
    public function dispatchVersionEvent(
45
        string $eventName,
46
        MigrationPlan $plan,
47
        MigratorConfiguration $migratorConfiguration
48
    ) : void {
49 15
        $event = $this->createMigrationsVersionEventArgs(
50 15
            $plan,
51 15
            $migratorConfiguration
52
        );
53
54 15
        $this->dispatchEvent($eventName, $event);
55 15
    }
56
57 15
    private function dispatchEvent(string $eventName, ?EventArgs $args = null) : void
58
    {
59 15
        $this->eventManager->dispatchEvent($eventName, $args);
60 15
    }
61
62 4
    private function createMigrationEventArgs(
63
        MigrationPlanList $migrationsPlan,
64
        MigratorConfiguration $migratorConfiguration
65
    ) : MigrationsEventArgs {
66 4
        return new MigrationsEventArgs($this->connection, $migrationsPlan, $migratorConfiguration);
67
    }
68
69 15
    private function createMigrationsVersionEventArgs(
70
        MigrationPlan $plan,
71
        MigratorConfiguration $migratorConfiguration
72
    ) : MigrationsVersionEventArgs {
73 15
        return new MigrationsVersionEventArgs(
74 15
            $this->connection,
75 15
            $plan,
76 15
            $migratorConfiguration
77
        );
78
    }
79
}
80