Passed
Push — master ( c6f9a3...c9f7be )
by Gabriel
03:32
created

ConversionCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 34
ccs 9
cts 10
cp 0.9
rs 10
c 1
b 0
f 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forCollection() 0 7 2
A shouldBePerformedOn() 0 11 3
1
<?php
2
3
namespace ByTIC\MediaLibrary\Conversions;
4
5
/**
6
 * Class ConversionCollection.
7
 */
8
class ConversionCollection extends \Nip\Collections\AbstractCollection
9
{
10
    /**
11
     * Get all the conversions in the collection.
12
     *
13
     * @param string $collectionName
14
     *
15
     * @return $this
16
     */
17 3
    public function forCollection(string $collectionName = '')
18
    {
19 3
        if ($collectionName === '') {
20
            return $this;
21
        }
22
23 3
        return $this->shouldBePerformedOn($collectionName);
24
    }
25
26
    /**
27
     * @param string $collectionName
28
     *
29
     * @return $this
30
     */
31 3
    protected function shouldBePerformedOn($collectionName)
32
    {
33 3
        $results = [];
34 3
        foreach ($this as $key=>$item) {
35
            /** @var Conversion $item */
36 1
            if ($item->shouldBePerformedOn($collectionName)) {
37 1
                $results[$key] = $item;
38
            }
39
        }
40
41 3
        return new self($results);
42
    }
43
}
44