Completed
Push — master ( 70f161...72dc5f )
by Julian
10s
created

Tester::configure()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 1
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
namespace ParaTest\Console\Testers;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Class Tester
11
 *
12
 * A base for Testers. A Tester is a specialized console
13
 * command for controlling a given tool - i.e PHPUnit
14
 *
15
 * @package ParaTest\Console\Testers
16
 */
17
abstract class Tester
18
{
19
    /**
20
     * Configures the ParaTestCommand with Tester specific
21
     * definitions
22
     *
23
     * @param Command $command
24
     * @return mixed
25
     */
26
    abstract public function configure(Command $command);
27
28
    /**
29
     * @param InputInterface $input
30
     * @param OutputInterface $output
31
     * @return mixed
32
     */
33
    abstract public function execute(InputInterface $input, OutputInterface $output);
34
35
    /**
36
     * Returns non-empty options
37
     *
38
     * @param InputInterface $input
39
     * @return array
40
     */
41 4
    protected function getOptions(InputInterface $input)
42
    {
43 4
        $options = $input->getOptions();
44 4
        foreach ($options as $key => $value) {
45 4
            if (empty($options[$key])) {
46 4
                unset($options[$key]);
47 4
            }
48 4
        }
49 4
        return $options;
50
    }
51
52
    /**
53
     * Displays help for the ParaTestCommand
54
     *
55
     * @param InputInterface $input
56
     * @param OutputInterface $output
57
     */
58
    protected function displayHelp(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        $help = $this->command->getApplication()->find('help');
0 ignored issues
show
Bug introduced by
The property command does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
61
        $input = new ArrayInput(array('command_name' => 'paratest'));
62
        $help->run($input, $output);
63
        exit(0);
0 ignored issues
show
Coding Style Compatibility introduced by
The method displayHelp() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
64
    }
65
}
66