Skip to content

Commit ee3d57c

Browse files
authored
[TASK] Use native type declarations in OutputFormatter (#964)
Also improve a related type annotation. Part of #811.
1 parent d7d9128 commit ee3d57c

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Please also have a look at our
2626
- Only allow `string` for some `OutputFormat` properties (#885)
2727
- Make all non-private properties `@internal` (#886)
2828
- Use more native type declarations and strict mode
29-
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933)
29+
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
30+
#964)
3031
- Add visibility to all class/interface constants (#469)
3132

3233
### Deprecated

config/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ parameters:
120120
count: 4
121121
path: ../src/OutputFormat.php
122122

123-
-
124-
message: '#^Parameters should have "string" types as the only types passed to this method$#'
125-
identifier: typePerfect.narrowPublicClassMethodParamType
126-
count: 3
127-
path: ../src/OutputFormatter.php
128-
129123
-
130124
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
131125
identifier: parameter.defaultValue

src/OutputFormat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public function set($aNames, $mValue)
284284
}
285285

286286
/**
287+
* @param non-empty-string $sMethodName
287288
* @param array<array-key, mixed> $aArguments
288289
*
289290
* @return mixed

src/OutputFormatter.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ public function __construct(OutputFormat $outputFormat)
1919
$this->outputFormat = $outputFormat;
2020
}
2121

22-
/**
23-
* @param string $sName
24-
* @param string|null $sType
25-
*/
26-
public function space($sName, $sType = null): string
22+
public function space(string $sName, ?string $sType = null): string
2723
{
2824
$sSpaceString = $this->outputFormat->get("Space$sName");
2925
// If $sSpaceString is an array, we have multiple values configured
@@ -78,9 +74,6 @@ public function spaceBeforeSelectorSeparator(): string
7874
return $this->space('BeforeSelectorSeparator');
7975
}
8076

81-
/**
82-
* @return string
83-
*/
8477
public function spaceAfterSelectorSeparator(): string
8578
{
8679
return $this->space('AfterSelectorSeparator');
@@ -89,7 +82,7 @@ public function spaceAfterSelectorSeparator(): string
8982
/**
9083
* @param non-empty-string $sSeparator
9184
*/
92-
public function spaceBeforeListArgumentSeparator($sSeparator): string
85+
public function spaceBeforeListArgumentSeparator(string $sSeparator): string
9386
{
9487
$spaceForSeparator = $this->outputFormat->getSpaceBeforeListArgumentSeparators();
9588

@@ -99,7 +92,7 @@ public function spaceBeforeListArgumentSeparator($sSeparator): string
9992
/**
10093
* @param non-empty-string $sSeparator
10194
*/
102-
public function spaceAfterListArgumentSeparator($sSeparator): string
95+
public function spaceAfterListArgumentSeparator(string $sSeparator): string
10396
{
10497
$spaceForSeparator = $this->outputFormat->getSpaceAfterListArgumentSeparators();
10598

@@ -112,13 +105,9 @@ public function spaceBeforeOpeningBrace(): string
112105
}
113106

114107
/**
115-
* Runs the given code, either swallowing or passing exceptions, depending on the `bIgnoreExceptions` setting.
116-
*
117-
* @param string $cCode the name of the function to call
118-
*
119-
* @return string|null
108+
* Runs the given code, either swallowing or passing exceptions, depending on the `ignoreExceptions` setting.
120109
*/
121-
public function safely($cCode)
110+
public function safely(callable $cCode): ?string
122111
{
123112
if ($this->outputFormat->get('IgnoreExceptions')) {
124113
// If output exceptions are ignored, run the code with exception guards
@@ -137,9 +126,8 @@ public function safely($cCode)
137126
* Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`.
138127
*
139128
* @param array<array-key, Renderable|string> $aValues
140-
* @param bool $bIncreaseLevel
141129
*/
142-
public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = false): string
130+
public function implode(string $sSeparator, array $aValues, bool $bIncreaseLevel = false): string
143131
{
144132
$result = '';
145133
$outputFormat = $this->outputFormat;
@@ -162,12 +150,7 @@ public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = fa
162150
return $result;
163151
}
164152

165-
/**
166-
* @param string $sString
167-
*
168-
* @return string
169-
*/
170-
public function removeLastSemicolon($sString)
153+
public function removeLastSemicolon(string $sString): string
171154
{
172155
if ($this->outputFormat->get('SemicolonAfterLastRule')) {
173156
return $sString;
@@ -199,17 +182,11 @@ public function comments(Commentable $oCommentable): string
199182
return $result;
200183
}
201184

202-
/**
203-
* @param string $sSpaceString
204-
*/
205-
private function prepareSpace($sSpaceString): string
185+
private function prepareSpace(string $sSpaceString): string
206186
{
207187
return \str_replace("\n", "\n" . $this->indent(), $sSpaceString);
208188
}
209189

210-
/**
211-
* @return string
212-
*/
213190
private function indent(): string
214191
{
215192
return \str_repeat($this->outputFormat->sIndentation, $this->outputFormat->getIndentationLevel());

0 commit comments

Comments
 (0)