Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f041e03

Browse filesBrowse files
committed
bug #42382 [Console] Add return type to OutputFormatterInterface::format() (derrabus)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Add return type to OutputFormatterInterface::format() | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Spotted while working on #42381. If we look at how `OutputFormatterInterface::format()` is used in the codebase, we can see that an implementation of that method is supposed to return something. Yet the interface does not declare a return value and the `NullOutputFormatter` implementation even has a `void` return type which does not make sense at all, imho. This PR attempts to fix that. Commits ------- d75f5e6 Add return type to OutputFormatterInterface::format()
2 parents c9f821a + d75f5e6 commit f041e03
Copy full SHA for f041e03

File tree

Expand file treeCollapse file tree

3 files changed

+5
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+5
-6
lines changed

‎src/Symfony/Component/Console/Formatter/NullOutputFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Formatter/NullOutputFormatter.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ final class NullOutputFormatter implements OutputFormatterInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function format(?string $message): void
24+
public function format(?string $message): ?string
2525
{
26-
// do nothing
26+
return null;
2727
}
2828

2929
/**

‎src/Symfony/Component/Console/Formatter/OutputFormatterInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Formatter/OutputFormatterInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function getStyle(string $name);
5353

5454
/**
5555
* Formats a message according to the given styles.
56+
*
57+
* @return string|null
5658
*/
5759
public function format(?string $message);
5860
}

‎src/Symfony/Component/Console/Tests/Formatter/NullOutputFormatterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Formatter/NullOutputFormatterTest.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public function testFormat()
2525
{
2626
$formatter = new NullOutputFormatter();
2727

28-
$message = 'this message will not be changed';
29-
$formatter->format($message);
30-
31-
$this->assertSame('this message will not be changed', $message);
28+
$this->assertNull($formatter->format('this message will be destroyed'));
3229
}
3330

3431
public function testGetStyle()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.