Test Failed
Push — main ( 0b8a69...454376 )
by Dimitri
13:28 queued 15s
created

Size::check()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
use Dimtrovich\Validation\Traits\FileTrait;
15
use Rakit\Validation\Rules\Traits\SizeTrait;
16
17
class Size extends AbstractRule
18
{
19
    use SizeTrait;
20
    use FileTrait;
21
22
    /**
23
     * @var array
24
     */
25
    protected $fillableParams = ['size'];
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function check($value): bool
31
    {
32 2
        $this->requireParameters($this->fillableParams);
33
34 2
        $this->setParameterText('size', $size = $this->parameter('size'));
35
36
        if ($this->isValidFileInstance($value)) {
37 2
            $valueSize = $value->getSize() / 1024;
38
        } else {
39
            $valueSize = $this->getValueSize($value);
40
        }
41
42 2
        return (float) $size === (float) $valueSize;
43
    }
44
}
45