Completed
Push — master ( 2c2534...8be39a )
by Pablo
02:42
created

PhpMd/Infrastructure/Tool/PhpMdToolProcessor.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PhpGitHooks\Module\PhpMd\Infrastructure\Tool;
4
5
use PhpGitHooks\Infrastructure\Tool\ToolPathFinder;
6
use PhpGitHooks\Module\PhpMd\Model\PhpMdToolProcessorInterface;
7
use Symfony\Component\Process\Process;
8
9
class PhpMdToolProcessor implements PhpMdToolProcessorInterface
10
{
11
    /**
12
     * @var ToolPathFinder
13
     */
14
    private $toolPathFinder;
15
16
    /**
17
     * PhpMdToolProcessor constructor.
18
     *
19
     * @param ToolPathFinder $toolPathFinder
20
     */
21
    public function __construct(ToolPathFinder $toolPathFinder)
22
    {
23
        $this->toolPathFinder = $toolPathFinder;
24
    }
25
26
    /**
27
     * @param string $file
28
     * @param string $options
29
     *
30
     * @return string
31
     */
32
    public function process($file, $options)
33
    {
34
        $process = $this->execute($file, $options);
35
36
        return $this->setError($process);
37
    }
38
39
    /**
40
     * @param string $file
41
     * @param string $options
42
     *
43
     * @return Process
44
     */
45
    private function execute($file, $options)
46
    {
47
        $command = sprintf('php %s %s text ./PmdRules.xml %s', $this->toolPathFinder->find('phpmd'), $file, $options);
48
49
        $process = new Process($command);
50
        $process->run();
51
52
        return $process;
53
    }
54
55
    /**
56
     * @param Process $process
57
     *
58
     * @return null|string
59
     *
60
     * @throws \Symfony\Component\Process\Exception\LogicException
61
     */
62 View Code Duplication
    private function setError(Process $process)
0 ignored issues
show
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...
63
    {
64
        if (false === $process->isSuccessful()) {
65
            return $process->getErrorOutput() ?: $process->getOutput();
66
        }
67
68
        return null;
69
    }
70
}
71