| Conditions | 4 |
| Paths | 8 |
| Total Lines | 26 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 4 |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 5 | public function __construct(array $words, array $options = []) |
|
| 29 | { |
||
| 30 | 5 | $options = array_merge([ |
|
| 31 | 5 | 'escape' => true, |
|
| 32 | 5 | 'separated' => true, |
|
| 33 | 5 | 'case-sensitivity' => false, |
|
| 34 | 5 | ], $options); |
|
| 35 | |||
| 36 | 5 | if ($options['escape']) { |
|
| 37 | 4 | $words = array_map(function ($word) { |
|
| 38 | 4 | return preg_quote($word, '/'); |
|
| 39 | 4 | }, $words); |
|
| 40 | 4 | } |
|
| 41 | |||
| 42 | 5 | $regex = '(' . implode('|', $words) . ')'; |
|
| 43 | 5 | if ($options['separated']) { |
|
| 44 | 4 | $regex = '\b' . $regex . '\b'; |
|
| 45 | 4 | } |
|
| 46 | |||
| 47 | 5 | $regex = "/$regex/"; |
|
| 48 | 5 | if (!$options['case-sensitivity']) { |
|
| 49 | 4 | $regex .= 'i'; |
|
| 50 | 4 | } |
|
| 51 | |||
| 52 | 5 | parent::__construct($regex); |
|
| 53 | } |
||
| 54 | } |