| Conditions | 2 |
| Paths | 2 |
| Total Lines | 116 |
| Code Lines | 55 |
| 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 |
||
| 28 | public function load(ObjectManager $manager): void |
||
| 29 | { |
||
| 30 | $data = [ |
||
| 31 | // Author 1 |
||
| 32 | [ |
||
| 33 | 'title' => 'Antony and Cleopatra', |
||
| 34 | 'author' => 'shakespeare', |
||
| 35 | ], |
||
| 36 | [ |
||
| 37 | 'title' => 'Coriolanus', |
||
| 38 | 'author' => 'shakespeare', |
||
| 39 | ], |
||
| 40 | [ |
||
| 41 | 'title' => 'Hamlet', |
||
| 42 | 'author' => 'shakespeare', |
||
| 43 | ], |
||
| 44 | [ |
||
| 45 | 'title' => 'Julius Caesar', |
||
| 46 | 'author' => 'shakespeare', |
||
| 47 | ], |
||
| 48 | [ |
||
| 49 | 'title' => 'King Lear', |
||
| 50 | 'author' => 'shakespeare', |
||
| 51 | ], |
||
| 52 | [ |
||
| 53 | 'title' => 'Macbeth', |
||
| 54 | 'author' => 'shakespeare', |
||
| 55 | ], |
||
| 56 | [ |
||
| 57 | 'title' => 'Othello', |
||
| 58 | 'author' => 'shakespeare', |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | 'title' => 'The Tragedy of Romeo and Juliet', |
||
| 62 | 'author' => 'shakespeare', |
||
| 63 | ], |
||
| 64 | [ |
||
| 65 | 'title' => 'Timon of Athens', |
||
| 66 | 'author' => 'shakespeare', |
||
| 67 | ], |
||
| 68 | [ |
||
| 69 | 'title' => 'Titus Andronicus', |
||
| 70 | 'author' => 'shakespeare', |
||
| 71 | ], |
||
| 72 | [ |
||
| 73 | 'title' => 'Troilus and Cressida', |
||
| 74 | 'author' => 'shakespeare', |
||
| 75 | ], |
||
| 76 | [ |
||
| 77 | 'title' => 'All\'s Well That Ends Well', |
||
| 78 | 'author' => 'shakespeare', |
||
| 79 | ], |
||
| 80 | [ |
||
| 81 | 'title' => 'As You Like It', |
||
| 82 | 'author' => 'shakespeare', |
||
| 83 | ], |
||
| 84 | [ |
||
| 85 | 'title' => 'The Comedy of Errors', |
||
| 86 | 'author' => 'shakespeare', |
||
| 87 | ], |
||
| 88 | [ |
||
| 89 | 'title' => 'Cymbeline', |
||
| 90 | 'author' => 'shakespeare', |
||
| 91 | ], |
||
| 92 | [ |
||
| 93 | 'title' => 'Love\'s Labour\'s Lost', |
||
| 94 | 'author' => 'shakespeare', |
||
| 95 | ], |
||
| 96 | [ |
||
| 97 | 'title' => 'Measure for Measure', |
||
| 98 | 'author' => 'shakespeare', |
||
| 99 | ], |
||
| 100 | |||
| 101 | // Author 2 |
||
| 102 | [ |
||
| 103 | 'title' => 'The Mysterious Affair at Styles', |
||
| 104 | 'author' => 'christie', |
||
| 105 | ], |
||
| 106 | [ |
||
| 107 | 'title' => 'The Secret Adversary', |
||
| 108 | 'author' => 'christie', |
||
| 109 | ], |
||
| 110 | [ |
||
| 111 | 'title' => 'The Murder on the Links', |
||
| 112 | 'author' => 'christie', |
||
| 113 | ], |
||
| 114 | [ |
||
| 115 | 'title' => 'The Man in the Brown Suit', |
||
| 116 | 'author' => 'christie', |
||
| 117 | ], |
||
| 118 | [ |
||
| 119 | 'title' => 'The Secret of Chimneys', |
||
| 120 | 'author' => 'christie', |
||
| 121 | ], |
||
| 122 | [ |
||
| 123 | 'title' => 'The Murder of Roger Ackroyd', |
||
| 124 | 'author' => 'christie', |
||
| 125 | ], |
||
| 126 | [ |
||
| 127 | 'title' => 'The Big Four', |
||
| 128 | 'author' => 'christie', |
||
| 129 | ], |
||
| 130 | [ |
||
| 131 | 'title' => 'The Mystery of the Blue Train', |
||
| 132 | 'author' => 'christie', |
||
| 133 | ], |
||
| 134 | ]; |
||
| 135 | |||
| 136 | foreach ($data as $item) { |
||
| 137 | /** @var Author $author */ |
||
| 138 | $author = $this->getReference('author-' . $item['author']); |
||
| 139 | |||
| 140 | $manager->persist(new Book($this->idGenerator->bookId(), $author->id(), $item['title'])); |
||
| 141 | } |
||
| 142 | |||
| 143 | $manager->flush(); |
||
| 144 | } |
||
| 146 |