| Conditions | 3 | 
| Paths | 16 | 
| Total Lines | 96 | 
| Code Lines | 72 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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  | 
            ||
| 98 | public function testTicket()  | 
            ||
| 99 |     { | 
            ||
| 100 | // Wrap dummy data creation in a transaction in order  | 
            ||
| 101 | // to not actually store it in the production database.  | 
            ||
| 102 | //  | 
            ||
| 103 | // We have to use eloquent models and cannot use factories,  | 
            ||
| 104 | // because factories are not available on prod installations.  | 
            ||
| 105 | DB::beginTransaction();  | 
            ||
| 106 | $vendor = User::create([  | 
            ||
| 107 | 'name' => 'TestVendor FamilynameOfVendor',  | 
            ||
| 108 | 'email' => '[email protected]',  | 
            ||
| 109 | 'password' => ''  | 
            ||
| 110 | ]);  | 
            ||
| 111 | $customer = User::create([  | 
            ||
| 112 | 'name' => 'Avery LongName ButItShouldWork',  | 
            ||
| 113 | 'email' => '[email protected]',  | 
            ||
| 114 | 'password' => ''  | 
            ||
| 115 | ]);  | 
            ||
| 116 | |||
| 117 | $priceList = PriceList::create([  | 
            ||
| 118 | 'name' => 'Testlist'  | 
            ||
| 119 | ]);  | 
            ||
| 120 | $priceCategory = PriceCategory::create([  | 
            ||
| 121 | 'name' => 'TestCategory',  | 
            ||
| 122 | 'price' => 450,  | 
            ||
| 123 | 'description' => 'Just for testing the ticket layout'  | 
            ||
| 124 | ]);  | 
            ||
| 125 | $priceList->categories()->save($priceCategory);  | 
            ||
| 126 | |||
| 127 | $location = Location::create([  | 
            ||
| 128 | 'name' => 'Some Test Location anywhere',  | 
            ||
| 129 | 'address' => 'Somewhere over the rainbox street 42, 424242 Kummerland, Wilde13'  | 
            ||
| 130 | ]);  | 
            ||
| 131 | $project = Project::create([  | 
            ||
| 132 | 'name' => 'A Test project',  | 
            ||
| 133 | 'description' => 'Something something testing',  | 
            ||
| 134 | 'is_archived' => false  | 
            ||
| 135 | ]);  | 
            ||
| 136 | $seatMap = SeatMap::create([  | 
            ||
| 137 | 'name' => 'TestSeatMap',  | 
            ||
| 138 | 'seats' => 2000,  | 
            ||
| 139 | 'description' => 'Some test description that does not really matter',  | 
            ||
| 140 | 'layout' => null  | 
            ||
| 141 | ]);  | 
            ||
| 142 | $now = now();  | 
            ||
| 143 | |||
| 144 | $purchase = new Purchase();  | 
            ||
| 145 | $purchase->state = 'paid';  | 
            ||
| 146 | $purchase->state_updated = $now;  | 
            ||
| 147 | $purchase->random_id = Str::random(20);  | 
            ||
| 148 | $purchase->payment_secret = Str::random(20);  | 
            ||
| 149 | $purchase->customer_id = $customer->id;  | 
            ||
| 150 | $purchase->vendor_id = $vendor->id;  | 
            ||
| 151 | $purchase->payment_id = 'dummy-reference';  | 
            ||
| 152 | $purchase->save();  | 
            ||
| 153 | |||
| 154 | $event = new Event();  | 
            ||
| 155 | $event->second_name = 'First event';  | 
            ||
| 156 | $event->customer_sell_stop = $now->add(1, 'day');  | 
            ||
| 157 | $event->retailer_sell_stop = $now->add(2, 'day');  | 
            ||
| 158 | $event->start_date = $now->add(1, 'day');  | 
            ||
| 159 | $event->end_date = $now->add(10, 'day');  | 
            ||
| 160 | $event->project_id = $project->id;  | 
            ||
| 161 | $event->location_id = $location->id;  | 
            ||
| 162 | $event->seat_map_id = $seatMap->id;  | 
            ||
| 163 | $event->price_list_id = $priceList->id;  | 
            ||
| 164 | $event->state = 'open';  | 
            ||
| 165 | $event->save();  | 
            ||
| 166 | |||
| 167 |         for($i = 0; $i < 8; $i++) { | 
            ||
| 168 | $ticket = new Ticket();  | 
            ||
| 169 | $ticket->random_id = Str::random(20);  | 
            ||
| 170 | $ticket->seat_number = $i + 1000;  | 
            ||
| 171 | $ticket->event_id = $event->id;  | 
            ||
| 172 | $ticket->purchase_id = $purchase->id;  | 
            ||
| 173 | $ticket->price_category_id = $priceCategory->id;  | 
            ||
| 174 | $ticket->state = 'consumed';  | 
            ||
| 175 | $ticket->save();  | 
            ||
| 176 | }  | 
            ||
| 177 |         try { | 
            ||
| 178 |             $html2pdf = new HTML2PDF('P', 'A4', 'de', true, 'UTF-8', 0); | 
            ||
| 179 |             $html2pdf->pdf->SetDisplayMode('fullpage'); | 
            ||
| 180 |             $html2pdf->pdf->SetAuthor(config('app.name')); | 
            ||
| 181 |             $html2pdf->pdf->SetTitle('Purchase #' . $purchase->id); | 
            ||
| 182 | |||
| 183 | // Generate pdf-content by passing the tickets to the view  | 
            ||
| 184 |             $content = view('pdfs.ticket-v2', ['tickets' => $purchase->tickets])->render(); | 
            ||
| 185 | $html2pdf->writeHTML($content);  | 
            ||
| 186 | |||
| 187 |             $html2pdf->output('tickets-' . $purchase->id . '.pdf'); | 
            ||
| 188 |         } catch (Html2PdfException $e) { | 
            ||
| 189 | $html2pdf->clean();  | 
            ||
| 190 | DB::rollBack();  | 
            ||
| 191 |             return redirect()->route('ticket.purchase', ['purchase' => $purchase])->with('state', $e->getMessage()); | 
            ||
| 192 | }  | 
            ||
| 193 | DB::rollBack();  | 
            ||
| 194 | }  | 
            ||
| 196 |