ProcessFactory::make()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4286
cc 3
eloc 4
nc 2
nop 1
crap 3
1
<?php
2
/**
3
 * File ProcessFactory.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\ProcessQueue\Process;
8
9
use Symfony\Component\Process\Process;
10
11
/**
12
 * Class ProcessFactory
13
 *
14
 * @package Epfremme\ProcessQueue\Process
15
 */
16
class ProcessFactory
17
{
18
    /**
19
     * @var string
20
     */
21
    private $cmd;
22
23
    /**
24
     * ProcessFactory constructor
25
     *
26
     * @param string $cmd
27
     */
28 11
    public function __construct($cmd)
29
    {
30 11
        $this->cmd = $cmd;
31 11
    }
32
33
    /**
34
     * @param \SplFileInfo|string $cwd
35
     * @return Process
36
     */
37 8
    public function make($cwd = null)
38
    {
39 8
        if (!is_null($cwd) && !is_dir($cwd)) {
40 1
            throw new Exception\InvalidWorkingDirectoryException($cwd);
41
        }
42
43 7
        return new Process($this->cmd, $cwd);
0 ignored issues
show
Bug introduced by
It seems like $cwd defined by parameter $cwd on line 37 can also be of type object<SplFileInfo>; however, Symfony\Component\Process\Process::__construct() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
44
    }
45
}
46