Skip to content

Navigation Menu

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 258fb73

Browse filesBrowse files
committed
minor #48384 [Console] Fix OutputInterface options int-mask for PHPStan (ogizanagi)
This PR was merged into the 6.2 branch. Discussion ---------- [Console] Fix `OutputInterface` options int-mask for PHPStan | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | N/A When upgrading an application to 6.2, I encountered this issue with PHPStan: ```shell ------ ------------------------------------------------------------------------------------------------------- Line Pilot/Runner/Output/MultiplexingOutput.php ------ ------------------------------------------------------------------------------------------------------- 79 Default value of the parameter #3 $options (0) of method App\Pilot\Runner\Output\MultiplexingOutput::write() is incompatible with type 1|2|4|16|32|64|128|256. ------ ------------------------------------------------------------------------------------------------------- ``` The `MultiplexingOutput` implements the `OutputInterface` and defined `0` as the default value for `$options`: ```php public function write(string|iterable $messages, bool $newline = false, int $options = 0): void ``` as defined by the interface: https://github.com/symfony/symfony/blob/69f46f231b16be1bce1e2ecfa7f9a1fb192cda22/src/Symfony/Component/Console/Output/OutputInterface.php#L40 When trying to use `self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL` as default value: ```shell ------ ------------------------------------------------------------------------------------------------------- Line Pilot/Runner/Output/MultiplexingOutput.php ------ ------------------------------------------------------------------------------------------------------- 79 Default value of the parameter #3 $options (33) of method App\Pilot\Runner\Output\MultiplexingOutput::write() is incompatible with type 1|2|4|16|32|64|128|256. ------ ------------------------------------------------------------------------------------------------------- ``` Or simply using `Output::write()` with specific options: ```shell ------ ------------------------------------------------------------------------------------------------------- Line Pilot/Runner/Output/MultiplexingOutput.php ------ ------------------------------------------------------------------------------------------------------- 81 Parameter #3 $options of method Symfony\Component\Console\Output\Output::write() expects 1|2|4|16|32|64|128|256, 33 given. ------ ------------------------------------------------------------------------------------------------------- ``` Using PHPStan's [`int-mask-of`](https://phpstan.org/writing-php-code/phpdoc-types#integer-masks) is the solution for this, and allows by nature the `0` value. It was even used [at some point](#47016 (comment)), but reverted to use `self::VERBOSITY_*|self::OUTPUT_*`. However, it does not behave as expected for masks. So, either we use `int-mask-of`, or we revert to `int`? Commits ------- 304a17a [Console] Fix OutputInterface options int-mask for PhpStan
2 parents 7300cc9 + 304a17a commit 258fb73
Copy full SHA for 258fb73

File tree

1 file changed

+5
-5
lines changed
Filter options

1 file changed

+5
-5
lines changed

‎src/Symfony/Component/Console/Output/OutputInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Output/OutputInterface.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ interface OutputInterface
3333
/**
3434
* Writes a message to the output.
3535
*
36-
* @param bool $newline Whether to add a newline
37-
* @param self::VERBOSITY_*|self::OUTPUT_* $options A bitmask of options (one of the OUTPUT or VERBOSITY constants),
38-
* 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
36+
* @param bool $newline Whether to add a newline
37+
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants),
38+
* 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
3939
*/
4040
public function write(string|iterable $messages, bool $newline = false, int $options = 0);
4141

4242
/**
4343
* Writes a message to the output and adds a newline at the end.
4444
*
45-
* @param self::VERBOSITY_*|self::OUTPUT_* $options A bitmask of options (one of the OUTPUT or VERBOSITY constants),
46-
* 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
45+
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants),
46+
* 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
4747
*/
4848
public function writeln(string|iterable $messages, int $options = 0);
4949

0 commit comments

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