HeightBetweenRule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Rules\ItemRules;
4
5
class HeightBetweenRule extends MediaItemRule
6
{
7
    public function __construct(
8
        protected int $minHeight = 0,
9
        protected int $maxHeight = 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
        $actualHeight = $size[1];
21
22
        return $actualHeight >= $this->minHeight && $actualHeight <= $this->maxHeight;
23
    }
24
25
    public function message()
26
    {
27
        return __('media-library::validation.height_not_between', [
28
            'min' => $this->minHeight,
29
            'max' => $this->maxHeight,
30
        ]);
31
    }
32
}
33