Completed
Push — master ( 257fa6...226ae9 )
by Loïc
26s queued 10s
created

InstallAssetsCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace App\Command\Installer;
4
5
use App\Command\Helper\EnsureDirectoryExistsAndIsWritable;
6
use App\Command\Helper\RunCommands;
7
use App\Installer\Checker\CommandDirectoryChecker;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class InstallAssetsCommand extends Command
14
{
15
    const WEB_ASSETS_DIRECTORY = 'public/assets/';
16
    const WEB_BUNDLES_DIRECTORY = 'public/bundles/';
17
18
    use EnsureDirectoryExistsAndIsWritable {
19
        EnsureDirectoryExistsAndIsWritable::__construct as private initializeEnsureDirectoryExistsAndIsWritable;
20
    }
21
    use RunCommands {
22
        RunCommands::__construct as private initializeRunCommands;
23
    }
24
25
    /**
26
     * @var CommandDirectoryChecker
27
     */
28
    private $commandDirectoryChecker;
29
30
    /**
31
     * @var EntityManagerInterface
32
     */
33
    private $entityManager;
34
35
    /**
36
     * @var string
37
     */
38
    private $environment;
39
40
    /**
41
     * @param CommandDirectoryChecker $commandDirectoryChecker
42
     * @param EntityManagerInterface  $entityManager
43
     * @param string                  $environment
44
     */
45
    public function __construct(CommandDirectoryChecker $commandDirectoryChecker, EntityManagerInterface $entityManager, string $environment)
46
    {
47
        $this->commandDirectoryChecker = $commandDirectoryChecker;
48
        $this->entityManager = $entityManager;
49
        $this->environment = $environment;
50
51
        parent::__construct();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function initialize(InputInterface $input, OutputInterface $output)
58
    {
59
        $commandExecutor = new CommandExecutor($input, $output, $this->getApplication());
0 ignored issues
show
Bug introduced by
It seems like $this->getApplication() can be null; however, __construct() 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...
60
61
        $this->initializeEnsureDirectoryExistsAndIsWritable($this->commandDirectoryChecker, $this->getName());
62
        $this->initializeRunCommands($commandExecutor, $this->entityManager);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    protected function configure()
69
    {
70
        $this
71
            ->setName('app:install:assets')
72
            ->setDescription('Installs all AppName assets.')
73
            ->setHelp(<<<EOT
74
The <info>%command.name%</info> command downloads and installs all AppName media assets.
75
EOT
76
            )
77
        ;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    protected function execute(InputInterface $input, OutputInterface $output)
84
    {
85
        $output->writeln(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment));
86
87
        try {
88
            $this->ensureDirectoryExistsAndIsWritable(self::WEB_ASSETS_DIRECTORY, $output);
89
            $this->ensureDirectoryExistsAndIsWritable(self::WEB_BUNDLES_DIRECTORY, $output);
90
        } catch (\RuntimeException $exception) {
91
            return 1;
92
        }
93
94
        $commands = [
95
            'assets:install',
96
        ];
97
98
        $this->runCommands($commands, $output);
99
    }
100
}
101