Conditions | 5 |
Paths | 16 |
Total Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Tests | 28 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
29 | 12 | public function __construct(array $words, array $options = []) |
|
30 | { |
||
31 | 12 | $this->words = $words; |
|
32 | 12 | $this->options = $options; |
|
33 | |||
34 | 12 | $options = array_merge([ |
|
35 | 12 | 'escape' => true, |
|
36 | 12 | 'atomic' => false, |
|
37 | 12 | 'separated' => true, |
|
38 | 12 | 'case-sensitivity' => false, |
|
39 | 12 | ], $options); |
|
40 | |||
41 | 12 | if ($options['escape']) { |
|
42 | 11 | $words = array_map(function ($word) { |
|
43 | 11 | return preg_quote($word, '/'); |
|
44 | 11 | }, $words); |
|
45 | 11 | } |
|
46 | |||
47 | 12 | $regex = implode('|', $words); |
|
48 | 12 | if ($options['atomic']) { |
|
49 | 4 | $regex = "(?>$regex)"; |
|
50 | 4 | } |
|
51 | 12 | $regex = "($regex)"; |
|
52 | |||
53 | 12 | if ($options['separated']) { |
|
54 | 7 | $regex = "\\b$regex\\b"; |
|
55 | 7 | } |
|
56 | |||
57 | 12 | $regex = "/$regex/"; |
|
58 | 12 | if (!$options['case-sensitivity']) { |
|
59 | 11 | $regex .= 'i'; |
|
60 | 11 | } |
|
61 | |||
62 | 12 | parent::__construct($regex); |
|
63 | 12 | } |
|
64 | |||
85 |