Skip to content

Commit

Permalink
refactor: split words by language (#8)
Browse files Browse the repository at this point in the history
This Pull Request splits words by language. It also adds a first version
of the Italian stop-words configuration.

---------

Co-authored-by: JonPurvis <[email protected]>
  • Loading branch information
davideprevosto and JonPurvis authored Aug 16, 2024
1 parent 603ac39 commit eda1382
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/Config/profanities/it.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

// SHOULD ALL WORDS BE lowercase!

return [
'cazzo',
'dioporco',
'dio porco',
'diocane',
'dio cane',
'dio can', // Veneto's version
'porcamadonna',
'porca madonna',
'porcodio',
'porco dio',
'stocazzo',
'vaffanculo',
];
19 changes: 17 additions & 2 deletions src/Expectations/Profanity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@
expect()->extend('toHaveNoProfanity', fn (array $excluding = [], array $including = []): ArchExpectation => Targeted::make(
$this,
function (ObjectDescription $object) use (&$foundWords, $excluding, $including): bool {
$words = include __DIR__.'/../Config/words.php';

$words = [];
$profanitiesDir = __DIR__.'/../Config/profanities';

if (($profanitiesFiles = scandir($profanitiesDir)) === false) {
return true;
}

$profanitiesFiles = array_diff($profanitiesFiles, ['.', '..']);
foreach ($profanitiesFiles as $profanitiesFile) {
$words = array_merge(
$words,
include "$profanitiesDir/$profanitiesFile"
);
}

$toleratedWords = include __DIR__.'/../Config/tolerated.php';

$words = array_merge($words, $including);
Expand All @@ -29,6 +44,6 @@ function (ObjectDescription $object) use (&$foundWords, $excluding, $including):
},
'to not use profanity',
FileLineFinder::where(function (string $line) use (&$foundWords): bool {
return str_contains(strtolower($line), strtolower(array_values($foundWords ?? [])[0]));
return str_contains(strtolower($line), strtolower((string) array_values($foundWords ?? [])[0]));
})
));

0 comments on commit eda1382

Please sign in to comment.