| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| 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 |
||
| 17 | public function testFromApi(): void |
||
| 18 | { |
||
| 19 | $data = <<<'EOD' |
||
| 20 | { |
||
| 21 | "name": "First set", |
||
| 22 | "encore": 3, |
||
| 23 | "song" : [ { |
||
| 24 | "name" : "Twist and Shout", |
||
| 25 | "cover" : { |
||
| 26 | "mbid" : "f18eac60-48d2-4d2b-b432-e43ce7e31d36", |
||
| 27 | "name" : "The Top Notes", |
||
| 28 | "sortName" : "Top Notes, The", |
||
| 29 | "url" : "https://www.setlist.fm/setlists/the-top-notes-53d433dd.html" |
||
| 30 | } |
||
| 31 | }, { |
||
| 32 | "name" : "You Can't Do That" |
||
| 33 | }, { |
||
| 34 | "name" : "All My Loving" |
||
| 35 | }, { |
||
| 36 | "name" : "She Loves You" |
||
| 37 | }, { |
||
| 38 | "name" : "Things We Said Today" |
||
| 39 | }, { |
||
| 40 | "name" : "Roll Over Beethoven", |
||
| 41 | "cover" : { |
||
| 42 | "mbid" : "592a3b6d-c42b-4567-99c9-ecf63bd66499", |
||
| 43 | "tmid" : 734540, |
||
| 44 | "name" : "Chuck Berry", |
||
| 45 | "sortName" : "Berry, Chuck", |
||
| 46 | "disambiguation" : "", |
||
| 47 | "url" : "https://www.setlist.fm/setlists/chuck-berry-63d6a2b7.html" |
||
| 48 | } |
||
| 49 | }, { |
||
| 50 | "name" : "Can't Buy Me Love" |
||
| 51 | }, { |
||
| 52 | "name" : "If I Fell" |
||
| 53 | }, { |
||
| 54 | "name" : "I Want to Hold Your Hand" |
||
| 55 | }, { |
||
| 56 | "name" : "Boys", |
||
| 57 | "cover" : { |
||
| 58 | "mbid" : "a8540ea0-1a74-4c22-8b70-1348a77a74a0", |
||
| 59 | "name" : "The Shirelles", |
||
| 60 | "sortName" : "Shirelles, The", |
||
| 61 | "disambiguation" : "", |
||
| 62 | "url" : "https://www.setlist.fm/setlists/the-shirelles-bd69d7a.html" |
||
| 63 | } |
||
| 64 | }, { |
||
| 65 | "name" : "A Hard Day's Night" |
||
| 66 | }, { |
||
| 67 | "name" : "Long Tall Sally", |
||
| 68 | "cover" : { |
||
| 69 | "mbid" : "95c2339b-8277-49a6-9aaf-08d8eeeaa0be", |
||
| 70 | "tmid" : 735520, |
||
| 71 | "name" : "Little Richard", |
||
| 72 | "sortName" : "Little Richard", |
||
| 73 | "disambiguation" : "", |
||
| 74 | "url" : "https://www.setlist.fm/setlists/little-richard-4bd6af2e.html" |
||
| 75 | } |
||
| 76 | } ] |
||
| 77 | } |
||
| 78 | EOD; |
||
| 79 | |||
| 80 | $set = Set::fromApi(json_decode($data, true)); |
||
| 81 | $this->assertSame('First set', $set->getName()); |
||
| 82 | $this->assertCount(12, $set->getSongs()); |
||
| 83 | $this->assertSame(3, $set->getEncore()); |
||
| 84 | } |
||
| 85 | } |
||
| 86 |