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

ConversionCollection::shouldBePerformedOn()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
c 1
b 0
f 1
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