Test Failed
Push — master ( f9dc8e...64f7bc )
by Petr
08:10
created

TSizes   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 18
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculateSize() 0 9 1
1
<?php
2
3
namespace kalanis\kw_images\Traits;
4
5
6
/**
7
 * Trait TSizes
8
 * Calculate image sizes
9
 * @package kalanis\kw_images\Traits
10
 */
11
trait TSizes
12
{
13
    /**
14
     * @param int $currentWidth
15
     * @param int $maxWidth
16
     * @param int $currentHeight
17
     * @param int $maxHeight
18
     * @return array<string, int>
19
     */
20
    protected function calculateSize(int $currentWidth, int $maxWidth, int $currentHeight, int $maxHeight): array
21
    {
22
        $newWidth = $currentWidth / $maxWidth;
23
        $newHeight = $currentHeight / $maxHeight;
24
        $ratio = max($newWidth, $newHeight); // due this it's necessary to pass all
25
        $ratio = max($ratio, 1.0);
26
        $newWidth = (int) ($currentWidth / $ratio);
27
        $newHeight = (int) ($currentHeight / $ratio);
28
        return ['width' => $newWidth, 'height' => $newHeight];
29
    }
30
}
31