Patterns::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 array_map;
8
use function implode;
9
use function preg_match;
10
11
class Patterns
12
{
13
    /** @var Pattern[] */
14
    private $patterns;
15
16
    /** @var string */
17
    private $regex;
18
19 1108
    public function __construct(Pattern ...$patterns)
20
    {
21 1108
        $this->patterns = $patterns;
22
23
        $patterns = array_map(static function (Pattern $pattern) : string {
24 1107
            return $pattern->getPattern();
25 1108
        }, $this->patterns);
26
27 1108
        $this->regex = '/^(?:' . implode('|', $patterns) . ')$/i';
28 1108
    }
29
30 1082
    public function matches(string $word) : bool
31
    {
32 1082
        return preg_match($this->regex, $word, $regs) === 1;
33
    }
34
}
35