WidthBetweenRule::validateMediaItem()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Rules\ItemRules;
4
5
class WidthBetweenRule extends MediaItemRule
6
{
7
    public function __construct(
8
        protected int $minWidth = 0,
9
        protected int $maxWidth = 0
10
    ) {
11
    }
12
13
    public function validateMediaItem(): bool
14
    {
15
        if (! $media = $this->getTemporaryUploadMedia()) {
16
            return true;
17
        }
18
19
        $size = getimagesize($media->getPath());
20
        $actualWidth = $size[0];
21
22
        return $actualWidth >= $this->minWidth && $actualWidth <= $this->maxWidth;
23
    }
24
25
    public function message()
26
    {
27
        return __('media-library::validation.width_not_between', [
28
            'min' => $this->minWidth,
29
            'max' => $this->maxWidth,
30
        ]);
31
    }
32
}
33