Passed
Push — master ( 1564fa...d2ad69 )
by Kacper
03:00 queued 15s
created

WordMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 36
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 26 4
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2015, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Matcher;
17
18
19
class WordMatcher extends RegexMatcher
20
{
21
22
    /**
23
     * WordMatcher constructor.
24
     *
25
     * @param array $words
26
     * @param array $options
27
     */
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
}