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

Patterns::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
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 523
    public function __construct(Pattern ...$patterns)
20
    {
21 523
        $this->patterns = $patterns;
22
23
        $patterns = array_map(function (Pattern $word) : string {
24 523
            return $word->getPattern();
25 523
        }, $this->patterns);
26
27 523
        $this->regex = '/^(?:' . implode('|', $patterns) . ')$/i';
28 523
    }
29
30 505
    public function matches(string $word) : bool
31
    {
32 505
        return preg_match($this->regex, $word, $regs) === 1;
33
    }
34
}
35