Skip to content

[CLEANUP] Avoid Hungarian notation for searchPattern #1030

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
Feb 28, 2025
Merged
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
38 changes: 19 additions & 19 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,29 +138,29 @@ public function addRule(Rule $rule, ?Rule $oSibling = null): void
* @example $ruleSet->getRules('font-')
* //returns an array of all rules either beginning with font- or matching font.
*
* @param Rule|string|null $mRule
* @param Rule|string|null $searchPattern
* Pattern to search for. If null, returns all rules.
* If the pattern ends with a dash, all rules starting with the pattern are returned
* as well as one matching the pattern with the dash excluded.
* Passing a Rule behaves like calling `getRules($mRule->getRule())`.
*
* @return array<int, Rule>
*/
public function getRules($mRule = null)
public function getRules($searchPattern = null)
{
if ($mRule instanceof Rule) {
$mRule = $mRule->getRule();
if ($searchPattern instanceof Rule) {
$searchPattern = $searchPattern->getRule();
}
/** @var array<int, Rule> $result */
$result = [];
foreach ($this->rules as $sName => $rules) {
// Either no search rule is given or the search rule matches the found rule exactly
// or the search rule ends in “-” and the found rule starts with the search rule.
if (
!$mRule || $sName === $mRule
!$searchPattern || $sName === $searchPattern
|| (
\strrpos($mRule, '-') === \strlen($mRule) - \strlen('-')
&& (\strpos($sName, $mRule) === 0 || $sName === \substr($mRule, 0, -1))
\strrpos($searchPattern, '-') === \strlen($searchPattern) - \strlen('-')
&& (\strpos($sName, $searchPattern) === 0 || $sName === \substr($searchPattern, 0, -1))
)
) {
$result = \array_merge($result, $rules);
Expand Down Expand Up @@ -196,18 +196,18 @@ public function setRules(array $rules): void
* like `{ background-color: green; background-color; rgba(0, 127, 0, 0.7); }` will only yield an associative array
* containing the rgba-valued rule while `getRules()` would yield an indexed array containing both.
*
* @param Rule|string|null $mRule $mRule
* @param Rule|string|null $searchPattern
* Pattern to search for. If null, returns all rules. If the pattern ends with a dash,
* all rules starting with the pattern are returned as well as one matching the pattern with the dash
* excluded. Passing a Rule behaves like calling `getRules($mRule->getRule())`.
*
* @return array<string, Rule>
*/
public function getRulesAssoc($mRule = null)
public function getRulesAssoc($searchPattern = null)
{
/** @var array<string, Rule> $result */
$result = [];
foreach ($this->getRules($mRule) as $rule) {
foreach ($this->getRules($searchPattern) as $rule) {
$result[$rule->getRule()] = $rule;
}
return $result;
Expand All @@ -222,20 +222,20 @@ public function getRulesAssoc($mRule = null)
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
*
* @param Rule|string|null $mRule
* pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash,
* @param Rule|string|null $searchPattern
* pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
* all rules starting with the pattern are removed as well as one matching the pattern with the dash
* excluded. Passing a Rule behaves matches by identity.
*/
public function removeRule($mRule): void
public function removeRule($searchPattern): void
{
if ($mRule instanceof Rule) {
$sRule = $mRule->getRule();
if ($searchPattern instanceof Rule) {
$sRule = $searchPattern->getRule();
if (!isset($this->rules[$sRule])) {
return;
}
foreach ($this->rules[$sRule] as $key => $rule) {
if ($rule === $mRule) {
if ($rule === $searchPattern) {
unset($this->rules[$sRule][$key]);
}
}
Expand All @@ -245,9 +245,9 @@ public function removeRule($mRule): void
// or the search rule ends in “-” and the found rule starts with the search rule or equals it
// (without the trailing dash).
if (
!$mRule || $sName === $mRule
|| (\strrpos($mRule, '-') === \strlen($mRule) - \strlen('-')
&& (\strpos($sName, $mRule) === 0 || $sName === \substr($mRule, 0, -1)))
!$searchPattern || $sName === $searchPattern
|| (\strrpos($searchPattern, '-') === \strlen($searchPattern) - \strlen('-')
&& (\strpos($sName, $searchPattern) === 0 || $sName === \substr($searchPattern, 0, -1)))
) {
unset($this->rules[$sName]);
}
Expand Down