Passed
Pull Request — master (#6740)
by Mathieu
15:42
created

DDC288Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 52.63 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 40
loc 76
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 23 1
A testCollectionFilteringLteOperator() 8 8 1
A testCollectionFilteringLtOperator() 8 8 1
A testCollectionFilteringGteOperator() 8 8 1
A testCollectionFilteringGtOperator() 8 8 1
A testCollectionFilteringEqualsOperator() 8 8 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
class DDC288Test extends OrmFunctionalTestCase
11
{
12
    private $firstProduct;
13
    private $secondProduct;
0 ignored issues
show
Unused Code introduced by
The property $secondProduct is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
    private $firstCategory;
15
    private $secondCategory;
16
17
    public function setUp()
18
    {
19
        $this->useModelSet('ecommerce');
20
        parent::setUp();
21
22
        $this->firstProduct = new ECommerceProduct();
23
        $this->firstProduct->setName("First Product");
24
25
        $this->firstCategory = new ECommerceCategory();
26
        $this->firstCategory->setName("Business");
27
28
29
        $this->secondCategory = new ECommerceCategory();
30
        $this->secondCategory->setName("Home");
31
32
        $this->firstProduct->addCategory($this->firstCategory);
33
        $this->firstProduct->addCategory($this->secondCategory);
34
35
        $this->_em->persist($this->firstProduct);
36
37
        $this->_em->flush();
38
        $this->_em->clear();
39
    }
40
41 View Code Duplication
    public function testCollectionFilteringLteOperator()
42
    {
43
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
44
45
        $criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategory->getId()));
46
47
        $this->assertCount(2, $firstProduct->getCategories()->matching($criteria));
48
    }
49
50 View Code Duplication
    public function testCollectionFilteringLtOperator()
51
    {
52
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
53
54
        $criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategory->getId()));
55
56
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
57
    }
58
59 View Code Duplication
    public function testCollectionFilteringGteOperator()
60
    {
61
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
62
63
        $criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategory->getId()));
64
65
        $this->assertCount(2, $firstProduct->getCategories()->matching($criteria));
66
    }
67
68 View Code Duplication
    public function testCollectionFilteringGtOperator()
69
    {
70
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
71
72
        $criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategory->getId()));
73
74
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
75
    }
76
77 View Code Duplication
    public function testCollectionFilteringEqualsOperator()
78
    {
79
        $firstProduct = $this->_em->find(ECommerceProduct::class, $this->firstProduct->getId());
80
81
        $criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategory->getId()));
82
83
        $this->assertCount(1, $firstProduct->getCategories()->matching($criteria));
84
    }
85
}
86