createWithInMemoryLocator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 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\DomainBus\Factory;
21
22
use Baleen\Migrations\Service\DomainBus\DomainBus;
23
use Baleen\Migrations\Service\DomainBus\DomainBusInterface;
24
use Baleen\Migrations\Service\DomainBus\Migrate\Collection\CollectionCommand;
25
use Baleen\Migrations\Service\DomainBus\Migrate\Collection\CollectionHandler;
26
use Baleen\Migrations\Service\DomainBus\Migrate\Converge\ConvergeCommand;
27
use Baleen\Migrations\Service\DomainBus\Migrate\Converge\ConvergeHandler;
28
use Baleen\Migrations\Service\DomainBus\Migrate\Single\SingleCommand;
29
use Baleen\Migrations\Service\DomainBus\Migrate\Single\SingleHandler;
30
use Baleen\Migrations\Service\Runner\HasRunnerTrait;
31
use Baleen\Migrations\Service\Runner\MigrationRunnerInterface;
32
use Baleen\Migrations\Service\Runner\Factory\CollectionRunnerFactory;
33
use Baleen\Migrations\Service\Runner\MigrationRunner;
34
use Baleen\Migrations\Common\Event\PublisherInterface;
35
use League\Tactician\CommandBus;
36
use League\Tactician\Handler\Locator\InMemoryLocator;
37
38
/**
39
 * Class DomainCommandBusFactory
40
 * @author Gabriel Somoza <[email protected]>
41
 */
42
final class DomainCommandBusFactory
43
{
44
    use HasRunnerTrait;
45
46
    /** @var PublisherInterface */
47
    private $publisher;
48
49
    /**
50
     * DomainCommandBusFactory constructor.
51
     *
52
     * @param PublisherInterface $publisher
53
     * @param null|MigrationRunnerInterface $migrationRunner
54
     */
55 2
    public function __construct(PublisherInterface $publisher, MigrationRunnerInterface $migrationRunner = null)
56
    {
57 2
        if (null === $migrationRunner) {
58
            $migrationRunner = new MigrationRunner($publisher);
59
        }
60 2
        $this->setRunner($migrationRunner);
61 2
        $this->publisher = $publisher;
62 2
    }
63
64
    /**
65
     * create
66
     *
67
     * @return DomainBusInterface
68
     */
69 1
    public function createWithInMemoryLocator()
70
    {
71 1
        $locator = new InMemoryLocator($this->getCommandHandlerMapping());
72 1
        return DomainBus::createWithLocator($locator);
73
    }
74
75
    /**
76
     * getCommandHandlerMapping
77
     *
78
     * @return array
79
     */
80 2
    public function getCommandHandlerMapping()
81
    {
82
        /** @var MigrationRunnerInterface $migrationRunner */
83 2
        $migrationRunner = $this->getRunner();
84 2
        $factory = new CollectionRunnerFactory($this->publisher, $migrationRunner);
85
        return [
86 2
            CollectionCommand::class => new CollectionHandler($factory),
87 2
            ConvergeCommand::class => new ConvergeHandler(),
88 2
            SingleCommand::class => new SingleHandler($migrationRunner),
89 2
        ];
90
    }
91
}
92