Failed Conditions
Pull Request — develop (#6873)
by
unknown
112:44 queued 47:41
created

GH6740Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 35.05 %

Importance

Changes 0
Metric Value
dl 34
loc 97
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCollectionFilteringGteOperator() 6 6 1
A testCollectionFilteringLteOperator() 6 6 1
A testCollectionFilteringEqualsOperator() 6 6 1
A testCollectionFilteringLtOperator() 6 6 1
B setUp() 0 25 1
A testCollectionFilteringGtOperator() 6 6 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 Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
7
use Doctrine\Tests\Models\ECommerce\ECommerceCategory;
8
use Doctrine\Common\Collections\Criteria;
9
10
final class GH6740Test extends OrmFunctionalTestCase
11
{
12
    /**
13
     * @var int
14
     */
15
    private $productId;
16
17
    /**
18
     * @var int
19
     */
20
    private $firstCategoryId;
21
22
    /**
23
     * @var int
24
     */
25
    private $secondCategoryId;
26
27
    public function setUp() : void
28
    {
29
        $this->useModelSet('ecommerce');
30
31
        parent::setUp();
32
33
        $product = new ECommerceProduct();
34
        $product->setName('First Product');
35
36
        $firstCategory  = new ECommerceCategory();
37
        $secondCategory = new ECommerceCategory();
38
39
        $firstCategory->setName('Business');
40
        $secondCategory->setName('Home');
41
42
        $product->addCategory($firstCategory);
43
        $product->addCategory($secondCategory);
44
45
        $this->_em->persist($product);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
46
        $this->_em->flush();
47
        $this->_em->clear();
48
49
        $this->productId        = $product->getId();
50
        $this->firstCategoryId  = $firstCategory->getId();
51
        $this->secondCategoryId = $secondCategory->getId();
52
    }
53
54
    /**
55
     * @group 6740
56
     */
57 View Code Duplication
    public function testCollectionFilteringLteOperator() : void
58
    {
59
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
60
        $criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategoryId));
61
62
        self::assertCount(2, $product->getCategories()->matching($criteria));
63
    }
64
65
    /**
66
     * @group 6740
67
     */
68 View Code Duplication
    public function testCollectionFilteringLtOperator() : void
69
    {
70
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
71
        $criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategoryId));
72
73
        self::assertCount(1, $product->getCategories()->matching($criteria));
74
    }
75
76
    /**
77
     * @group 6740
78
     */
79 View Code Duplication
    public function testCollectionFilteringGteOperator() : void
80
    {
81
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
82
        $criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategoryId));
83
84
        self::assertCount(2, $product->getCategories()->matching($criteria));
85
    }
86
87
    /**
88
     * @group 6740
89
     */
90 View Code Duplication
    public function testCollectionFilteringGtOperator() : void
91
    {
92
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
93
        $criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategoryId));
94
95
        self::assertCount(1, $product->getCategories()->matching($criteria));
96
    }
97
98
    /**
99
     * @group 6740
100
     */
101 View Code Duplication
    public function testCollectionFilteringEqualsOperator() : void
102
    {
103
        $product  = $this->_em->find(ECommerceProduct::class, $this->productId);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH6740Test. Did you maybe forget to declare it?
Loading history...
104
        $criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategoryId));
105
106
        self::assertCount(1, $product->getCategories()->matching($criteria));
107
    }
108
}
109