ProductAttributesRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 41.38 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 0
dl 24
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findByScopable() 12 12 1
A findByLocalizable() 12 12 1
A findByAttributeType() 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 DefaultValue\Bundle\AkeneoInlineEditBundle\Product;
4
5
use Pim\Bundle\CatalogBundle\Doctrine\ORM\Repository\AttributeRepository;
6
7
/**
8
 * Query from database product attributes
9
 */
10
class ProductAttributesRepository extends AttributeRepository
11
{
12
    /**
13
     * Find attributes by `scopable` attribute. By default fetches scopable attributes
14
     *
15
     * @param int $scopable
16
     * @return \Doctrine\ORM\QueryBuilder
17
     */
18 View Code Duplication
    public function findByScopable($scopable = 1)
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...
19
    {
20
        $result = $this->getEntityManager()
21
            ->createQueryBuilder()
22
            ->select('attr')
23
            ->from('PimCatalogBundle:Attribute', 'attr')
24
            ->where('attr.scopable = :scopable')
25
            ->setParameter(':scopable', $scopable)
26
            ->orderBy('attr.id', 'desc');
27
28
        return $result;
29
    }
30
31
    /**
32
     * Find attributes by `localizable` attribute. By default fetches localizable attributes
33
     *
34
     * @param int $localizable
35
     * @return \Doctrine\ORM\QueryBuilder
36
     */
37 View Code Duplication
    public function findByLocalizable($localizable = 1)
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...
38
    {
39
        $result = $this->getEntityManager()
40
            ->createQueryBuilder()
41
            ->select('attr')
42
            ->from('PimCatalogBundle:Attribute', 'attr')
43
            ->where('attr.localizable = :localizable')
44
            ->setParameter(':localizable', $localizable)
45
            ->orderBy('attr.id', 'desc');
46
47
        return $result;
48
    }
49
50
    /**
51
     * Find attributes by attributeType.
52
     *
53
     * @param string $attributeType
54
     * @return \Doctrine\ORM\QueryBuilder
55
     */
56
    public function findByAttributeType($attributeType)
57
    {
58
        $result = $this->getEntityManager()
59
            ->createQueryBuilder()
60
            ->select()
61
            ->from('PimCatalogBundle:Attribute', 'attr')
62
            ->where('attr.attributeType = :attributeType')
63
            ->setParameter(':attributeType', $attributeType);
64
65
        return $result;
66
    }
67
}
68