TSizes   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 18
ccs 8
cts 8
cp 1
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{width: int, height: int}
19
     */
20 13
    protected function calculateSize(int $currentWidth, int $maxWidth, int $currentHeight, int $maxHeight): array
21
    {
22 13
        $newWidth = $currentWidth / $maxWidth;
23 13
        $newHeight = $currentHeight / $maxHeight;
24 13
        $ratio = max($newWidth, $newHeight); // due this it's necessary to pass all
25 13
        $ratio = max($ratio, 1.0);
26 13
        $newWidth = (int) ($currentWidth / $ratio);
27 13
        $newHeight = (int) ($currentHeight / $ratio);
28 13
        return ['width' => $newWidth, 'height' => $newHeight];
29
    }
30
}
31