-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add scalar typehints/return types #23262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
O E377 riginal file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
namespace Symfony\Component\Console\Event; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Exception\InvalidArgumentException; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
|
@@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent | |
private $error; | ||
private $exitCode; | ||
|
||
public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null) | ||
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null) | ||
{ | ||
parent::__construct($command, $input, $output); | ||
|
||
$this->setError($error); | ||
$this->error = $error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be kept as is, BC break otherwise, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure as the class is final, do I miss it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right! |
||
} | ||
|
||
/** | ||
* Returns the thrown error/exception. | ||
* | ||
* @return \Throwable | ||
*/ | ||
public function getError() | ||
public function getError(): \Throwable | ||
{ | ||
return $this->error; | ||
} | ||
|
||
/** | ||
* Replaces the thrown error/exception. | ||
* | ||
* @param \Throwable $error | ||
*/ | ||
public function setError($error) | ||
public function setError(\Throwable $error): void | ||
{ | ||
if (!$error instanceof \Throwable && !$error instanceof \Exception) { | ||
throw new InvalidArgumentException(sprintf('The error passed to ConsoleErrorEvent must be an instance of \Throwable or \Exception, "%s" was passed instead.', is_object($error) ? get_class($error) : gettype($error))); | ||
} | ||
|
||
$this->error = $error; | ||
} | ||
|
||
/** | ||
* Sets the exit code. | ||
* | ||
* @param int $exitCode The command exit code | ||
*/ | ||
public function setExitCode($exitCode) | ||
public function setExitCode(int $exitCode): void | ||
{ | ||
$this->exitCode = (int) $exitCode; | ||
$this->exitCode = $exitCode; | ||
|
||
$r = new \ReflectionProperty($this->error, 'code'); | ||
$r->setAccessible(true); | ||
$r->setValue($this->error, $this->exitCode); | ||
} | ||
|
||
/** | ||
* Gets the exit code. | ||
* | ||
* @return int The command exit code | ||
*/ | ||
public function getExitCode() | ||
public function getExitCode(): int | ||
{ | ||
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason w 106D2 ill be displayed to describe this comment to others. Learn more.
Short array syntax for
$listeners
default value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed #12456 so think the consensus is to keep old style syntax, unless opinions have changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line became very long and hard to read. Please split into multiple lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Please reconsider #18890 ! With scalar type hints and return types, it should be.