Test Failed
Push — master ( e3b206...99d1d4 )
by Enjoys
02:23 queued 23s
created

RequiredCheck   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 11
cp 0
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
    public function __construct(false|UploadedFileInterface $value, Ruleable $element, string $message = null)
17
    {
18
        $this->value = $value;
19
        $this->element = $element;
20
        $this->message = $message;
21
    }
22
23
    public function check(): bool
24
    {
25
        if (is_null($this->message)) {
26
            $this->message = 'Выберите файл для загрузки';
27
        }
28
29
        if ($this->value === false || $this->value->getError() == \UPLOAD_ERR_NO_FILE) {
30
            $this->element->setRuleError($this->message);
31
            return false;
32
        }
33
34
        return true;
35
    }
36
}
37