Skip to content

Commit 3a784d6

Browse files
staabmondrejmirtes
authored andcommitted
Simplify RegularExpressionPatternRule
1 parent 959a40d commit 3a784d6

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

src/Rules/Regexp/RegularExpressionPatternRule.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,44 @@ private function extractPatterns(FuncCall $functionCall, Scope $scope): array
6363

6464
$patternStrings = [];
6565

66-
foreach ($patternType->getConstantStrings() as $constantStringType) {
67-
if (
68-
!in_array($functionName, [
69-
'preg_match',
70-
'preg_match_all',
71-
'preg_split',
72-
'preg_grep',
73-
'preg_replace',
74-
'preg_replace_callback',
75-
'preg_filter',
76-
], true)
77-
) {
78-
continue;
66+
if (
67+
in_array($functionName, [
68+
'preg_match',
69+
'preg_match_all',
70+
'preg_split',
71+
'preg_grep',
72+
'preg_replace',
73+
'preg_replace_callback',
74+
'preg_filter',
75+
], true)
76+
) {
77+
foreach ($patternType->getConstantStrings() as $constantStringType) {
78+
$patternStrings[] = $constantStringType->getValue();
7979
}
80-
81-
$patternStrings[] = $constantStringType->getValue();
8280
}
8381

84-
foreach ($patternType->getConstantArrays() as $constantArrayType) {
85-
if (
86-
in_array($functionName, [
87-
'preg_replace',
88-
'preg_replace_callback',
89-
'preg_filter',
90-
], true)
91-
) {
82+
if (
83+
in_array($functionName, [
84+
'preg_replace',
85+
'preg_replace_callback',
86+
'preg_filter',
87+
], true)
88+
) {
89+
foreach ($patternType->getConstantArrays() as $constantArrayType) {
9290
foreach ($constantArrayType->getValueTypes() as $arrayKeyType) {
9391
foreach ($arrayKeyType->getConstantStrings() as $constantString) {
9492
$patternStrings[] = $constantString->getValue();
9593
}
9694
}
9795
}
96+
}
9897

99-
if ($functionName !== 'preg_replace_callback_array') {
100-
continue;
101-
}
102-
103-
foreach ($constantArrayType->getKeyTypes() as $arrayKeyType) {
104-
foreach ($arrayKeyType->getConstantStrings() as $constantString) {
105-
$patternStrings[] = $constantString->getValue();
98+
if ($functionName === 'preg_replace_callback_array') {
99+
foreach ($patternType->getConstantArrays() as $constantArrayType) {
100+
foreach ($constantArrayType->getKeyTypes() as $arrayKeyType) {
101+
foreach ($arrayKeyType->getConstantStrings() as $constantString) {
102+
$patternStrings[] = $constantString->getValue();
103+
}
106104
}
107105
}
108106
}

0 commit comments

Comments
 (0)