Completed
Pull Request — master (#220)
by Alejandro
03:52
created

InstallApplicationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Installer\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use Shlinkio\Shlink\Installer\Command\InstallCommand;
9
use Shlinkio\Shlink\Installer\Config\ConfigCustomizerManager;
10
use Shlinkio\Shlink\Installer\Config\Plugin;
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\AbstractFactory\ConfigAbstractFactory;
16
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
17
use Zend\ServiceManager\Exception\ServiceNotFoundException;
18
use Zend\ServiceManager\Factory\FactoryInterface;
19
use Zend\ServiceManager\Factory\InvokableFactory;
20
21
class InstallApplicationFactory implements FactoryInterface
22
{
23
    /**
24
     * Create an object
25
     *
26
     * @param  ContainerInterface $container
27
     * @param  string $requestedName
28
     * @param  null|array $options
29
     * @return object
30
     * @throws LogicException
31
     * @throws ServiceNotFoundException if unable to resolve the service.
32
     * @throws ServiceNotCreatedException if an exception is raised when
33
     *     creating a service.
34
     * @throws ContainerException if any other error occurs
35
     */
36
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38
        $isUpdate = $options !== null && isset($options['isUpdate']) ? (bool) $options['isUpdate'] : false;
39
40
        $app = new Application();
41
        $command = new InstallCommand(
42
            new PhpArray(),
43
            $container->get(Filesystem::class),
44
            new ConfigCustomizerManager($container, ['factories' => [
45
                Plugin\DatabaseConfigCustomizer::class => ConfigAbstractFactory::class,
46
                Plugin\UrlShortenerConfigCustomizer::class => InvokableFactory::class,
47
                Plugin\LanguageConfigCustomizer::class => InvokableFactory::class,
48
                Plugin\ApplicationConfigCustomizer::class => InvokableFactory::class,
49
            ]]),
50
            $isUpdate
51
        );
52
        $app->add($command);
53
        $app->setDefaultCommand($command->getName(), true);
0 ignored issues
show
Bug introduced by
Consider using $command->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
54
55
        return $app;
56
    }
57
}
58