Conditions | 3 |
Paths | 9 |
Total Lines | 62 |
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 |
||
10 | public function testFactory() |
||
11 | { |
||
12 | $view1 = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock(); |
||
13 | $view2 = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock(); |
||
14 | $view3 = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock(); |
||
15 | $view4 = $this->getMockBuilder('Pagerfanta\View\ViewInterface')->getMock(); |
||
16 | |||
17 | $factory = new ViewFactory(); |
||
18 | |||
19 | $factory->set('foo', $view1); |
||
|
|||
20 | $factory->set('bar', $view2); |
||
21 | |||
22 | $this->assertSame(array('foo' => $view1, 'bar' => $view2), $factory->all()); |
||
23 | |||
24 | $this->assertSame($view1, $factory->get('foo')); |
||
25 | $this->assertSame($view2, $factory->get('bar')); |
||
26 | try { |
||
27 | $factory->get('foobar'); |
||
28 | $this->fail(); |
||
29 | } catch (\Exception $e) { |
||
30 | $this->assertInstanceOf('Pagerfanta\Exception\InvalidArgumentException', $e); |
||
31 | } |
||
32 | |||
33 | $this->assertTrue($factory->has('foo')); |
||
34 | $this->assertTrue($factory->has('bar')); |
||
35 | $this->assertFalse($factory->has('foobar')); |
||
36 | |||
37 | $factory->add(array( |
||
38 | 'ups' => $view3, |
||
39 | 'man' => $view4, |
||
40 | )); |
||
41 | $this->assertSame($view3, $factory->get('ups')); |
||
42 | $this->assertSame($view4, $factory->get('man')); |
||
43 | $this->assertTrue($factory->has('ups')); |
||
44 | $this->assertTrue($factory->has('man')); |
||
45 | $this->assertSame(array( |
||
46 | 'foo' => $view1, |
||
47 | 'bar' => $view2, |
||
48 | 'ups' => $view3, |
||
49 | 'man' => $view4, |
||
50 | ), $factory->all()); |
||
51 | |||
52 | $factory->remove('bar'); |
||
53 | $this->assertFalse($factory->has('bar')); |
||
54 | $this->assertTrue($factory->has('foo')); |
||
55 | $this->assertTrue($factory->has('ups')); |
||
56 | $this->assertTrue($factory->has('man')); |
||
57 | $this->assertSame(array( |
||
58 | 'foo' => $view1, |
||
59 | 'ups' => $view3, |
||
60 | 'man' => $view4, |
||
61 | ), $factory->all()); |
||
62 | try { |
||
63 | $factory->remove('foobar'); |
||
64 | $this->fail(); |
||
65 | } catch (\Exception $e) { |
||
66 | $this->assertInstanceOf('Pagerfanta\Exception\InvalidArgumentException', $e); |
||
67 | } |
||
68 | |||
69 | $factory->clear(); |
||
70 | $this->assertSame(array(), $factory->all()); |
||
71 | } |
||
72 | } |
||
73 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: