Passed
Pull Request — main (#3)
by
unknown
16:19 queued 13:20
created

Size   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 2
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 4
        $this->requireParameters($this->fillableParams);
33
34 4
        $this->setParameterText('size', $size = $this->parameter('size'));
35
36
        if ($this->isValidFileInstance($value)) {
37 2
            $valueSize = $value->getSize() / 1024;
38
        } else {
39 2
            $valueSize = $this->getValueSize($value);
40
        }
41
42 4
        return (float) $size === (float) $valueSize;
43
    }
44
}
45