WidthBetweenRule   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 5 1
A __construct() 0 4 1
A validateMediaItem() 0 10 3
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