CountController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 20.75 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 11
loc 53
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A countAction() 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\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