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