CriteriaBuilderCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 48
loc 48
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addCriteriaBuilder() 4 4 1
A getCriteriaBuilders() 4 4 1
A getCriteriaBuildersForContext() 10 10 1
A isItemValid() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types=1);
3
4
namespace KGzocha\Searcher\CriteriaBuilder\Collection;
5
6
use KGzocha\Searcher\AbstractCollection;
7
use KGzocha\Searcher\Context\SearchingContextInterface;
8
use KGzocha\Searcher\CriteriaBuilder\CriteriaBuilderInterface;
9
10
/**
11
 * @author Krzysztof Gzocha <[email protected]>
12
 */
13 View Code Duplication
class CriteriaBuilderCollection extends AbstractCollection implements CriteriaBuilderCollectionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @param CriteriaBuilderInterface[] $builders array or \Traversable object
17
     */
18 9
    public function __construct($builders = [])
19
    {
20 9
        parent::__construct($builders);
21 4
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 1
    public function addCriteriaBuilder(CriteriaBuilderInterface $criteriaBuilder): CriteriaBuilderCollectionInterface
27
    {
28 1
        return $this->addItem($criteriaBuilder);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function getCriteriaBuilders()
35
    {
36 1
        return $this->getItems();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 2
    public function getCriteriaBuildersForContext(
43
        SearchingContextInterface $searchingContext
44
    ): CriteriaBuilderCollectionInterface {
45 2
        return new self(array_filter(
46 2
            $this->getItems(),
47 2
            function (CriteriaBuilderInterface $criteriaBuilder) use ($searchingContext) {
48 2
                return $criteriaBuilder->supportsSearchingContext($searchingContext);
49 2
            }
50
        ));
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 3
    protected function isItemValid($item): bool
57
    {
58 3
        return $item instanceof CriteriaBuilderInterface;
59
    }
60
}
61