Completed
Push — master ( 98c39c...c8155d )
by Pavel
16:50
created

CountController::countAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Controller;
4
5
use Doctrine\Common\Collections\Criteria;
6
use Doctrine\Common\Collections\Selectable;
7
use ScayTrase\Api\Cruds\CriteriaConfiguratorInterface;
8
use ScayTrase\Api\Cruds\Event\CrudEvents;
9
use ScayTrase\Api\Cruds\Exception\CriteriaConfigurationException;
10
use Symfony\Component\EventDispatcher\Event;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
13
final class CountController
14
{
15
    const ACTION = 'countAction';
16
17
    /** @var string */
18
    private $fqcn;
19
    /** @var CriteriaConfiguratorInterface */
20
    private $configurator;
21
    /** @var  Selectable */
22
    private $repository;
23
    /** @var EventDispatcherInterface */
24
    private $evm;
25
26
    /**
27
     * CountController constructor.
28
     *
29
     * @param string                        $fqcn
30
     * @param Selectable                    $repository
31
     * @param CriteriaConfiguratorInterface $configurator
32
     * @param EventDispatcherInterface      $evm
33
     */
34 8 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...
35
        $fqcn,
36
        Selectable $repository,
37
        CriteriaConfiguratorInterface $configurator,
38
        EventDispatcherInterface $evm
39
    ) {
40 8
        $this->fqcn         = $fqcn;
41 8
        $this->configurator = $configurator;
42 8
        $this->repository   = $repository;
43 8
        $this->evm          = $evm;
44 8
    }
45
46
    /**
47
     * Performs counting search of entities and returns count
48
     *
49
     * @param array $criteria
50
     *
51
     * @return integer
52
     * @throws CriteriaConfigurationException
53
     */
54 8
    public function countAction(array $criteria)
55
    {
56 8
        $queryCriteria = new Criteria();
57
58 8
        $this->configurator->configure($this->fqcn, $queryCriteria, $criteria);
59 8
        $count = $this->repository->matching($queryCriteria)->count();
60
61 8
        $this->evm->dispatch(CrudEvents::COUNT, new Event());
62
63 8
        return $count;
64
    }
65
}
66