Passed
Pull Request — master (#97)
by Jonathan
02:13
created

Pattern::getRegex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
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 531
    public function __construct(string $pattern)
15
    {
16 531
        $this->pattern = $pattern;
17 531
    }
18
19 507
    public function getPattern() : string
20
    {
21 507
        return $this->pattern;
22
    }
23
24 166
    public function getRegex() : string
25
    {
26 166
        if ($this->pattern[0] === '/') {
27 2
            return $this->pattern;
28
        }
29
30 164
        return '/' . $this->pattern . '/i';
31
    }
32
33 163
    public function matches(string $word) : bool
34
    {
35 163
        return preg_match($this->getRegex(), $word) === 1;
36
    }
37
}
38