RequiredRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 4 1
A errorMessage() 0 3 1
A canSkip() 0 3 1
1
<?php
2
3
4
namespace SolBianca\Validator\Rules;
5
6
7
use SolBianca\Validator\Interfaces\RuleInterface;
8
9
class RequiredRule implements RuleInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function run($value, array $input, array $args): bool
15
    {
16
        $value = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $value);
17
        return !empty($value);
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function errorMessage(): string
24
    {
25
        return 'Field `{field}` is required.';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function canSkip(): bool
32
    {
33
        return true;
34
    }
35
}