Conditions | 1 |
Paths | 1 |
Total Lines | 79 |
Code Lines | 65 |
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 |
||
22 | public function construct() |
||
23 | { |
||
24 | $client = new Client('not under test', 'not under test', new CharacterAdapter()); |
||
|
|||
25 | |||
26 | $now = new \DateTime(); |
||
27 | |||
28 | $data = [ |
||
29 | 'id' => 1, |
||
30 | 'name' => 'a name', |
||
31 | 'description' => 'a description', |
||
32 | 'modified' => $now->format('r'), |
||
33 | 'resourceURI' => 'a resource uri', |
||
34 | 'urls' => [['type' => 'a type', 'url' => 'a url']], |
||
35 | 'thumbnail' => ['path' => 'a path', 'extension' => 'an extension'], |
||
36 | 'comics' => [ |
||
37 | 'available' => 2, |
||
38 | 'returned' => 1, |
||
39 | 'collectionURI' => 'a comics collection uri', |
||
40 | 'items' => [['resourceURI' => 'a comics resource uri', 'name' => 'a comics name']], |
||
41 | ], |
||
42 | 'stories' => [ |
||
43 | 'available' => 2, |
||
44 | 'returned' => 1, |
||
45 | 'collectionURI' => 'a stories collection uri', |
||
46 | 'items' => [['resourceURI' => 'a stories resource uri', 'name' => 'a stories name']], |
||
47 | ], |
||
48 | 'events' => [ |
||
49 | 'available' => 2, |
||
50 | 'returned' => 1, |
||
51 | 'collectionURI' => 'a events collection uri', |
||
52 | 'items' => [['resourceURI' => 'a events resource uri', 'name' => 'a events name']], |
||
53 | ], |
||
54 | 'series' => [ |
||
55 | 'available' => 2, |
||
56 | 'returned' => 1, |
||
57 | 'collectionURI' => 'a series collection uri', |
||
58 | 'items' => [['resourceURI' => 'a series resource uri', 'name' => 'a series name']], |
||
59 | ], |
||
60 | ]; |
||
61 | |||
62 | $character = new Character($data); |
||
63 | $this->assertSame(1, $character->getId()); |
||
64 | $this->assertSame('a name', $character->getName()); |
||
65 | $this->assertSame('a description', $character->getDescription()); |
||
66 | $this->assertSame($now->getTimestamp(), $character->getModified()->getTimestamp()); |
||
67 | $this->assertSame('a resource uri', $character->getResourceURI()); |
||
68 | $this->assertSame(1, count($character->getUrls())); |
||
69 | $this->assertSame('a type', $character->getUrls()[0]->getType()); |
||
70 | $this->assertSame('a url', $character->getUrls()[0]->getUrl()); |
||
71 | $this->assertSame('a path', $character->getThumbnail()->getPath()); |
||
72 | $this->assertSame('an extension', $character->getThumbnail()->getExtension()); |
||
73 | |||
74 | $this->assertSame(2, $character->getComics()->getAvailable()); |
||
75 | $this->assertSame(1, $character->getComics()->getReturned()); |
||
76 | $this->assertSame('a comics collection uri', $character->getComics()->getCollectionURI()); |
||
77 | $this->assertSame(1, count($character->getComics()->getItems())); |
||
78 | $this->assertSame('a comics resource uri', $character->getComics()->getItems()[0]->getResourceURI()); |
||
79 | $this->assertSame('a comics name', $character->getComics()->getItems()[0]->getName()); |
||
80 | |||
81 | $this->assertSame(2, $character->getStories()->getAvailable()); |
||
82 | $this->assertSame(1, $character->getStories()->getReturned()); |
||
83 | $this->assertSame(1, count($character->getStories()->getItems())); |
||
84 | $this->assertSame('a stories resource uri', $character->getStories()->getItems()[0]->getResourceURI()); |
||
85 | $this->assertSame('a stories name', $character->getStories()->getItems()[0]->getName()); |
||
86 | |||
87 | $this->assertSame(2, $character->getEvents()->getAvailable()); |
||
88 | $this->assertSame(1, $character->getEvents()->getReturned()); |
||
89 | $this->assertSame('a events collection uri', $character->getEvents()->getCollectionURI()); |
||
90 | $this->assertSame(1, count($character->getEvents()->getItems())); |
||
91 | $this->assertSame('a events resource uri', $character->getEvents()->getItems()[0]->getResourceURI()); |
||
92 | $this->assertSame('a events name', $character->getEvents()->getItems()[0]->getName()); |
||
93 | |||
94 | $this->assertSame(2, $character->getSeries()->getAvailable()); |
||
95 | $this->assertSame(1, $character->getSeries()->getReturned()); |
||
96 | $this->assertSame('a series collection uri', $character->getSeries()->getCollectionURI()); |
||
97 | $this->assertSame(1, count($character->getSeries()->getItems())); |
||
98 | $this->assertSame('a series resource uri', $character->getSeries()->getItems()[0]->getResourceURI()); |
||
99 | $this->assertSame('a series name', $character->getSeries()->getItems()[0]->getName()); |
||
100 | } |
||
101 | |||
164 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.