CategoryReader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 19.67 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 2
cbo 4
dl 12
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A read() 12 12 3
A getQuery() 0 10 2
A getRepository() 0 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
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Reader\ORM;
4
5
use Pim\Bundle\BaseConnectorBundle\Reader\ORM\EntityReader;
6
use Actualys\Bundle\DrupalCommerceConnectorBundle\Entity\Repository\CategoryRepository;
7
use Doctrine\ORM\EntityManager;
8
9
/**
10
 * Class CategoryReader
11
 * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Reader\ORM
12
 */
13
class CategoryReader extends EntityReader
14
{
15
    /**
16
     * @var CategoryRepository
17
     */
18
    protected $repository;
19
20
    /**
21
     * @param EntityManager      $em
22
     * @param string             $className
23
     * @param CategoryRepository $repository
24
     */
25
    public function __construct(
26
      EntityManager $em,
27
      $className,
28
      CategoryRepository $repository
29
    ) {
30
        parent::__construct($em, $className);
31
32
        $this->repository = $repository;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 View Code Duplication
    public function read()
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...
39
    {
40
        $entities = [];
41
42
        while ($entity = parent::read()) {
43
            $this->stepExecution->incrementReadCount();
44
45
            $entities[] = $entity;
46
        }
47
48
        return empty($entities) ? null : $entities;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getQuery()
55
    {
56
        if (!$this->query) {
57
            $this->query = $this->getRepository()
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getRepository()->...ategories()->getQuery() of type object<Doctrine\ORM\Query> is incompatible with the declared type object<Pim\Bundle\BaseCo...Doctrine\AbstractQuery> of property $query.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
              ->findRootCategories()
59
              ->getQuery();
60
        }
61
62
        return $this->query;
63
    }
64
65
    /**
66
     * Get the custom category repository
67
     * @return CategoryRepository
68
     */
69
    protected function getRepository()
70
    {
71
        return $this->repository;
72
    }
73
}
74