HelpAsciiDocHandler::getLessBinary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 Symfony\Component\Process\ExecutableFinder;
15
use Webmozart\Assert\Assert;
16
use Webmozart\Console\Api\Args\Args;
17
use Webmozart\Console\Api\IO\IO;
18
use Webmozart\Console\Process\ProcessLauncher;
19
20
/**
21
 * Displays the application/command help as AsciiDoc.
22
 *
23
 * @since  1.0
24
 *
25
 * @author Bernhard Schussek <[email protected]>
26
 */
27
class HelpAsciiDocHandler
28
{
29
    /**
30
     * @var string
31
     */
32
    private $path;
33
34
    /**
35
     * @var string
36
     */
37
    private $lessBinary;
38
39
    /**
40
     * @var ExecutableFinder
41
     */
42
    private $executableFinder;
43
44
    /**
45
     * @var ProcessLauncher
46
     */
47
    private $processLauncher;
48
49
    /**
50
     * Creates the handler.
51
     *
52
     * @param string           $path             The path to the AsciiDoc file.
53
     * @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...
54
     *                                           "less" binary.
55
     * @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...
56
     *                                           "less" binary.
57
     */
58 17 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...
59
    {
60 17
        Assert::file($path);
61
62 17
        $this->path = $path;
63 17
        $this->executableFinder = $executableFinder ?: new ExecutableFinder();
64 17
        $this->processLauncher = $processLauncher ?: new ProcessLauncher();
65 17
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 15
    public function handle(Args $args, IO $io)
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
71
    {
72 15
        if ($this->processLauncher->isSupported()) {
73 13
            if (!$this->lessBinary) {
74 12
                $this->lessBinary = $this->executableFinder->find('less');
75
            }
76
77 13
            if ($this->lessBinary) {
78 12
                return $this->processLauncher->launchProcess(
79 12
                    escapeshellcmd($this->lessBinary).' %path%',
80 12
                    array('path' => $this->path),
81 12
                    false
82
                );
83
            }
84
        }
85
86 3
        $io->write(file_get_contents($this->path));
87
88 3
        return 0;
89
    }
90
91
    /**
92
     * Returns the "less" binary used to display the AsciiDoc page.
93
     *
94
     * @return string The "less" binary or `null` if the binary is auto-detected.
95
     */
96
    public function getLessBinary()
97
    {
98
        return $this->lessBinary;
99
    }
100
101
    /**
102
     * Sets the "less" binary used to display the AsciiDoc page.
103
     *
104
     * @param string $lessBinary The "less" binary to use.
105
     */
106 12 View Code Duplication
    public function setLessBinary($lessBinary)
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...
107
    {
108 12
        if (null !== $lessBinary) {
109 1
            Assert::string($lessBinary, 'The less binary must be a string or null. Got: %s');
110 1
            Assert::notEmpty($lessBinary, 'The less binary must not be empty.');
111
        }
112
113 12
        $this->lessBinary = $lessBinary;
114 12
    }
115
}
116