Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 43 |
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 |
||
20 | public function testImmutability() |
||
21 | { |
||
22 | $old = new Archive(); |
||
23 | |||
24 | $value = 'new comment'; |
||
25 | $this->assertNotSame($value, $old->getComment()); |
||
26 | $new = $old->withComment($value); |
||
27 | $this->assertNotSame($old, $new); |
||
28 | $this->assertNotSame($old->getComment(), $new->getComment()); |
||
29 | $this->assertSame($value, $new->getComment()); |
||
30 | $old = $new; |
||
31 | |||
32 | $this->assertEmpty($old->getEntries()); |
||
33 | |||
34 | $entry = new ArchiveEntry('entry1'); |
||
35 | $this->assertNotContains($entry, $old->getEntries()); |
||
36 | $new = $old->addEntry($entry); |
||
37 | $this->assertNotSame($old, $new); |
||
38 | $this->assertNotContains($entry, $old->getEntries()); |
||
39 | $this->assertContains($entry, $new->getEntries()); |
||
40 | $this->assertSame($entry, $new->getEntry(0)); |
||
41 | $this->assertSame($entry, $new->getEntry('entry1')); |
||
42 | $old = $new; |
||
43 | |||
44 | $new = $old |
||
45 | ->addEntry(new ArchiveEntry('entry2')) |
||
46 | ->addEntry($entry3 = new ArchiveEntry('entry3')) |
||
47 | ->addEntry(new ArchiveEntry('entry4')) |
||
48 | ->addEntry(new ArchiveEntry('entry5')) |
||
49 | ; |
||
50 | $this->assertNotSame($old, $new); |
||
51 | $this->assertCount(5, $new->getEntries()); |
||
52 | $old = $new; |
||
53 | |||
54 | $entry = $entry3->withComment('a comment'); |
||
55 | $this->assertContains($entry3, $old->getEntries()); |
||
56 | $this->assertNotContains($entry, $old->getEntries()); |
||
57 | |||
58 | $new = $old->replaceEntry($entry3, $entry); |
||
59 | $this->assertNotSame($old, $new); |
||
60 | $this->assertNotContains($entry, $old->getEntries()); |
||
61 | $this->assertContains($entry, $new->getEntries()); |
||
62 | $this->assertSame($entry3, $old->getEntry('entry3')); |
||
63 | $this->assertSame($entry, $new->getEntry('entry3')); |
||
64 | $old = $new; |
||
65 | |||
66 | $new = $old->delEntry($entry); |
||
67 | $this->assertNotSame($old, $new); |
||
68 | $this->assertNotContains($entry, $new->getEntries()); |
||
69 | $this->assertCount(4, $new->getEntries()); |
||
70 | $this->assertNull($new->getEntry(2)); |
||
71 | $this->assertNull($new->getEntry('entry3')); |
||
72 | } |
||
73 | |||
169 |
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: