1 | <?php |
||
90 | class StdinHandler |
||
91 | { |
||
92 | protected $path; |
||
93 | protected $stream; |
||
94 | |||
95 | public static function selectStream(InputInterface $input, $optionOrArg) |
||
101 | |||
102 | /** |
||
103 | * hasPath returns 'true' if the stdin handler has a path to a file. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function hasPath() |
||
112 | |||
113 | /** |
||
114 | * hasStream returns 'true' if the stdin handler has opened a stream. |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function hasStream() |
||
122 | |||
123 | /** |
||
124 | * path returns the path to any file that was set as a redirection |
||
125 | * source, or `php://stdin` if none have been. |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function path() |
||
133 | |||
134 | /** |
||
135 | * close closes the input stream if it was opened. |
||
136 | */ |
||
137 | public function close() |
||
145 | |||
146 | /** |
||
147 | * redirect specifies a path to a file that should serve as the |
||
148 | * source to read from. If the input path is '-' or empty, |
||
149 | * then output will be taken from php://stdin (or whichever source |
||
150 | * was provided via the 'redirect' method). |
||
151 | * |
||
152 | * @return $this |
||
153 | */ |
||
154 | public function redirect($path) |
||
162 | |||
163 | /** |
||
164 | * select chooses the source of the input stream based on whether or |
||
165 | * not the user provided the specified option or argument on the commandline. |
||
166 | * Stdin is selected if there is no user selection. |
||
167 | * |
||
168 | * @param InputInterface $input |
||
169 | * @param string $optionOrArg |
||
170 | * @return $this |
||
171 | */ |
||
172 | public function select(InputInterface $input, $optionOrArg) |
||
181 | |||
182 | /** |
||
183 | * getStream opens and returns the stdin stream (or redirect file). |
||
184 | */ |
||
185 | public function getStream() |
||
192 | |||
193 | /** |
||
194 | * setStream functions like 'select', and also sets up the $input |
||
195 | * object to read from the selected input stream e.g. when used |
||
196 | * with a question helper. |
||
197 | */ |
||
198 | public function setStream(InputInterface $input, $optionOrArg) |
||
207 | |||
208 | /** |
||
209 | * contents reads the entire contents of the standard input stream. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function contents() |
||
227 | |||
228 | /** |
||
229 | * Returns 'true' if a path was specfied, and that path was not '-'. |
||
230 | */ |
||
231 | protected function pathProvided($path) |
||
235 | |||
236 | protected function getOptionOrArg(InputInterface $input, $optionOrArg) |
||
243 | } |
||
244 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.