Completed
Push — master ( 69d052...8e3b2f )
by Michał
02:14
created

Argv::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php namespace nyx\console\input\formats;
2
3
// Internal dependencies
4
use nyx\console;
5
6
/**
7
 * Argv Input
8
 *
9
 * Note: When passing an argv array yourself, ensure it does not contain the scriptname (when using $_SERVER['argv']
10
 * it will be present as the first element).
11
 *
12
 * @version     0.1.0
13
 * @author      Michal Chojnacki <[email protected]>
14
 * @copyright   2012-2017 Nyx Dev Team
15
 * @link        https://github.com/unyx/nyx
16
 */
17
class Argv extends console\Input
18
{
19
    /**
20
     * @var lexers\ArgvToCollections    The token parser to be used.
21
     */
22
    private $lexer;
23
24
    /**
25
     * Constructs a new Argv Input instance.
26
     *
27
     * @param   array                       $parameters An array of parameters (in the argv format).
28
     * @param   lexers\ArgvToCollections    $lexer      A Argv to Collections Lexer instance.
29
     */
30
    public function __construct(array $parameters = null, lexers\ArgvToCollections $lexer = null)
31
    {
32
        // If no arguments were passed, let's use the globals returned by the CLI SAPI.
33
        if (!isset($parameters)) {
34
            $parameters = $_SERVER['argv'];
35
36
            // Strip the script name from the arguments.
37
            array_shift($parameters);
38
        }
39
40
        $this->lexer = $lexer;
41
        $this->raw   = new tokens\Argv($parameters);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function parse() : console\Input
48
    {
49
        // Instantiate a Lexer if none has been defined yet.
50
        if (!isset($this->lexer)) {
51
            $this->lexer = new lexers\ArgvToCollections;
52
        }
53
54
        // Fill our parameter value collections with the parsed input.
55
        $this->lexer->fill($this->arguments(), $this->options(), $this->raw);
0 ignored issues
show
Compatibility introduced by
$this->raw of type object<nyx\console\input...mats\interfaces\Tokens> is not a sub-type of object<nyx\console\input\formats\tokens\Argv>. It seems like you assume a concrete implementation of the interface nyx\console\input\formats\interfaces\Tokens to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
56
57
        return $this;
58
    }
59
}
60