Passed
Push — main ( c698a6...2d171d )
by Yaroslav
02:44
created

HasSrcSet::srcsetMap()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 20
ccs 12
cts 12
cp 1
crap 5
rs 9.6111
1
<?php
2
3
namespace SimpleImageManager\Managers;
4
5
trait HasSrcSet
6
{
7
    /**
8
     * @inheritDoc
9
     */
10 1
    public function srcsetMap(): array
11
    {
12 1
        $map = [];
13
14 1
        if (is_array($this->original) &&
15 1
            !empty($this->original['srcset'])) {
16 1
            $map[''] = $this->original['srcset'];
17
        }
18
19 1
        foreach ($this->formats as $format => $configuration) {
20 1
            if (!empty($configuration['srcset'])) {
21 1
                $map[$format] = $configuration['srcset'];
22
            }
23
        }
24
25 1
        uasort($map, function ($a, $b) {
26 1
            return (int)$b - (int)$a;
27 1
        });
28
29 1
        return $map;
30
    }
31
}
32