| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 58 |
| 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 |
||
| 19 | public function basicUsage() |
||
| 20 | { |
||
| 21 | $data = [ |
||
| 22 | 'id' => 5, |
||
| 23 | 'title' => 'a title', |
||
| 24 | 'description' => 'a description', |
||
| 25 | 'resourceURI' => 'a resourceURI', |
||
| 26 | 'urls' => [['type' => 'a type', 'url' => 'a url']], |
||
| 27 | 'modified' => 'Fri, 31 Jul 2015 19:44:03 -0400', |
||
| 28 | 'start' => 'Fri, 31 Jul 2015 19:44:03 -0400', |
||
| 29 | 'end' => 'Fri, 31 Jul 2015 19:44:03 -0400', |
||
| 30 | 'thumbnail' => ['path' => 'an image path', 'extension' => 'an image extension'], |
||
| 31 | 'comics' => ['available' => 2, 'returned' => 1, 'collectionURI' => 'a collection URI', 'items' => []], |
||
| 32 | 'stories' => ['available' => 4, 'returned' => 3, 'collectionURI' => 'a collection URI', 'items' => []], |
||
| 33 | 'series' => ['available' => 6, 'returned' => 5, 'collectionURI' => 'a collection URI', 'items' => []], |
||
| 34 | 'characters' => ['available' => 9, 'returned' => 8, 'collectionURI' => 'a collection URI', 'items' => []], |
||
| 35 | 'creators' => ['available' => 2, 'returned' => 1, 'collectionURI' => 'a collection URI', 'items' => []], |
||
| 36 | 'next' => ['resourceURI' => 'a resource URI', 'name' => 'a name', 'type' => 'a type', 'role' => 'a role'], |
||
| 37 | 'previous' => [ |
||
| 38 | 'resourceURI' => 'a resource URI', |
||
| 39 | 'name' => 'a name', |
||
| 40 | 'type' => 'a type', |
||
| 41 | 'role' => 'a role', |
||
| 42 | ], |
||
| 43 | ]; |
||
| 44 | |||
| 45 | $event = new Event($data); |
||
| 46 | $this->assertSame($data['id'], $event->id); |
||
| 47 | $this->assertSame($data['title'], $event->title); |
||
| 48 | $this->assertSame($data['description'], $event->description); |
||
| 49 | $this->assertSame($data['resourceURI'], $event->resourceURI); |
||
| 50 | $this->assertSame(count($data['urls']), count($event->urls)); |
||
| 51 | $this->assertSame($data['urls'][0]['type'], $event->urls[0]->type); |
||
| 52 | $this->assertSame($data['urls'][0]['url'], $event->urls[0]->url); |
||
| 53 | $this->assertSame($data['modified'], $event->modified->format('r')); |
||
| 54 | $this->assertSame($data['start'], $event->start->format('r')); |
||
| 55 | $this->assertSame($data['end'], $event->end->format('r')); |
||
| 56 | $this->assertSame($data['thumbnail']['path'], $event->thumbnail->path); |
||
| 57 | $this->assertSame($data['thumbnail']['extension'], $event->thumbnail->extension); |
||
| 58 | $this->assertSame($data['comics']['available'], $event->comics->available); |
||
| 59 | $this->assertSame($data['comics']['returned'], $event->comics->returned); |
||
| 60 | $this->assertSame($data['comics']['collectionURI'], $event->comics->collectionURI); |
||
| 61 | $this->assertSame($data['stories']['available'], $event->stories->available); |
||
| 62 | $this->assertSame($data['stories']['returned'], $event->stories->returned); |
||
| 63 | $this->assertSame($data['stories']['collectionURI'], $event->stories->collectionURI); |
||
| 64 | $this->assertSame($data['series']['available'], $event->series->available); |
||
| 65 | $this->assertSame($data['series']['returned'], $event->series->returned); |
||
| 66 | $this->assertSame($data['series']['collectionURI'], $event->series->collectionURI); |
||
| 67 | $this->assertSame($data['characters']['available'], $event->characters->available); |
||
| 68 | $this->assertSame($data['characters']['returned'], $event->characters->returned); |
||
| 69 | $this->assertSame($data['characters']['collectionURI'], $event->characters->collectionURI); |
||
| 70 | $this->assertSame($data['creators']['available'], $event->creators->available); |
||
| 71 | $this->assertSame($data['creators']['returned'], $event->creators->returned); |
||
| 72 | $this->assertSame($data['creators']['collectionURI'], $event->creators->collectionURI); |
||
| 73 | $this->assertSame($data['next']['resourceURI'], $event->next->resourceURI); |
||
| 74 | $this->assertSame($data['next']['name'], $event->next->name); |
||
| 75 | $this->assertSame($data['next']['type'], $event->next->type); |
||
| 76 | $this->assertSame($data['next']['role'], $event->next->role); |
||
| 77 | $this->assertSame($data['previous']['resourceURI'], $event->previous->resourceURI); |
||
| 78 | $this->assertSame($data['previous']['name'], $event->previous->name); |
||
| 79 | $this->assertSame($data['previous']['type'], $event->previous->type); |
||
| 80 | $this->assertSame($data['previous']['role'], $event->previous->role); |
||
| 81 | } |
||
| 82 | } |
||
| 83 |