Completed
Push — dev ( 5c06f5...dcd39b )
by Arnaud
09:19
created

DataProviderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 70.97 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 2
dl 44
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSave() 11 11 1
A testDelete() 11 11 1
A testFind() 11 11 1
A testfindBy() 11 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 BlueBear\AdminBundle\Tests\AdminBundle\DataProvider;
4
5
use LAG\AdminBundle\DataProvider\DataProvider;
6
use LAG\AdminBundle\Tests\Base;
7
use stdClass;
8
9
/**
10
 * Test the built-in data provider
11
 */
12
class DataProviderTest extends Base
13
{
14
    /**
15
     * Method save SHOULD be called on the entiy repository
16
     */
17 View Code Duplication
    public function testSave()
18
    {
19
        // repository save method SHOULD be called
20
        $repositoryMock = $this->mockEntityRepository();
21
        $repositoryMock
22
            ->expects($this->once())
23
            ->method('save');
24
25
        $dataProvider = new DataProvider($repositoryMock);
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->mockEntityRepository() on line 20 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LAG\AdminBundle\DataProv...Provider::__construct() does only seem to accept object<LAG\DoctrineRepos...ry\RepositoryInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
26
        $dataProvider->save(new stdClass());
27
    }
28
29
    /**
30
     * Method delete SHOULD be called on the entity repository
31
     */
32 View Code Duplication
    public function testDelete()
33
    {
34
        // entity manager delete method SHOULD be called
35
        $repositoryMock = $this->mockEntityRepository();
36
        $repositoryMock
37
            ->expects($this->once())
38
            ->method('delete');
39
40
        $dataProvider = new DataProvider($repositoryMock);
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->mockEntityRepository() on line 35 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LAG\AdminBundle\DataProv...Provider::__construct() does only seem to accept object<LAG\DoctrineRepos...ry\RepositoryInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
41
        $dataProvider->remove(new stdClass());
42
    }
43
44
    /**
45
     * Method find SHOULD be called on the entity repository
46
     */
47 View Code Duplication
    public function testFind()
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...
48
    {
49
        // repository find method SHOULD be called
50
        $repositoryMock = $this->mockEntityRepository();
51
        $repositoryMock
52
            ->expects($this->once())
53
            ->method('find');
54
55
        $dataProvider = new DataProvider($repositoryMock);
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->mockEntityRepository() on line 50 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LAG\AdminBundle\DataProv...Provider::__construct() does only seem to accept object<LAG\DoctrineRepos...ry\RepositoryInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
56
        $dataProvider->find('unique_id');
57
    }
58
59
    /**
60
     * Method findBy SHOULD be called on the entity repository
61
     */
62 View Code Duplication
    public function testfindBy()
63
    {
64
        // repository findBy method SHOULD be called
65
        $repositoryMock = $this->mockEntityRepository();
66
        $repositoryMock
67
            ->expects($this->once())
68
            ->method('findBy');
69
70
        $dataProvider = new DataProvider($repositoryMock);
0 ignored issues
show
Bug introduced by
It seems like $repositoryMock defined by $this->mockEntityRepository() on line 65 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LAG\AdminBundle\DataProv...Provider::__construct() does only seem to accept object<LAG\DoctrineRepos...ry\RepositoryInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
71
        $dataProvider->findBy([]);
72
    }
73
}
74