8000 feature #23262 Add scalar typehints/return types (chalasr, xabbuh) · symfony/console@ce9c400 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit ce9c400

Browse files
committed
feature #23262 Add scalar typehints/return types (chalasr, xabbuh)
This PR was merged into the 4.0-dev branch. Discussion ---------- Add scalar typehints/return types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no (final, already breaks if doc not respected) | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#23242 (comment) | License | MIT | Doc PR | n/a Commits ------- 7b1715b078 [Yaml] use scalar type hints where possible 6ce70e4bf9 Add scalar typehints/return types on final/internal/private code
2 parents 0269e71 + 9ebe3c2 commit ce9c400

File tree

3 files changed

+56
-172
lines changed

3 files changed

+56
-172
lines changed

Event/ConsoleErrorEvent.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Console\Event;
1313

1414
use Symfony\Component\Console\Command\Command;
15-
use Symfony\Component\Console\Exception\InvalidArgumentException;
1615
use Symfony\Component\Console\Input\InputInterface;
1716
use Symfony\Component\Console\Output\OutputInterface;
1817

@@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent
2625
private $error;
2726
private $exitCode;
2827

29-
public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
28+
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
3029
{
3130
parent::__construct($command, $input, $output);
3231

33-
$this->setError($error);
32+
$this->error = $error;
3433
}
3534

36-
/**
37-
* Returns the thrown error/exception.
38-
*
39-
* @return \Throwable
40-
*/
41-
public function getError()
35+
public function getError(): \Throwable
4236
{
4337
return $this->error;
4438
}
4539

46-
/**
47-
* Replaces the thrown error/exception.
48-
*
49-
* @param \Throwable $error
50-
*/
51-
public function setError($error)
40+
public function setError(\Throwable $error): void
5241
{
53-
if (!$error instanceof \Throwable && !$error instanceof \Exception) {
54-
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)));
55-
}
56-
5742
$this->error = $error;
5843
}
5944

60-
/**
61-
* Sets the exit code.
62-
*
63-
* @param int $exitCode The command exit code
64-
*/
65-
public function setExitCode($exitCode)
45+
public function setExitCode(int $exitCode): void
6646
{
67-
$this->exitCode = (int) $exitCode;
47+
$this->exitCode = $exitCode;
6848

6949
$r = new \ReflectionProperty($this->error, 'code');
7050
$r->setAccessible(true);
7151
$r->setValue($this->error, $this->exitCode);
7252
}
7353

74-
/**
75-
* Gets the exit code.
76-
*
77-
* @return int The command exit code
78-
*/
79-
public function getExitCode()
54+
public function getExitCode(): int
8055
{
8156
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
8257
}

0 commit comments

Comments
 (0)
0