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

ResultPagerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 58.7 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 27
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_properly_handles_a_too_large_page_as_the_last_page() 11 11 1
A invalid_page() 8 8 1
A invalid_limit() 8 8 1
A createPager() 0 4 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\Pager;
4
5
use Zenstruck\Porpaginas\Arrays\ArrayResult;
6
use Zenstruck\Porpaginas\Pager;
7
use Zenstruck\Porpaginas\Pager\ResultPager;
8
use Zenstruck\Porpaginas\Tests\PagerTestCase;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class ResultPagerTest extends PagerTestCase
14
{
15
    /**
16
     * @test
17
     */
18 View Code Duplication
    public function it_properly_handles_a_too_large_page_as_the_last_page()
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
        $pager = $this->createPager(\range(1, 504), 30, 20);
21
22
        $this->assertSame(26, $pager->getCurrentPage());
23
        $this->assertSame(1, $pager->getFirstPage());
24
        $this->assertNull($pager->getNextPage());
25
        $this->assertSame(25, $pager->getPreviousPage());
26
        $this->assertCount(4, $pager);
27
        $this->assertSame(\range(501, 504), \iterator_to_array($pager));
28
    }
29
30
    /**
31
     * @test
32
     */
33 View Code Duplication
    public function invalid_page()
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
        $pager = new ResultPager(new ArrayResult([]), 0);
36
        $this->assertSame(1, $pager->getCurrentPage());
37
38
        $pager = new ResultPager(new ArrayResult([]), -1);
39
        $this->assertSame(1, $pager->getCurrentPage());
40
    }
41
42
    /**
43
     * @test
44
     */
45 View Code Duplication
    public function invalid_limit()
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...
46
    {
47
        $pager = new ResultPager(new ArrayResult([]), 1, 0);
48
        $this->assertSame(20, $pager->getLimit());
49
50
        $pager = new ResultPager(new ArrayResult([]), 1, -1);
51
        $this->assertSame(20, $pager->getLimit());
52
    }
53
54
    protected function createPager(array $results, int $page, int $limit): Pager
55
    {
56
        return new ResultPager(new ArrayResult($results), $page, $limit);
57
    }
58
}
59