RequiredCheck   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 12 4
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms\Rule\UploadCheck;
6
7
use Enjoys\Forms\Interfaces\Ruleable;
8
use Psr\Http\Message\UploadedFileInterface;
9
10
final class RequiredCheck implements UploadCheckInterface
11
{
12
    private UploadedFileInterface|false $value;
13
    private Ruleable $element;
14
    private ?string $message;
15
16 8
    public function __construct(false|UploadedFileInterface $value, Ruleable $element, ?string $message = null)
17
    {
18 8
        $this->value = $value;
19 8
        $this->element = $element;
20 8
        $this->message = $message;
21
    }
22
23 8
    public function check(): bool
24
    {
25 8
        if (is_null($this->message)) {
26 7
            $this->message = 'Выберите файл для загрузки';
27
        }
28
29 8
        if ($this->value === false || $this->value->getError() == \UPLOAD_ERR_NO_FILE) {
30 4
            $this->element->setRuleError($this->message);
31 4
            return false;
32
        }
33
34 4
        return true;
35
    }
36
}
37