Completed
Push — master ( ac48e3...f05831 )
by Tom
04:26
created

InstallSampleData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 7
c 4
b 1
f 0
lcom 1
cbo 8
dl 0
loc 72
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 24 4
B runSampleDataInstaller() 0 41 3
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
        if ($this->input->getOption('installSampleData') !== null) {
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