SearchController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
crap 1
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 6 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 6
        $this->fqcn         = $fqcn;
42 6
        $this->configurator = $configurator;
43 6
        $this->repository   = $repository;
44 6
        $this->evm          = $evm;
45 6
    }
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 6
    public function findAction(array $criteria, array $order = [], $limit = 10, $offset = 0)
59
    {
60 6
        $queryCriteria = new Criteria(null, $order, $offset, $limit);
61
62 6
        $this->configurator->configure($this->fqcn, $queryCriteria, $criteria);
63 6
        $entities = $this->repository->matching($queryCriteria);
64
65 6
        $this->evm->dispatch(CrudEvents::READ, new CollectionCrudEvent($entities));
66
67 6
        return $entities;
68
    }
69
}
70