Completed
Pull Request — master (#15)
by Gabriel
03:36
created

DomainCommandBusFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 1
cbo 6
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createWithInMemoryLocator() 0 5 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\DomainBus;
23
use Baleen\Migrations\Service\Command\DomainBusInterface;
24
use Baleen\Migrations\Service\Command\Migrate\Collection\CollectionCommand;
25
use Baleen\Migrations\Service\Command\Migrate\Collection\CollectionHandler;
26
use Baleen\Migrations\Service\Command\Migrate\Converge\ConvergeCommand;
27
use Baleen\Migrations\Service\Command\Migrate\Converge\ConvergeHandler;
28
use Baleen\Migrations\Service\Command\Migrate\Single\SingleCommand;
29
use Baleen\Migrations\Service\Command\Migrate\Single\SingleHandler;
30
use Baleen\Migrations\Service\Runner\ContextualRunnerInterface;
31
use Baleen\Migrations\Service\Runner\Factory\CollectionRunnerFactory;
32
use Baleen\Migrations\Service\Runner\MigrationRunner;
33
use Baleen\Migrations\Shared\Event\PublisherInterface;
34
use League\Tactician\CommandBus;
35
use League\Tactician\Handler\Locator\InMemoryLocator;
36
37
/**
38
 * Class DomainCommandBusFactory
39
 * @author Gabriel Somoza <[email protected]>
40
 */
41
final class DomainCommandBusFactory
42
{
43
    /** @var ContextualRunnerInterface */
44
    private $migrationRunner;
45
46
    /** @var PublisherInterface */
47
    private $publisher;
48
49
    /**
50
     * DomainCommandBusFactory constructor.
51
     *
52
     * @param PublisherInterface $publisher
53
     * @param ContextualRunnerInterface $migrationRunner
54
     */
55 2
    public function __construct(PublisherInterface $publisher, ContextualRunnerInterface $migrationRunner)
56
    {
57 2
        $this->migrationRunner = $migrationRunner;
58 2
        $this->publisher = $publisher;
59 2
    }
60
61
    /**
62
     * create
63
     *
64
     * @return DomainBusInterface
65
     */
66 1
    public function createWithInMemoryLocator()
67
    {
68 1
        $locator = new InMemoryLocator($this->getCommandHandlerMapping());
69 1
        return DomainBus::createWithLocator($locator);
70
    }
71
72
    /**
73
     * getCommandHandlerMapping
74
     *
75
     * @return array
76
     */
77 2
    public function getCommandHandlerMapping()
78
    {
79 2
        $factory = new CollectionRunnerFactory($this->publisher, $this->migrationRunner);
80
        return [
81 2
            CollectionCommand::class => new CollectionHandler($factory),
82 2
            ConvergeCommand::class => new ConvergeHandler(),
83 2
            SingleCommand::class => new SingleHandler($this->migrationRunner),
84 2
        ];
85
    }
86
}
87