Passed
Pull Request — master (#21)
by Pavel
06:33
created

SearchController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 19.64 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A findAction() 0 11 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
3
namespace ScayTrase\Api\Cruds\Controller;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\Common\Collections\Criteria;
7
use Doctrine\Common\Collections\Selectable;
8
use ScayTrase\Api\Cruds\CriteriaConfiguratorInterface;
9
use ScayTrase\Api\Cruds\Event\CollectionCrudEvent;
10
use ScayTrase\Api\Cruds\Event\CrudEvents;
11
use ScayTrase\Api\Cruds\Exception\CriteriaConfigurationException;
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
14
final class SearchController
15
{
16
    const ACTION = 'findAction';
17
18
    /** @var string */
19
    private $fqcn;
20
    /** @var CriteriaConfiguratorInterface */
21
    private $configurator;
22
    /** @var  Selectable */
23
    private $repository;
24
    /** @var EventDispatcherInterface */
25
    private $evm;
26
27
    /**
28
     * ReadController constructor.
29
     *
30
     * @param string                        $fqcn
31
     * @param Selectable                    $repository
32
     * @param CriteriaConfiguratorInterface $configurator
33
     * @param EventDispatcherInterface      $evm
34
     */
35 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method 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...
36
        $fqcn,
37
        Selectable $repository,
38
        CriteriaConfiguratorInterface $configurator,
39
        EventDispatcherInterface $evm
40
    ) {
41
        $this->fqcn         = $fqcn;
42
        $this->configurator = $configurator;
43
        $this->repository   = $repository;
44
        $this->evm          = $evm;
45
    }
46
47
    /**
48
     * Performs search of entities and returns them
49
     *
50
     * @param array $criteria
51
     * @param array $order
52
     * @param int   $limit
53
     * @param int   $offset
54
     *
55
     * @return object[]|Collection
56
     * @throws CriteriaConfigurationException
57
     */
58
    public function findAction(array $criteria, array $order = [], $limit = 10, $offset = 0)
59
    {
60
        $queryCriteria = new Criteria(null, $order, $offset, $limit);
61
62
        $this->configurator->configure($this->fqcn, $queryCriteria, $criteria);
63
        $entities = $this->repository->matching($queryCriteria);
64
65
        $this->evm->dispatch(CrudEvents::READ, new CollectionCrudEvent($entities));
66
67
        return $entities;
68
    }
69
}
70