Completed
Push — master ( 23d5f0...daf9a4 )
by Kamil
05:58
created

InstallCommand::execute()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 8.6897
c 0
b 0
f 0
cc 6
nc 18
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\CoreBundle\Command;
15
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Style\SymfonyStyle;
20
use Symfony\Component\Process\Exception\RuntimeException;
21
22
final class InstallCommand extends AbstractInstallCommand
23
{
24
    /**
25
     * @var array
26
     *
27
     * @psalm-var non-empty-list
28
     */
29
    private $commands = [
30
        [
31
            'command' => 'check-requirements',
32
            'message' => 'Checking system requirements.',
33
        ],
34
        [
35
            'command' => 'database',
36
            'message' => 'Setting up the database.',
37
        ],
38
        [
39
            'command' => 'setup',
40
            'message' => 'Shop configuration.',
41
        ],
42
        [
43
            'command' => 'assets',
44
            'message' => 'Installing assets.',
45
        ],
46
    ];
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function configure(): void
52
    {
53
        $this
54
            ->setName('sylius:install')
55
            ->setDescription('Installs Sylius in your preferred environment.')
56
            ->setHelp(<<<EOT
57
The <info>%command.name%</info> command installs Sylius.
58
EOT
59
            )
60
            ->addOption('fixture-suite', 's', InputOption::VALUE_OPTIONAL, 'Load specified fixture suite during install', null)
61
        ;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    protected function execute(InputInterface $input, OutputInterface $output): int
68
    {
69
        $suite = $input->getOption('fixture-suite');
70
71
        $outputStyle = new SymfonyStyle($input, $output);
72
        $outputStyle->writeln('<info>Installing Sylius...</info>');
73
        $outputStyle->writeln($this->getSyliusLogo());
74
75
        $this->ensureDirectoryExistsAndIsWritable($this->getContainer()->getParameter('kernel.cache_dir'), $output);
76
77
        $errored = false;
78
        foreach ($this->commands as $step => $command) {
79
            try {
80
                $outputStyle->newLine();
81
                $outputStyle->section(sprintf(
82
                    'Step %d of %d. <info>%s</info>',
83
                    $step + 1,
84
                    count($this->commands),
85
                    $command['message']
86
                ));
87
88
                $parameters = [];
89
                if ('database' === $command['command'] && null !== $suite) {
90
                    $parameters['--fixture-suite'] = $suite;
91
                }
92
93
                $this->commandExecutor->runCommand('sylius:install:' . $command['command'], $parameters, $output);
94
            } catch (RuntimeException $exception) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Proces...eption\RuntimeException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
95
                $errored = true;
96
            }
97
        }
98
99
        $outputStyle->newLine(2);
100
        $outputStyle->success($this->getProperFinalMessage($errored));
101
        $outputStyle->writeln('You can now open your store at the following path under the website root: /');
102
103
        return $errored ? 1 : 0;
104
    }
105
106
    private function getProperFinalMessage(bool $errored): string
107
    {
108
        if ($errored) {
109
            return 'Sylius has been installed, but some error occurred.';
110
        }
111
112
        return 'Sylius has been successfully installed.';
113
    }
114
115
    private function getSyliusLogo(): string
116
    {
117
        return '
118
           <info>,</info>
119
         <info>,;:,</info>
120
       <info>`;;;.:`</info>
121
      <info>`::;`  :`</info>
122
       <info>:::`   `</info>          .\'++:           \'\'.   \'.
123
       <info>`:::</info>             :+\',;+\'          :+;  `+.
124
        <info>::::</info>            +\'   :\'          `+;
125
        <info>`:::,</info>           \'+`     ++    :+.`+; `++. ;+\'    \'\'  ,++++.
126
         <info>,:::`</info>          `++\'.   .+:  `+\' `+;  .+,  ;+    +\'  +;  \'\'
127
          <info>::::`</info>           ,+++.  \'+` :+. `+;  `+,  ;+    +\'  \'+.
128
   <info>,.     .::::</info>             .++` `+: +\'  `+;  `+,  ;+    +\'  `;++;
129
<info>`;;.:::`   :::::</info>             :+.  \'+,+.  `+;  `+,  ;+   `+\'     .++
130
 <info>.;;;;;;::`.::::,</info>       +\'` `++   `++\'   `+;  `+:  :+. `++\'  \'.  ;+
131
  <info>,;;;;;;;;;:::::</info>       .+++++`    ;+,    ++;  ++, `\'+++,\'+\' :++++,
132
   <info>,;;;;;;;;;:::</info>`                  ;\'
133
    <info>:;;;;;;;;;:,</info>                :.:+,
134
     <info>;;;;;;;;;:</info>                 ;++,'
135
        ;
136
    }
137
}
138