HelpManHandler::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 5
nc 4
nop 3
crap 3
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Console\Handler\Help;
13
14
use RuntimeException;
15
use Symfony\Component\Process\ExecutableFinder;
16
use Webmozart\Assert\Assert;
17
use Webmozart\Console\Process\ProcessLauncher;
18
19
/**
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class HelpManHandler
25
{
26
    /**
27
     * @var string
28
     */
29
    private $path;
30
31
    /**
32
     * @var string
33
     */
34
    private $manBinary;
35
36
    /**
37
     * @var ExecutableFinder
38
     */
39
    private $executableFinder;
40
41
    /**
42
     * @var ProcessLauncher
43
     */
44
    private $processLauncher;
45
46
    /**
47
     * Creates a new AsciiDoc descriptor.
48
     *
49
     * @param ExecutableFinder $executableFinder The finder used to find the
0 ignored issues
show
Documentation introduced by
Should the type for parameter $executableFinder not be null|ExecutableFinder?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
50
     *                                           "man" binary.
51
     * @param ProcessLauncher  $processLauncher  The launcher for executing the
0 ignored issues
show
Documentation introduced by
Should the type for parameter $processLauncher not be null|ProcessLauncher?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
52
     *                                           "man" binary.
53
     */
54 19 View Code Duplication
    public function __construct($path, ExecutableFinder $executableFinder = null, ProcessLauncher $processLauncher = null)
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...
55
    {
56 19
        Assert::file($path);
57
58 19
        $this->path = $path;
59 19
        $this->executableFinder = $executableFinder ?: new ExecutableFinder();
60 19
        $this->processLauncher = $processLauncher ?: new ProcessLauncher();
61 19
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 17
    public function handle()
67
    {
68 17
        if (!$this->processLauncher->isSupported()) {
69 1
            throw new RuntimeException('The ProcessLauncher must be supported for the man help to run.');
70
        }
71
72 16
        if (!$this->manBinary) {
73 10
            $this->manBinary = $this->executableFinder->find('man');
74
        }
75
76 16
        if (!$this->manBinary) {
77 1
            throw new RuntimeException('The "man" binary was not found.');
78
        }
79
80 15
        return $this->processLauncher->launchProcess(
81 15
            escapeshellcmd($this->manBinary).' -l %path%',
82 15
            array('path' => $this->path),
83 15
            false
84
        );
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getManBinary()
91
    {
92
        return $this->manBinary;
93
    }
94
95
    /**
96
     * @param string $manBinary
97
     */
98 14
    public function setManBinary($manBinary)
99
    {
100 14
        $this->manBinary = $manBinary;
101 14
    }
102
}
103