Last active
December 24, 2023 15:58
-
-
Save mcsee/0beea3108976e868fdc78292b24ffbf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
private function alreadyIncludesPattern( | |
array $patterns, string $needlePattern): bool { | |
foreach ($patterns as $innerPattern) { | |
if ($needlePattern != $innerPattern && | |
substr_compare | |
($needlePattern, | |
$innerPattern, | |
0, | |
strlen($innerPattern), true) === 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function simplify(array $patterns): array { | |
return array_values(array_filter($patterns, | |
fn ($outerPattern) => $this->alreadyIncludesPattern( | |
$patterns, $outerPattern))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment