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
|
|
|
/** |
10
|
|
|
* Class PhpspecCommand |
11
|
|
|
* @package Magestead\Command |
12
|
|
|
*/ |
13
|
|
View Code Duplication |
class PhpspecCommand extends Command |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
protected $_projectPath; |
16
|
|
|
|
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this->_projectPath = getcwd(); |
20
|
|
|
|
21
|
|
|
$this->setName("phpspec"); |
22
|
|
|
$this->setDescription("Run PHPSpec against your project"); |
23
|
|
|
$this->addArgument('option', InputArgument::OPTIONAL, 'Add options to run'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param InputInterface $input |
28
|
|
|
* @param OutputInterface $output |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
|
|
$option = $input->getArgument('option'); |
34
|
|
|
|
35
|
|
|
$command = $this->getCommand(new Config($output), $option); |
36
|
|
|
if (!$command) { |
37
|
|
|
return $output->writeln('<error>Command not available for this application</error>'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$output->writeln('<info>Running PHPSpec</info>'); |
41
|
|
|
$passedCommand = "vagrant ssh -c '". $command ."'"; |
42
|
|
|
passthru($passedCommand); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Config $config |
47
|
|
|
* @param $option |
48
|
|
|
* @return bool|string |
49
|
|
|
*/ |
50
|
|
|
protected function getCommand(Config $config, $option) |
51
|
|
|
{ |
52
|
|
|
$type = $config->type; |
|
|
|
|
53
|
|
|
switch ($type) { |
54
|
|
|
case 'magento': |
55
|
|
|
return "cd /var/www;bin/phpspec $option"; |
56
|
|
|
break; |
|
|
|
|
57
|
|
|
case 'magento2': |
58
|
|
|
return "cd /var/www/public;bin/phpspec $option"; |
59
|
|
|
break; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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.