Completed
Push — feature/add-cli-installers ( 278b10...1a65a6 )
by Steven
14:48 queued 56s
created

PhpspecCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php namespace Magestead\Command;
2
3
use Magestead\Helper\Config;
4
use Symfony\Component\Console\Input\InputArgument;
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class PhpspecCommand extends Command
10
{
11
    protected $_projectPath;
12
13
    protected function configure()
14
    {
15
        $this->_projectPath = getcwd();
16
17
        $this->setName("phpspec");
18
        $this->setDescription("Run PHPSpec against your project");
19
        $this->addArgument('option', InputArgument::OPTIONAL, 'Add options to run');
20
    }
21
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        $output->writeln('<info>Running PHPSpec</info>');
25
        $option = $input->getArgument('option');
26
27
28
        $command = $this->getCommand(new Config($output), $option);
29
        if ($command) {
30
            $passedCommand = "vagrant ssh -c '". $command ."'";
31
            return new ProcessCommand($passedCommand, $this->_projectPath, $output);
32
        }
33
34
        return $output->writeln('<error>Command not available for this application</error>');
35
    }
36
37 View Code Duplication
    protected function getCommand(Config $config, $option)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39
        $type = $config->type;
0 ignored issues
show
Bug introduced by
The property type does not seem to exist in Magestead\Helper\Config.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
40
        switch ($type) {
41
            case 'magento':
42
                return "cd /var/www;bin/phpspec $option";
43
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
44
        }
45
46
        return false;
47
    }
48
49
}
50