Passed
Push — 5.x ( 80f665...fe0c03 )
by Enjoys
57s queued 13s
created

SystemCheck::check()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.9666
cc 3
nc 3
nop 0
crap 3
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 SystemCheck implements UploadCheckInterface
11
{
12
    private UploadedFileInterface|false $value;
13
    private Ruleable $element;
14
    private ?string $message;
15
16 5
    public function __construct(false|UploadedFileInterface $value, Ruleable $element, string $message = null)
17
    {
18 5
        $this->value = $value;
19 5
        $this->element = $element;
20 5
        $this->message = $message;
21
    }
22
23 5
    public function check(): bool
24
    {
25 5
        if ($this->value === false) {
26 2
            return true;
27
        }
28
29 3
        if (!in_array($this->value->getError(), array(\UPLOAD_ERR_OK, \UPLOAD_ERR_NO_FILE))) {
30 1
            $this->message =
31 1
                UploadCheckInterface::UPLOAD_ERROR_MESSAGE[$this->value->getError(
32 1
                )] ?? UploadCheckInterface::UPLOAD_ERROR_MESSAGE['unknown']
33 1
            ;
34 1
            $this->element->setRuleError($this->message);
35 1
            return false;
36
        }
37 2
        return true;
38
    }
39
}
40