Completed
Branch ddd-changes (96d3bc)
by Gabriel
05:08
created

DomainCommandBusFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createQuickStartBus() 0 4 1
A getCommandHandlerMapping() 0 9 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Baleen\Migrations\Service\Command\Factory;
21
22
use Baleen\Migrations\Service\Command\Migrate\Collection\CollectionCommand;
23
use Baleen\Migrations\Service\Command\Migrate\Collection\CollectionHandler;
24
use Baleen\Migrations\Service\Command\Migrate\Converge\ConvergeCommand;
25
use Baleen\Migrations\Service\Command\Migrate\Converge\ConvergeHandler;
26
use Baleen\Migrations\Service\Command\Migrate\Single\SingleCommand;
27
use Baleen\Migrations\Service\Command\Migrate\Single\SingleHandler;
28
use Baleen\Migrations\Service\Runner\Factory\CollectionRunnerFactory;
29
use Baleen\Migrations\Service\Runner\RunnerInterface;
30
use Baleen\Migrations\Shared\Event\PublisherInterface;
31
use League\Tactician\CommandBus;
32
use League\Tactician\Setup\QuickStart;
33
34
/**
35
 * Class DomainCommandBusFactory
36
 * @author Gabriel Somoza <[email protected]>
37
 */
38
final class DomainCommandBusFactory
39
{
40
    /** @var RunnerInterface */
41
    private $migrationRunner;
42
43
    /** @var PublisherInterface */
44
    private $publisher;
45
46
    /**
47
     * DomainCommandBusFactory constructor.
48
     * @param PublisherInterface $publisher
49
     * @param \Baleen\Migrations\Service\Runner\RunnerInterface $migrationRunner
50
     */
51 2
    public function __construct(PublisherInterface $publisher, RunnerInterface $migrationRunner)
52
    {
53 2
        $this->migrationRunner = $migrationRunner;
54 2
        $this->publisher = $publisher;
55 2
    }
56
57
    /**
58
     * create
59
     *
60
     * @return CommandBus
61
     */
62 1
    public function createQuickStartBus()
63
    {
64 1
        return QuickStart::create($this->getCommandHandlerMapping());
65
    }
66
67
    /**
68
     * getCommandHandlerMapping
69
     *
70
     * @return array
71
     */
72 2
    public function getCommandHandlerMapping()
73
    {
74 2
        $factory = new CollectionRunnerFactory($this->publisher, $this->migrationRunner);
75
        return [
76 2
            CollectionCommand::class => new CollectionHandler($factory),
77 2
            ConvergeCommand::class => new ConvergeHandler(),
78 2
            SingleCommand::class => new SingleHandler($this->migrationRunner),
79 2
        ];
80
    }
81
}
82