ValidatorImpl   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMessage() 0 3 1
1
<?php
2
/**
3
 * @author    Nurlan Mukhanov <[email protected]>
4
 * @copyright 2022 Nurlan Mukhanov
5
 * @license   https://en.wikipedia.org/wiki/MIT_License MIT License
6
 * @link      https://github.com/Falseclock/service-layer
7
 */
8
9
declare(strict_types=1);
10
11
namespace Falseclock\Service\Validation;
12
13
abstract class ValidatorImpl implements Validator
14
{
15
    /**
16
     * @var mixed Значение переменной устанавливается динамически
17
     * @see ValidationProcessImpl::validate()
18
     */
19
    public $value;
20
    /** @var string|null Error message */
21
    protected $message;
22
    /** @var bool */
23
    protected $nullable = false;
24
25
    /**
26
     * Validator constructor.
27
     *
28
     * @param string|null $message
29
     */
30
    public function __construct(string $message, ?bool $nullable = false)
31
    {
32
        $this->nullable = $nullable;
33
        $this->message = $message;
34
    }
35
36
    /**
37
     * @return ValidatorError
38
     */
39
    public function getMessage(): ValidatorError
40
    {
41
        return new ValidatorError($this->message, $this->value);
0 ignored issues
show
Bug introduced by
It seems like $this->message can also be of type null; however, parameter $message of Falseclock\Service\Valid...torError::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        return new ValidatorError(/** @scrutinizer ignore-type */ $this->message, $this->value);
Loading history...
42
    }
43
}
44