Completed
Pull Request — master (#53)
by
unknown
03:06
created

PhpUnitProcessBuilder::setSuite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace PhpGitHooks\Infrastructure\PhpUnit;
4
5
use PhpGitHooks\Infrastructure\Common\ProcessBuilderInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Process\Process;
8
use Symfony\Component\Process\ProcessBuilder;
9
10
/**
11
 * Class PhpUnitProcessBuilder.
12
 */
13
class PhpUnitProcessBuilder implements ProcessBuilderInterface
14
{
15
    /**
16
     * @var bool|string
17
     */
18
    protected $suite = false;
19
20
    /**
21
     * @return ProcessBuilder
22
     */
23 View Code Duplication
    public function getProcessBuilder()
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...
24
    {
25
        $params = array('php', 'bin/phpunit');
26
        if ($this->suite) {
27
            $params[] = '--testsuite';
28
            $params[] = $this->suite;
29
        }
30
31
        return new ProcessBuilder($params);
0 ignored issues
show
Documentation introduced by
$params is of type array<integer,boolean|string>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
    }
33
34
    /**
35
     * @param $suite
36
     */
37
    public function setSuite($suite)
38
    {
39
        $this->suite = $suite;
40
    }
41
42
    /**
43
     * @param Process         $process
44
     * @param OutputInterface $outputInterface
45
     *
46
     * @return int
47
     */
48
    public function executeProcess(Process $process, OutputInterface $outputInterface)
49
    {
50
        return $process->run(function ($type, $buffer) use ($outputInterface) {
51
            $type;
52
            $outputInterface->write($buffer);
53
        });
54
    }
55
}
56