Skip to content

Commit f4c6aa6

Browse files
committed
Throw exception if not instanceof ConsoleOutupuInterface
1 parent 83b430d commit f4c6aa6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

console.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,17 @@ which returns an instance of
196196
protected function execute(InputInterface $input, OutputInterface $output)
197197
{
198198
// The section() method is only available in classes that implement ConsoleOutputInterface
199-
if ($output instanceof ConsoleOutputInterface) {
200-
$section1 = $output->section();
201-
$section2 = $output->section();
202-
} else {
203-
$section1 = $section2 = $output;
199+
if (!$output instanceof ConsoleOutputInterface) {
200+
throw new InvalidArgumentException(sprintf(
201+
'This command accepts only an instance of "%s", an instance of "%s" is given',
202+
ConsoleOutputInterface::class,
203+
\get_class($output)
204+
));
204205
}
205-
206+
207+
$section1 = $output->section();
208+
$section2 = $output->section();
209+
206210
$section1->writeln('Hello');
207211
$section2->writeln('World!');
208212
// Output displays "Hello\nWorld!\n"

0 commit comments

Comments
 (0)