| Conditions | 5 |
| Paths | 16 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 5.0113 |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | 5 | public function __construct(array $words, array $options = []) |
|
| 28 | { |
||
| 29 | 5 | $options = array_merge([ |
|
| 30 | 5 | 'escape' => true, |
|
| 31 | 5 | 'atomic' => false, |
|
| 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['atomic']) { |
|
| 44 | $regex = "(?>$regex)"; |
||
| 45 | } |
||
| 46 | 5 | $regex = "($regex)"; |
|
| 47 | |||
| 48 | 5 | if ($options['separated']) { |
|
| 49 | 4 | $regex = "\\b$regex\\b"; |
|
| 50 | 4 | } |
|
| 51 | |||
| 52 | 5 | $regex = "/$regex/"; |
|
| 53 | 5 | if (!$options['case-sensitivity']) { |
|
| 54 | 4 | $regex .= 'i'; |
|
| 55 | 4 | } |
|
| 56 | |||
| 57 | 5 | parent::__construct($regex); |
|
| 58 | 5 | } |
|
| 59 | } |
||
| 60 |