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

ConversionCollection::forCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
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