Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 7 |
| Civility | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 7 |
| format | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 7 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\DictionaryFormatter\Formatters; |
| 4 | |
| 5 | class Civility |
| 6 | { |
| 7 | |
| 8 | /** |
| 9 | * @var array |
| 10 | */ |
| 11 | protected static $patterns = [ |
| 12 | '0' => ['0', 'f', 'mme', 'mlle', 'femme', 'w'], |
| 13 | '1' => ['1', 'm', 'h', 'mr', 'homme'] |
| 14 | ]; |
| 15 | |
| 16 | /** |
| 17 | * Undocumented function |
| 18 | * |
| 19 | * @param string $value |
| 20 | * @param array|null $patterns |
| 21 | * @return string |
| 22 | */ |
| 23 | public static function format(string $value, array $patterns = null): string |
| 24 | { |
| 25 | if($patterns) { |
| 26 | self::$patterns = $patterns; |
| 27 | } |
| 28 | |
| 29 | $filtered = collect(self::$patterns)->filter(function ($gender) use ($value) { |
| 30 | $value = str_replace('.', '', strtolower($value)); |
| 31 | return in_array((string) $value, $gender); |
| 32 | })->keys()->first(); |
| 33 | |
| 34 | return is_null($filtered) ? (string) $value : (string) $filtered; |
| 35 | } |
| 36 | |
| 37 | } |