Skip to content

Commit 2db8991

Browse files
authored
[TASK] Add native type declarations for Rule (#1190)
Part of #811
1 parent e89a90c commit 2db8991

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Please also have a look at our
3535
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
3636
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
3737
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186,
38-
#1187)
38+
#1187, #1190)
3939
- Add visibility to all class/interface constants (#469)
4040

4141
### Deprecated

config/phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ parameters:
3636
count: 1
3737
path: ../src/Rule/Rule.php
3838

39-
-
40-
message: '#^Parameters should have "bool" types as the only types passed to this method$#'
41-
identifier: typePerfect.narrowPublicClassMethodParamType
42-
count: 1
43-
path: ../src/Rule/Rule.php
44-
45-
-
46-
message: '#^Parameters should have "int\|int" types as the only types passed to this method$#'
47-
identifier: typePerfect.narrowPublicClassMethodParamType
48-
count: 1
49-
path: ../src/Rule/Rule.php
50-
5139
-
5240
message: '#^Only booleans are allowed in an if condition, string given\.$#'
5341
identifier: if.condNotBoolean

src/Parsing/ParserState.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function setPosition(int $position): void
107107
}
108108

109109
/**
110+
* @return non-empty-string
111+
*
110112
* @throws UnexpectedTokenException
111113
*/
112114
public function parseIdentifier(bool $ignoreCase = true): string

src/Rule/Rule.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Rule implements Renderable, Commentable
2323
{
2424
/**
25-
* @var string
25+
* @var non-empty-string
2626
*/
2727
private $rule;
2828

@@ -42,7 +42,7 @@ class Rule implements Renderable, Commentable
4242
protected $lineNumber;
4343

4444
/**
45-
* @var int
45+
* @var int<0, max>
4646
*
4747
* @internal since 8.8.0
4848
*/
@@ -56,11 +56,11 @@ class Rule implements Renderable, Commentable
5656
protected $comments = [];
5757

5858
/**
59-
* @param string $rule
59+
* @param non-empty-string $rule
6060
* @param int<0, max> $lineNumber
61-
* @param int $columnNumber
61+
* @param int<0, max> $columnNumber
6262
*/
63-
public function __construct($rule, int $lineNumber = 0, $columnNumber = 0)
63+
public function __construct(string $rule, int $lineNumber = 0, int $columnNumber = 0)
6464
{
6565
$this->rule = $rule;
6666
$this->lineNumber = $lineNumber;
@@ -108,11 +108,11 @@ public static function parse(ParserState $parserState, array $commentsBeforeRule
108108
* The first item is the innermost separator (or, put another way, the highest-precedence operator).
109109
* The sequence continues to the outermost separator (or lowest-precedence operator).
110110
*
111-
* @param string $rule
111+
* @param non-empty-string $rule
112112
*
113113
* @return list<non-empty-string>
114114
*/
115-
private static function listDelimiterForRule($rule): array
115+
private static function listDelimiterForRule(string $rule): array
116116
{
117117
if (\preg_match('/^font($|-)/', $rule)) {
118118
return [',', '/', ' '];
@@ -135,35 +135,35 @@ public function getLineNo(): int
135135
}
136136

137137
/**
138-
* @return int
138+
* @return int<0, max>
139139
*/
140-
public function getColNo()
140+
public function getColNo(): int
141141
{
142142
return $this->columnNumber;
143143
}
144144

145145
/**
146146
* @param int<0, max> $lineNumber
147-
* @param int $columnNumber
147+
* @param int<0, max> $columnNumber
148148
*/
149-
public function setPosition(int $lineNumber, $columnNumber): void
149+
public function setPosition(int $lineNumber, int $columnNumber): void
150150
{
151151
$this->columnNumber = $columnNumber;
152152
$this->lineNumber = $lineNumber;
153153
}
154154

155155
/**
156-
* @param string $rule
156+
* @param non-empty-string $rule
157157
*/
158-
public function setRule($rule): void
158+
public function setRule(string $rule): void
159159
{
160160
$this->rule = $rule;
161161
}
162162

163163
/**
164-
* @return string
164+
* @return non-empty-string
165165
*/
166-
public function getRule()
166+
public function getRule(): string
167167
{
168168
return $this->rule;
169169
}
@@ -189,9 +189,8 @@ public function setValue($value): void
189189
* Otherwise, the existing value will be wrapped by one.
190190
*
191191
* @param RuleValueList|array<int, RuleValueList> $value
192-
* @param string $type
193192
*/
194-
public function addValue($value, $type = ' '): void
193+
public function addValue($value, string $type = ' '): void
195194
{
196195
if (!\is_array($value)) {
197196
$value = [$value];
@@ -208,22 +207,19 @@ public function addValue($value, $type = ' '): void
208207
}
209208
}
210209

211-
/**
212-
* @param bool $isImportant
213-
*/
214-
public function setIsImportant($isImportant): void
210+
public function setIsImportant(bool $isImportant): void
215211
{
216212
$this->isImportant = $isImportant;
217213
}
218214

219-
/**
220-
* @return bool
221-
*/
222-
public function getIsImportant()
215+
public function getIsImportant(): bool
223216
{
224217
return $this->isImportant;
225218
}
226219

220+
/**
221+
* @return non-empty-string
222+
*/
227223
public function render(OutputFormat $outputFormat): string
228224
{
229225
$formatter = $outputFormat->getFormatter();

0 commit comments

Comments
 (0)