Completed
Push — develop ( 569b94...a0c664 )
by Tom
04:46
created

InstallSampleData::runMagentoCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
namespace N98\Magento\Command\Installer\SubCommand;
4
5
use N98\Magento\Command\SubCommand\AbstractSubCommand;
6
use N98\Util\OperatingSystem;
7
use Symfony\Component\Process\ProcessBuilder;
8
9
class InstallSampleData extends AbstractSubCommand
10
{
11
    /**
12
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
13
     */
14
    public function execute()
15
    {
16
        if ($this->input->getOption('noDownload')) {
17
            return false;
18
        }
19
20
        $installationFolder = $this->config->getString('installationFolder');
21
        chdir($installationFolder);
22
23
        $flag = $this->getOptionalBooleanOption('installSampleData', 'Install sample data?');
24
25
        if ($flag) {
26
            $this->runSampleDataInstaller();
27
        }
28
    }
29
30
    protected function runSampleDataInstaller()
31
    {
32
        $installationArgs = $this->config->getArray('installation_args');
0 ignored issues
show
Unused Code introduced by
$installationArgs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
34
        $this->runMagentoCommand('sampledata:deploy');
35
        $this->runMagentoCommand('setup:upgrade');
36
    }
37
38
    /**
39
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
40
     */
41
    private function runMagentoCommand($command)
42
    {
43
        $processBuilder = new ProcessBuilder([
44
            'php',
45
            'bin/magento',
46
            $command,
47
        ]);
48
49
        if (!OperatingSystem::isWindows()) {
50
            $processBuilder->setPrefix('/usr/bin/env');
51
        }
52
53
        $process = $processBuilder->getProcess();
54
        $process->setTimeout(86400);
55
        $process->start();
56
        $process->wait(function ($type, $buffer) {
57
            $this->output->write('bin/magento > ' . $buffer, false);
58
        });
59
    }
60
}
61