Passed
Pull Request — main (#6)
by Viktor
35:45 queued 27:24
created

Pattern::getMessage()   A

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 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace PrinsFrank\PhpStrictModels\Rule;
5
6
use Attribute;
7
use PrinsFrank\PhpStrictModels\Enum\Type;
8
9
#[Attribute]
10
class Pattern implements Rule
11
{
12 1
    public function __construct(private string $pattern) {}
13
14
    /** @return Type[] */
15 1
    public function applicableToTypes(): array
16
    {
17 1
        return [Type::string];
18
    }
19
20
    /** @param string $value */
21 1
    public function isValid(mixed $value): bool
22
    {
23 1
        return preg_match($this->pattern, $value) === 1;
24
    }
25
26 1
    public function getMessage(): string
27
    {
28 1
        return 'Should follow pattern "' . $this->pattern . '"';
29
    }
30
}
31