Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
14 | public function test() |
||
15 | { |
||
16 | $results = array( |
||
17 | 'Adrien', |
||
18 | 'William', |
||
19 | ); |
||
20 | |||
21 | $pagerProphecy = $this->prophesize('Pagerfanta\Pagerfanta'); |
||
22 | $pagerProphecy->getCurrentPageResults()->willReturn($results); |
||
23 | $pagerProphecy->getCurrentPage()->willReturn(2); |
||
24 | $pagerProphecy->getMaxPerPage()->willReturn(20); |
||
25 | $pagerProphecy->getNbPages()->willReturn(4); |
||
26 | $pagerProphecy->getNbResults()->willReturn(100); |
||
27 | |||
28 | $factory = new PagerfantaFactory('p', 'l'); |
||
29 | $representation1 = $factory->createRepresentation( |
||
30 | $pagerProphecy->reveal(), |
||
31 | new Route( |
||
32 | 'users', |
||
33 | array( |
||
34 | 'query' => 'hateoas', |
||
35 | ) |
||
36 | ) |
||
37 | ); |
||
38 | $representation2 = $factory->createRepresentation( |
||
39 | $pagerProphecy->reveal(), |
||
40 | new Route( |
||
41 | 'users', |
||
42 | array( |
||
43 | 'query' => 'hateoas', |
||
44 | ) |
||
45 | ), |
||
46 | array() |
||
47 | ); |
||
48 | |||
49 | $this->assertEquals(new CollectionRepresentation($results), $representation1->getInline()); |
||
50 | $this->assertSame([], $representation2->getInline()); |
||
51 | |||
52 | foreach (array($representation1, $representation2) as $representation) { |
||
53 | $this->assertInstanceOf('Hateoas\Representation\PaginatedRepresentation', $representation); |
||
54 | $this->assertSame(2, $representation->getPage()); |
||
55 | $this->assertSame(20, $representation->getLimit()); |
||
56 | $this->assertSame(4, $representation->getPages()); |
||
57 | $this->assertSame(100, $representation->getTotal()); |
||
58 | $this->assertSame( |
||
59 | [ |
||
60 | 'query' => 'hateoas', |
||
61 | 'p' => 2, |
||
62 | 'l' => 20, |
||
63 | ], |
||
64 | $representation->getParameters() |
||
65 | ); |
||
66 | $this->assertSame('p', $representation->getPageParameterName()); |
||
67 | $this->assertSame('l', $representation->getLimitParameterName()); |
||
68 | } |
||
69 | } |
||
70 | |||
170 |