Pattern::matches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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 1115
    public function __construct(string $pattern)
18
    {
19 1115
        $this->pattern = $pattern;
20
21 1115
        if (isset($this->pattern[0]) && $this->pattern[0] === '/') {
22 245
            $this->regex = $this->pattern;
23
        } else {
24 1114
            $this->regex = '/' . $this->pattern . '/i';
25
        }
26 1115
    }
27
28 1109
    public function getPattern() : string
29
    {
30 1109
        return $this->pattern;
31
    }
32
33 493
    public function getRegex() : string
34
    {
35 493
        return $this->regex;
36
    }
37
38 490
    public function matches(string $word) : bool
39
    {
40 490
        return preg_match($this->getRegex(), $word) === 1;
41
    }
42
}
43