Completed
Push — develop ( a0c664...f8e6eb )
by Tom
04:27
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
        $dialog = $this->getCommand()->getHelper('dialog');
24
25 View Code Duplication
        if ($this->input->getOption('installSampleData') !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            $installSampleData = $this->getCommand()->parseBoolOption($this->input->getOption('installSampleData'));
27
        } else {
28
            $installSampleData = $dialog->askConfirmation(
29
                $this->output,
30
                '<question>Install sample data?</question> <comment>[y]</comment>: '
31
            );
32
        }
33
34
        if ($installSampleData) {
35
            $this->runSampleDataInstaller();
36
        }
37
    }
38
39
    protected function runSampleDataInstaller()
40
    {
41
        $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...
42
43
        $processBuilder = new ProcessBuilder([
44
            'php',
45
            'bin/magento',
46
            'sampledata:deploy',
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($buffer, false);
58
        });
59
60
61
        // @TODO Refactor code duplication
62
        if (!OperatingSystem::isWindows()) {
63
            $processBuilder->setPrefix('/usr/bin/env');
64
        }
65
66
        $processBuilder = new ProcessBuilder(
67
            array(
68
                'php',
69
                'bin/magento',
70
                'setup:upgrade'
71
            )
72
        );
73
        $process = $processBuilder->getProcess();
74
        $process->setTimeout(86400);
75
        $process->start();
76
        $process->wait(function ($type, $buffer) {
77
            $this->output->write($buffer, false);
78
        });
79
    }
80
}
81