1 | <?php |
||
12 | class Cli |
||
13 | { |
||
14 | const VERSION = '0.8.0'; |
||
15 | |||
16 | /** |
||
17 | * @var CLImate |
||
18 | */ |
||
19 | private $cli; |
||
20 | |||
21 | /** |
||
22 | * @var \PhpParser\Parser |
||
23 | */ |
||
24 | private $parser; |
||
25 | |||
26 | 8 | private function createParser() |
|
31 | |||
32 | 8 | public function __construct(CLImate $cli) |
|
67 | |||
68 | /** |
||
69 | * @param array $args |
||
70 | * @return int |
||
71 | */ |
||
72 | 8 | public function handle(array $args) |
|
73 | { |
||
74 | try { |
||
75 | 8 | $this->cli->arguments->parse($args); |
|
76 | 1 | } catch (\Exception $e) { |
|
77 | 1 | $this->cli->usage($args); |
|
78 | 1 | return 100; |
|
79 | } |
||
80 | |||
81 | 7 | if ($this->cli->arguments->defined('version')) { |
|
82 | 1 | $this->cli->out(Cli::VERSION); |
|
83 | 1 | return 0; |
|
84 | } |
||
85 | |||
86 | 6 | $this->cli->out(sprintf('PHPAssumptions analyser v%s by @rskuipers', Cli::VERSION))->br(); |
|
87 | |||
88 | 6 | $target = $this->cli->arguments->get('path'); |
|
89 | |||
90 | 6 | if (!is_string($target)) { |
|
91 | $this->cli->error('Missing target path')->br(); |
||
92 | $this->cli->usage($args); |
||
93 | return 100; |
||
94 | } |
||
95 | |||
96 | 6 | switch ($this->cli->arguments->get('format')) { |
|
97 | 6 | case 'xml': |
|
98 | 1 | $output = new XmlOutput($this->cli, $this->cli->arguments->get('output')); |
|
99 | 1 | break; |
|
100 | default: |
||
101 | 5 | $output = new PrettyOutput($this->cli); |
|
102 | 5 | break; |
|
103 | } |
||
104 | |||
105 | 6 | $excludes = $this->getPathsFromList($this->cli->arguments->get('exclude')); |
|
106 | |||
107 | 6 | $nodeTraverser = new NodeTraverser(); |
|
108 | |||
109 | 6 | $analyser = new Analyser( |
|
110 | 6 | $this->parser, |
|
|
|||
111 | $nodeTraverser, |
||
112 | $excludes |
||
113 | ); |
||
114 | |||
115 | 6 | $nodeTraverser->addVisitor(new NodeVisitor($analyser, new Detector())); |
|
116 | |||
117 | 6 | $target = $this->cli->arguments->get('path'); |
|
118 | 6 | $targets = $this->getPaths($target); |
|
119 | |||
120 | 6 | $result = $analyser->analyse($targets); |
|
121 | |||
122 | 6 | $output->output($result); |
|
123 | |||
124 | 6 | if ($result->getAssumptionsCount() > 0) { |
|
125 | 4 | return 110; |
|
126 | } |
||
127 | |||
128 | 2 | return 0; |
|
129 | } |
||
130 | |||
131 | /** |
||
132 | * @param string $list |
||
133 | * @return array |
||
134 | */ |
||
135 | 6 | private function getPathsFromList($list) |
|
147 | |||
148 | /** |
||
149 | * @param string $fromPath |
||
150 | * @return array |
||
151 | */ |
||
152 | 6 | private function getPaths($fromPath) |
|
169 | } |
||
170 |
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.