| Conditions | 3 |
| Paths | 4 |
| Total Lines | 76 |
| Code Lines | 62 |
| 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 |
||
| 32 | public function listUnprintedTickets() |
||
| 33 | { |
||
| 34 | $client = static::createClient(); |
||
| 35 | $container = $client->getContainer(); |
||
| 36 | |||
| 37 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
| 38 | $em = $container |
||
| 39 | ->get('doctrine') |
||
| 40 | ->getManager(); |
||
| 41 | $event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
||
| 42 | |||
| 43 | // Create registrations |
||
| 44 | for ($i = 0; $i < 5; $i++) { |
||
| 45 | $payment = new Payment(); |
||
| 46 | $payment->setTransactionId('payment' . $i); |
||
| 47 | $payment->setMethod('cash'); |
||
| 48 | $em->persist($payment); |
||
| 49 | $registration = new Registration(); |
||
| 50 | $registration->setUuid($i); |
||
| 51 | $registration->setEmail(sprintf('john.doe.198%[email protected]', $i)); |
||
| 52 | $registration->setName(sprintf('John Doe %d', $i)); |
||
| 53 | $registration->setEvent($event); |
||
| 54 | $registration->setSaturday(false); |
||
| 55 | $registration->setSunday(true); |
||
| 56 | $registration->setTags(sprintf('#johndoe%d', $i)); |
||
| 57 | $registration->setPayment($payment); |
||
| 58 | $em->persist($registration); |
||
| 59 | } |
||
| 60 | |||
| 61 | // Create tickets |
||
| 62 | for ($i = 0; $i < 5; $i++) { |
||
| 63 | $checkedIn = $i > 1; |
||
| 64 | $sundayTicket = new Ticket(); |
||
| 65 | $sundayTicket->setEmail(sprintf('john.doe.198%[email protected]', $i)); |
||
| 66 | $sundayTicket->setName(sprintf('John Doe %d', $i)); |
||
| 67 | $sundayTicket->setEvent($event); |
||
| 68 | $sundayTicket->setDay(Ticket::DAY_SUNDAY); |
||
| 69 | $sundayTicket->setCode(sprintf('PRNT%d', $i)); |
||
| 70 | $sundayTicket->setNotified(true); |
||
| 71 | $sundayTicket->setCheckedIn($checkedIn); |
||
| 72 | $em->persist($sundayTicket); |
||
| 73 | $saturdayTicket = new Ticket(); |
||
| 74 | $saturdayTicket->setEmail(sprintf('john.doe.198%[email protected]', $i)); |
||
| 75 | $saturdayTicket->setName(sprintf('John Doe %d', $i)); |
||
| 76 | $saturdayTicket->setEvent($event); |
||
| 77 | $saturdayTicket->setDay(Ticket::DAY_SATURDAY); |
||
| 78 | $saturdayTicket->setCode(sprintf('NOPRNT%d', $i)); |
||
| 79 | $saturdayTicket->setNotified(true); |
||
| 80 | $saturdayTicket->setCheckedIn($checkedIn); |
||
| 81 | $em->persist($saturdayTicket); |
||
| 82 | } |
||
| 83 | $em->flush(); |
||
| 84 | |||
| 85 | $client = static::createClient(array(), array( |
||
| 86 | 'PHP_AUTH_USER' => 'concierge', |
||
| 87 | 'PHP_AUTH_PW' => 'letmein', |
||
| 88 | )); |
||
| 89 | $client->request('GET', '/api/printing/queue'); |
||
| 90 | $response = $client->getResponse(); |
||
| 91 | $this->assertEquals(200, $response->getStatusCode()); |
||
| 92 | $this->assertEquals("application/json", $response->headers->get('Content-Type')); |
||
| 93 | $this->assertEquals("utf-8", $response->getCharset()); |
||
| 94 | $queue = json_decode($response->getContent()); |
||
| 95 | $this->assertEquals(3, count($queue->items)); |
||
| 96 | |||
| 97 | $ticket = $queue->items[0]; |
||
| 98 | $this->assertObjectHasAttribute('name', $ticket); |
||
| 99 | $this->assertObjectHasAttribute('tags', $ticket); |
||
| 100 | $this->assertObjectHasAttribute('code', $ticket); |
||
| 101 | $this->assertObjectHasAttribute('day', $ticket); |
||
| 102 | $this->assertEquals('#' . strtolower(str_replace(' ', '', $ticket->name)), $ticket->tags); |
||
| 103 | $this->assertEquals(1, preg_match('/^PRNT[0-9]+$/', $ticket->code)); |
||
| 104 | $this->assertEquals(2, $ticket->day); |
||
| 105 | |||
| 106 | return $queue->items; |
||
| 107 | } |
||
| 108 | |||
| 169 |