-
Notifications
You must be signed in to change notification settings - Fork 144
[TASK] Use native type declarations in OutputFormatter
#964
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,7 @@ public function __construct(OutputFormat $outputFormat) | |
$this->outputFormat = $outputFormat; | ||
} | ||
|
||
/** | ||
* @param string $sName | ||
* @param string|null $sType | ||
*/ | ||
public function space($sName, $sType = null): string | ||
public function space(string $sName, ?string $sType = null): string | ||
{ | ||
$sSpaceString = $this->outputFormat->get("Space$sName"); | ||
// If $sSpaceString is an array, we have multiple values configured | ||
|
@@ -78,9 +74,6 @@ public function spaceBeforeSelectorSeparator(): string | |
return $this->space('BeforeSelectorSeparator'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function spaceAfterSelectorSeparator(): string | ||
{ | ||
return $this->space('AfterSelectorSeparator'); | ||
|
@@ -89,7 +82,7 @@ public function spaceAfterSelectorSeparator(): string | |
/** | ||
* @param non-empty-string $sSeparator | ||
*/ | ||
public function spaceBeforeListArgumentSeparator($sSeparator): string | ||
public function spaceBeforeListArgumentSeparator(string $sSeparator): string | ||
{ | ||
$spaceForSeparator = $this->outputFormat->getSpaceBeforeListArgumentSeparators(); | ||
|
||
|
@@ -99,7 +92,7 @@ public function spaceBeforeListArgumentSeparator($sSeparator): string | |
/** | ||
* @param non-empty-string $sSeparator | ||
*/ | ||
public function spaceAfterListArgumentSeparator($sSeparator): string | ||
public function spaceAfterListArgumentSeparator(string $sSeparator): string | ||
{ | ||
$spaceForSeparator = $this->outputFormat->getSpaceAfterListArgumentSeparators(); | ||
|
||
|
@@ -112,13 +105,9 @@ public function spaceBeforeOpeningBrace(): string | |
} | ||
|
||
/** | ||
* Runs the given code, either swallowing or passing exceptions, depending on the `bIgnoreExceptions` setting. | ||
* | ||
* @param string $cCode the name of the function to call | ||
* | ||
* @return string|null | ||
* Runs the given code, either swallowing or passing exceptions, depending on the `ignoreExceptions` setting. | ||
*/ | ||
public function safely($cCode) | ||
public function safely(callable $cCode): ?string | ||
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. 👍 |
||
{ | ||
if ($this->outputFormat->get('IgnoreExceptions')) { | ||
// If output exceptions are ignored, run the code with exception guards | ||
|
@@ -137,9 +126,8 @@ public function safely($cCode) | |
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`. | ||
* | ||
* @param array<array-key, Renderable|string> $aValues | ||
* @param bool $bIncreaseLevel | ||
*/ | ||
public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = false): string | ||
public function implode(string $sSeparator, array $aValues, bool $bIncreaseLevel = false): string | ||
{ | ||
$result = ''; | ||
$outputFormat = $this->outputFormat; | ||
|
@@ -162,12 +150,7 @@ public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = fa | |
return $result; | ||
} | ||
|
||
/** | ||
* @param string $sString | ||
* | ||
* @return string | ||
*/ | ||
public function removeLastSemicolon($sString) | ||
public function removeLastSemicolon(string $sString): string | ||
{ | ||
if ($this->outputFormat->get('SemicolonAfterLastRule')) { | ||
return $sString; | ||
|
@@ -199,17 +182,11 @@ public function comments(Commentable $oCommentable): string | |
return $result; | ||
} | ||
|
||
/** | ||
* @param string $sSpaceString | ||
*/ | ||
private function prepareSpace($sSpaceString): string | ||
private function prepareSpace(string $sSpaceString): string | ||
{ | ||
return \str_replace("\n", "\n" . $this->indent(), $sSpaceString); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function indent(): string | ||
{ | ||
return \str_repeat($this->outputFormat->sIndentation, $this->outputFormat->getIndentationLevel()); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for adding #958.