CreateApplicationCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
A __construct() 0 6 1
A configure() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\Command;
15
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Yaml\Yaml;
20
use Tardigrades\SectionField\Service\ApplicationManagerInterface;
21
use Tardigrades\SectionField\ValueObject\ApplicationConfig;
22
23
class CreateApplicationCommand extends ApplicationCommand
24
{
25
    /** @var ApplicationManagerInterface */
26
    private $applicationManager;
27
28
    public function __construct(
29
        ApplicationManagerInterface $applicationManager
30
    ) {
31
        $this->applicationManager = $applicationManager;
32
33
        parent::__construct('sf:create-application');
34
    }
35
36
    protected function configure()
37
    {
38
        // @codingStandardsIgnoreStart
39
        $this
40
            ->setDescription('Create application')
41
            ->setHelp('Create a new application, an application is related to sections, you can group sections and isolate them when necessary. You need at least one application, and only one application counts as default.')
42
            ->addArgument('config', InputArgument::REQUIRED, 'The application configuration yml');
43
        // @codingStandardsIgnoreEnd
44
    }
45
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $config = $input->getArgument('config');
49
50
        try {
51
            $applicationConfig = ApplicationConfig::fromArray(
52
                Yaml::parse(file_get_contents($config))
53
            );
54
            $this->applicationManager->createByConfig($applicationConfig);
55
            $output->writeln('<info>Application created!</info>');
56
        } catch (\Exception $exception) {
57
            $output->writeln("<error>Invalid config. {$exception->getMessage()}</error>");
58
        }
59
    }
60
}
61