Skip to content

[TASK] Add native type declarations for RuleSet #1186

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 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Please also have a look at our
- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184)
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181, #1183, #1184, #1186)
- Add visibility to all class/interface constants (#469)

### Deprecated
Expand Down
10 changes: 5 additions & 5 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,13 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void
* as well as one matching the pattern with the dash excluded.
* Passing a `Rule` behaves like calling `getRules($rule->getRule())`.
*
* @return array<int, Rule>
* @return array<int<0, max>, Rule>
*/
public function getRules($searchPattern = null)
public function getRules($searchPattern = null): array
{
if ($searchPattern instanceof Rule) {
$searchPattern = $searchPattern->getRule();
}
/** @var array<int, Rule> $result */
$result = [];
foreach ($this->rules as $propertyName => $rules) {
// Either no search rule is given or the search rule matches the found rule exactly
Expand Down Expand Up @@ -187,7 +186,7 @@ public function getRules($searchPattern = null)
/**
* Overrides all the rules of this set.
*
* @param array<array-key, Rule> $rules The rules to override with.
* @param array<Rule> $rules The rules to override with.
*/
public function setRules(array $rules): void
{
Expand All @@ -212,13 +211,14 @@ public function setRules(array $rules): void
*
* @return array<string, Rule>
*/
public function getRulesAssoc($searchPattern = null)
public function getRulesAssoc($searchPattern = null): array
{
/** @var array<string, Rule> $result */
$result = [];
foreach ($this->getRules($searchPattern) as $rule) {
$result[$rule->getRule()] = $rule;
}

return $result;
}

Expand Down