DeployPlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 55
ccs 0
cts 36
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 45 3
A configure() 0 5 1
1
<?php
2
3
4
namespace Deployee\Plugins\Deploy;
5
6
7
use Deployee\Components\Application\CommandCollection;
8
use Deployee\Components\Config\ConfigInterface;
9
use Deployee\Components\Container\ContainerInterface;
10
use Deployee\Components\Dependency\ContainerResolver;
11
use Deployee\Components\Environment\EnvironmentInterface;
12
use Deployee\Components\Plugins\PluginInterface;
13
use Deployee\Plugins\Deploy\Commands\DeployRunCommand;
14
use Deployee\Plugins\Deploy\Definitions\Deploy\DeployFactory;
15
use Deployee\Plugins\Deploy\Definitions\Tasks\TaskFactory;
16
use Deployee\Plugins\Deploy\Dispatcher\DispatcherCollection;
17
use Deployee\Plugins\Deploy\Dispatcher\DispatcherFinder;
18
use Deployee\Plugins\Deploy\Finder\DeployDefinitionFileFinder;
19
use Deployee\Plugins\Deploy\Helper\TaskCreationHelper;
20
21
class DeployPlugin implements PluginInterface
22
{
23
    public function boot(ContainerInterface $container)
24
    {
25
        /* @var EnvironmentInterface $env */
26
        $env = $container->get(EnvironmentInterface::class);
27
        $container->set(DeployDefinitionFileFinder::class, function(ContainerInterface $container) use($env){
28
            /* @var ContainerResolver $resolver */
29
            $resolver = $container->get(ContainerResolver::class);
30
            /* @var ConfigInterface $config */
31
            $config = $container->get(ConfigInterface::class);
32
            $path = $config->get('deploy_definition_path', 'definitions');
33
34
            $path = strpos($path, '/') !== 0 && strpos($path, ':') !== 1
35
                ? $env->getWorkDir() . DIRECTORY_SEPARATOR . $path
36
                : $path;
37
38
39
            return $resolver->createInstance(DeployDefinitionFileFinder::class, [$path]);
40
        });
41
42
        $container->set(DeployFactory::class, function(ContainerInterface $container){
43
            /* @var ContainerResolver $resolver */
44
            $resolver = $container->get(ContainerResolver::class);
45
            return $resolver->createInstance(DeployFactory::class);
46
        });
47
48
        $container->set(TaskFactory::class, function(ContainerInterface $container){
49
            /* @var ContainerResolver $resolver */
50
            $resolver = $container->get(ContainerResolver::class);
51
            return $resolver->createInstance(TaskFactory::class);
52
        });
53
54
        $container->set(TaskCreationHelper::class, function(ContainerInterface $container){
55
            /* @var ContainerResolver $resolver */
56
            $resolver = $container->get(ContainerResolver::class);
57
            return $resolver->createInstance(TaskCreationHelper::class);
58
        });
59
60
        $container->set(DispatcherCollection::class, function(){
61
            return new DispatcherCollection();
62
        });
63
64
        $container->set(DispatcherFinder::class, function(ContainerInterface $container){
65
            /* @var ContainerResolver $resolver */
66
            $resolver = $container->get(ContainerResolver::class);
67
            return $resolver->createInstance(DispatcherFinder::class);
68
        });
69
    }
70
71
    public function configure(ContainerInterface $container)
72
    {
73
        /* @var CommandCollection $cmdCollection */
74
        $cmdCollection = $container->get(CommandCollection::class);
75
        $cmdCollection->addCommand(new DeployRunCommand());
76
    }
77
}