Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
4 / 4 |
|
77.78% |
7 / 9 |
|
33.33% |
2 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Regex | |
100.00% |
4 / 4 |
|
77.78% |
7 / 9 |
|
33.33% |
2 / 6 |
|
100.00% |
1 / 1 |
3.19 | |
100.00% |
1 / 1 |
| validate | |
100.00% |
4 / 4 |
|
77.78% |
7 / 9 |
|
33.33% |
2 / 6 |
|
100.00% |
1 / 1 |
3.19 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Sire\Rule; |
| 6 | |
| 7 | use Celemas\Sire\Contract; |
| 8 | use Celemas\Sire\Validation; |
| 9 | use Override; |
| 10 | |
| 11 | /** @api */ |
| 12 | final class Regex implements Contract\Rule |
| 13 | { |
| 14 | public string $message { |
| 15 | get => '{label} has an invalid format'; |
| 16 | } |
| 17 | |
| 18 | #[Override] |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 27 | return Validation::invalid(); |
| 28 | } |
| 29 | |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 31 | } |
| 32 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 15 | get => '{label} has an invalid format'; |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 27 | return Validation::invalid(); |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 31 | } |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 31 | } |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 27 | return Validation::invalid(); |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 31 | } |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | // As regex patterns could contain colons ':' and rule |
| 22 | // args are separated by colons and split at their position |
| 23 | // we need to join them again |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 24 | $pattern = implode(':', $args); |
| 25 | |
| 26 | if ($pattern === '') { |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 30 | return Validation::from(preg_match($pattern, $value->value) === 1); |
| 31 | } |