Failed Conditions
Pull Request — master (#97)
by Jonathan
02:10
created

Pattern   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRegex() 0 7 2
A getPattern() 0 3 1
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 535
    public function __construct(string $pattern)
15
    {
16 535
        $this->pattern = $pattern;
17 535
    }
18
19 509
    public function getPattern() : string
20
    {
21 509
        return $this->pattern;
22
    }
23
24 177
    public function getRegex() : string
25
    {
26 177
        if ($this->pattern[0] === '/') {
27 4
            return $this->pattern;
28
        }
29
30 173
        return '/' . $this->pattern . '/i';
31
    }
32
33 177
    public function matches(string $word) : bool
34
    {
35 177
        return preg_match($this->getRegex(), $word) !== 0;
36
    }
37
}
38