Pattern   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 20
ccs 7
cts 7
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A getMessage() 0 3 1
A isValid() 0 3 1
A applicableToTypes() 0 3 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