Completed
Pull Request — master (#97)
by Jonathan
02:39
created

Pattern   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegex() 0 3 1
A getPattern() 0 3 1
A __construct() 0 8 2
A matches() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector\Rules;
6
7
use function preg_match;
8
9
final class Pattern
10
{
11
    /** @var string */
12
    private $pattern;
13
14
    /** @var string */
15
    private $regex;
16
17 531
    public function __construct(string $pattern)
18
    {
19 531
        $this->pattern = $pattern;
20
21 531
        if ($this->pattern[0] === '/') {
22 2
            $this->regex = $this->pattern;
23
        } else {
24 530
            $this->regex = '/' . $this->pattern . '/i';
25
        }
26 531
    }
27
28 525
    public function getPattern() : string
29
    {
30 525
        return $this->pattern;
31
    }
32
33 166
    public function getRegex() : string
34
    {
35 166
        return $this->regex;
36
    }
37
38 163
    public function matches(string $word) : bool
39
    {
40 163
        return preg_match($this->getRegex(), $word) === 1;
41
    }
42
}
43