Passed
Push — main ( 34571b...e79ce9 )
by Breno
01:59
created

FoneSemDDD::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Rules\Brazilian;
5
6
use Attribute;
7
use BrenoRoosevelt\Validation\AbstractValidation;
8
use Throwable;
9
10
#[Attribute(Attribute::TARGET_PROPERTY)]
11
class FoneSemDDD extends AbstractValidation
12
{
13
    const WITH_MASK = '/^\[0-9]{4,5}-[0-9]{4}$/';
14
    const NO_MASK = '/^\[0-9]{8,9}$/';
15
16
    public function __construct(private bool $mask = true, ?string $message = 'Telefone inválido')
17
    {
18
        parent::__construct($message);
19
    }
20
21
    public function evaluate($input, array $context = []): bool
22
    {
23
        try {
24
            $fone = (string) $input;
25
        } catch (Throwable) {
0 ignored issues
show
Unused Code introduced by
catch (\Throwable) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
26
            return false;
27
        }
28
29
        $pattern = $this->mask ? self::WITH_MASK : self::NO_MASK;
30
        return preg_match($pattern, $fone) === 1;
31
    }
32
}
33