Completed
Push — master ( 2044f4...a35418 )
by Loïc
13s queued 11s
created

InstallAssetsCommand::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Command\Installer;
4
5
use App\Command\Helper\CommandsRunner;
6
use App\Command\Helper\DirectoryChecker;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class InstallAssetsCommand extends Command
12
{
13
    /**
14
     * @var DirectoryChecker
15
     */
16
    private $directoryChecker;
17
    /**
18
     * @var CommandsRunner
19
     */
20
    private $commandsRunner;
21
    /**
22
     * @var string
23
     */
24
    private $publicDir;
25
    /**
26
     * @var string
27
     */
28
    private $environment;
29
30
    public function __construct(
31
        DirectoryChecker $directoryChecker,
32
        CommandsRunner $commandsRunner,
33
        string $publicDir,
34
        string $environment
35
    ) {
36
        $this->directoryChecker = $directoryChecker;
37
        $this->commandsRunner = $commandsRunner;
38
        $this->publicDir = $publicDir;
39
        $this->environment = $environment;
40
41
        parent::__construct();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function configure()
48
    {
49
        $this
50
            ->setName('app:install:assets')
51
            ->setDescription('Installs all AppName assets.')
52
            ->setHelp(<<<EOT
53
The <info>%command.name%</info> command downloads and installs all AppName media assets.
54
EOT
55
            )
56
        ;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     *
62
     * @throws \Exception
63
     */
64
    protected function execute(InputInterface $input, OutputInterface $output)
65
    {
66
        $output->writeln(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment));
67
68
        try {
69
            $this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/assets/', $output, $this->getName());
70
            $this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/bundles/', $output, $this->getName());
71
        } catch (\RuntimeException $exception) {
72
            return 1;
73
        }
74
75
        $commands = [
76
            'assets:install',
77
        ];
78
79
        $this->commandsRunner->run($commands, $input, $output, $this->getApplication());
0 ignored issues
show
Bug introduced by
It seems like $this->getApplication() can be null; however, run() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
80
    }
81
}
82