Completed
Push — master ( 78d6cc...47a555 )
by Paweł
17:34 queued 17:12
created

ProductFilter::filter()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Promotion\Filter;
13
14
/**
15
 * @author Łukasz Chruściel <[email protected]>
16
 */
17
final class ProductFilter implements FilterInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function filter(array $items, array $configuration)
23
    {
24
        if (!isset($configuration['filters']['products_filter'])) {
25
            return $items;
26
        }
27
28
        $filteredItems = [];
29
        foreach ($items as $item) {
30
            if (in_array($item->getProduct()->getCode(), $configuration['filters']['products_filter']['products'], true)) {
31
                $filteredItems[] = $item;
32
            }
33
        }
34
35
        return $filteredItems;
36
    }
37
}
38