Completed
Pull Request — master (#51)
by Greg
02:38
created

CommandData::output()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Consolidation\AnnotatedCommand;
3
4
use Symfony\Component\Console\Input\InputInterface;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
class CommandData
8
{
9
    /** var AnnotationData */
10
    protected $annotatedData;
11
    /** var InputInterface */
12
    protected $input;
13
    /** var OutputInterface */
14
    protected $output;
15
    /** var boolean */
16
    protected $usesInputInterface;
17
    /** var boolean */
18
    protected $usesOutputInterface;
19
20
    public function __construct(
21
        AnnotationData $annotationData,
22
        InputInterface $input,
23
        OutputInterface $output,
24
        $usesInputInterface,
25
        $usesOutputInterface
26
    ) {
27
        $this->annotationData = $annotationData;
0 ignored issues
show
Bug introduced by
The property annotationData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
        $this->input = $input;
29
        $this->output = $output;
30
        $this->usesInputInterface = $usesInputInterface;
31
        $this->usesOutputInterface = $usesOutputInterface;
32
    }
33
34
    public function annotationData()
35
    {
36
        return $this->annotationData;
37
    }
38
39
    public function input()
40
    {
41
        return $this->input;
42
    }
43
44
    public function output()
45
    {
46
        return $this->output;
47
    }
48
49
    public function arguments()
50
    {
51
        return $this->input->getArguments();
52
    }
53
54
    public function options()
55
    {
56
        return $this->input->getOptions();
57
    }
58
59
    public function getArgsWithoutAppName()
60
    {
61
        $args = $this->arguments();
62
63
        // When called via the Application, the first argument
64
        // will be the command name. The Application alters the
65
        // input definition to match, adding a 'command' argument
66
        // to the beginning.
67
        array_shift($args);
68
        return $args;
69
    }
70
71
    public function getArgsAndOptions()
72
    {
73
        // Get passthrough args, and add the options on the end.
74
        $args = $this->getArgsWithoutAppName();
75
        $args['options'] = $this->options();
76
        return $args;
77
    }
78
}
79