Skip to content

Commit 26fbd77

Browse files
authored
Refactor ProfanityAnalyser (#68)
After making `en` the default language in 36a3df5, I refactored the `ProfanityAnalyser` accordingly. ### Changes - `$language` can't be string anymore (always array), I changed it's type and also name to `$languages`. - We don't need that line to check if `$languages` is array anymore. - We don't need that for loop anymore, it's one file (`en.php`).
1 parent 14bd3f9 commit 26fbd77

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

src/Analyser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ final class Analyser
1818
* @param \Closure(\Pest\Profanity\Result): void $callback
1919
* @param array<string> $excludingWords
2020
* @param array<string> $includingWords
21-
* @param string|array<string>|null $language
21+
* @param array<string>|null $languages
2222
*/
2323
public static function analyse(
2424
array $files,
2525
Closure $callback,
2626
array $excludingWords = [],
2727
array $includingWords = [],
28-
$language = null
28+
$languages = null
2929
): void {
3030
foreach ($files as $file) {
31-
$errors = ProfanityAnalyser::analyse($file, $excludingWords, $includingWords, $language);
31+
$errors = ProfanityAnalyser::analyse($file, $excludingWords, $includingWords, $languages);
3232
$callback(new Result($file, $errors));
3333
}
3434
}

src/ProfanityAnalyser.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ final class ProfanityAnalyser
1414
*
1515
* @param array<string> $excludingWords
1616
* @param array<string> $includingWords
17-
* @param string|array<string>|null $language
17+
* @param array<string>|null $languages
1818
* @return array<int, Error>
1919
*/
20-
public static function analyse(string $file, array $excludingWords = [], array $includingWords = [], $language = null): array
20+
public static function analyse(string $file, array $excludingWords = [], array $includingWords = [], $languages = null): array
2121
{
2222
$words = [];
2323
$profanitiesDir = __DIR__.'/Config/profanities';
@@ -33,9 +33,7 @@ public static function analyse(string $file, array $excludingWords = [], array $
3333

3434
$profanitiesFiles = array_diff($profanitiesFiles, ['.', '..']);
3535

36-
if ($language) {
37-
$languages = is_array($language) ? $language : [$language];
38-
36+
if ($languages) {
3937
foreach ($languages as $lang) {
4038
$specificLanguage = "$profanitiesDir/$lang.php";
4139
if (file_exists($specificLanguage)) {
@@ -46,12 +44,7 @@ public static function analyse(string $file, array $excludingWords = [], array $
4644
}
4745
}
4846
} else {
49-
foreach ($profanitiesFiles as $profanitiesFile) {
50-
$words = array_merge(
51-
$words,
52-
include "$profanitiesDir/en.php"
53-
);
54-
}
47+
$words = include "$profanitiesDir/en.php";
5548
}
5649

5750
$words = array_merge($words, $includingWords);

0 commit comments

Comments
 (0)