ApplicationProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 2
c 3
b 0
f 1
lcom 0
cbo 2
dl 0
loc 51
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 38 2
1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license. For more information, see
18
 * <https://github.com/baleen/migrations>.
19
 */
20
21
namespace Baleen\Cli\Provider;
22
23
use Baleen\Cli\Application;
24
use Baleen\Cli\CommandBus\AbstractMessage;
25
use Baleen\Cli\CommandBus\Util\ComparatorAwareInterface;
26
use Baleen\Cli\CommandBus\Util\ConfigStorageAwareInterface;
27
use Baleen\Cli\CommandBus\Util\RepositoryAwareInterface;
28
use Baleen\Cli\CommandBus\Util\StorageAwareInterface;
29
use Baleen\Cli\CommandBus\Util\TimelineAwareInterface;
30
use League\Container\ServiceProvider;
31
use Symfony\Component\EventDispatcher\EventDispatcher;
32
33
/**
34
 * Class ApplicationProvider.
35
 *
36
 * @author Gabriel Somoza <[email protected]>
37
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
38
 */
39
class ApplicationProvider extends ServiceProvider
40
{
41
    protected $provides = [
42
        Services::APPLICATION,
43
        Services::APPLICATION_DISPATCHER,
44
    ];
45
46
    /**
47
     * Use the register method to register items with the container via the
48
     * protected $this->container property or the `getContainer` method
49
     * from the ContainerAwareTrait.
50
     */
51
    public function register()
52
    {
53
        $container = $this->getContainer();
54
55
        $container->singleton(Services::APPLICATION_DISPATCHER, EventDispatcher::class);
56
57
        if (!$container->isRegistered(Services::APPLICATION)) {
58
            $args = [
59
                Services::COMMANDS,
60
                Services::HELPERSET,
61
                Services::APPLICATION_DISPATCHER,
62
            ];
63
            $container->singleton(Services::APPLICATION, Application::class)
64
                ->withArguments($args);
65
        }
66
67
        // register inflectors for the different types of commands
68
        $container->inflector(RepositoryAwareInterface::class)
69
            ->invokeMethods([
70
                'setRepository' => [Services::REPOSITORY],
71
                'setFilesystem' => [Services::REPOSITORY_FILESYSTEM],
72
            ]);
73
74
        $container->inflector(StorageAwareInterface::class)
75
            ->invokeMethod('setStorage', [Services::STORAGE]);
76
77
        $container->inflector(TimelineAwareInterface::class)
78
            ->invokeMethod('setTimeline', [Services::TIMELINE]);
79
80
        $container->inflector(ComparatorAwareInterface::class)
81
            ->invokeMethod('setComparator', [Services::COMPARATOR]);
82
83
        $container->inflector(ConfigStorageAwareInterface::class)
84
            ->invokeMethod('setConfigStorage', [Services::CONFIG_STORAGE]);
85
86
        $container->inflector(AbstractMessage::class)
87
            ->invokeMethod('setConfig', [Services::CONFIG]);
88
    }
89
}
90