Completed
Push — master ( b53e51...1009f9 )
by Alejandro
04:13 queued 38s
created

InstallApplicationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 16
cts 16
cp 1
rs 10
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 3
1
<?php
2
namespace Shlinkio\Shlink\CLI\Factory;
3
4
use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory;
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Shlinkio\Shlink\CLI\Command\Install\InstallCommand;
8
use Shlinkio\Shlink\CLI\Install\ConfigCustomizerPluginManager;
9
use Shlinkio\Shlink\CLI\Install\Plugin;
10
use Shlinkio\Shlink\CLI\Install\Plugin\Factory\DefaultConfigCustomizerPluginFactory;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Exception\LogicException;
13
use Symfony\Component\Filesystem\Filesystem;
14
use Zend\Config\Writer\PhpArray;
15
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
16
use Zend\ServiceManager\Exception\ServiceNotFoundException;
17
use Zend\ServiceManager\Factory\FactoryInterface;
18
19
class InstallApplicationFactory implements FactoryInterface
20
{
21
    /**
22
     * Create an object
23
     *
24
     * @param  ContainerInterface $container
25
     * @param  string $requestedName
26
     * @param  null|array $options
27
     * @return object
28
     * @throws LogicException
29
     * @throws ServiceNotFoundException if unable to resolve the service.
30
     * @throws ServiceNotCreatedException if an exception is raised when
31
     *     creating a service.
32
     * @throws ContainerException if any other error occurs
33
     */
34 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
35
    {
36 1
        $isUpdate = $options !== null && isset($options['isUpdate']) ? (bool) $options['isUpdate'] : false;
37
38 1
        $app = new Application();
39 1
        $command = new InstallCommand(
40 1
            new PhpArray(),
41 1
            $container->get(Filesystem::class),
42 1
            new ConfigCustomizerPluginManager($container, ['factories' => [
43 1
                Plugin\DatabaseConfigCustomizerPlugin::class => AnnotatedFactory::class,
44 1
                Plugin\UrlShortenerConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
45 1
                Plugin\LanguageConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
46 1
                Plugin\ApplicationConfigCustomizerPlugin::class => DefaultConfigCustomizerPluginFactory::class,
47 1
            ]]),
48
            $isUpdate
49 1
        );
50 1
        $app->add($command);
51 1
        $app->setDefaultCommand($command->getName());
52
53 1
        return $app;
54
    }
55
}
56