Completed
Pull Request — master (#2)
by Kevin
01:28
created

DBALObjectRepositoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 30 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 9
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A can_iterate_and_count() 0 9 1
A creates_object() 9 9 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 Zenstruck\Porpaginas\Tests\Doctrine\Repository;
4
5
use PHPUnit\Framework\TestCase;
6
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\DBALObject;
7
use Zenstruck\Porpaginas\Tests\Doctrine\Fixtures\DBALObjectRepository;
8
use Zenstruck\Porpaginas\Tests\Doctrine\HasEntityManager;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class DBALObjectRepositoryTest extends TestCase
14
{
15
    use HasEntityManager;
16
17
    /**
18
     * @test
19
     */
20
    public function can_iterate_and_count(): void
21
    {
22
        $this->persistEntities(4);
23
24
        $repository = new DBALObjectRepository($this->em->getConnection());
25
26
        $this->assertCount(4, \iterator_to_array($repository));
27
        $this->assertCount(4, $repository);
28
    }
29
30
    /**
31
     * @test
32
     */
33 View Code Duplication
    public function creates_object(): void
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...
34
    {
35
        $this->persistEntities(1);
36
37
        $object = \iterator_to_array(new DBALObjectRepository($this->em->getConnection()))[0];
38
39
        $this->assertInstanceOf(DBALObject::class, $object);
40
        $this->assertSame('value 1', $object->value);
41
    }
42
}
43