Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
35 | public function vipTicketsShouldAlwaysBeCreated() |
||
36 | { |
||
37 | /* @var $em \Doctrine\Common\Persistence\ObjectManager */ |
||
38 | $client = static::createClient(); |
||
39 | $container = $client->getContainer(); |
||
40 | $em = $container |
||
41 | ->get('doctrine') |
||
42 | ->getManager(); |
||
43 | |||
44 | $event = $em->getRepository('BCRMBackendBundle:Event\Event')->findAll()[0]; |
||
45 | |||
46 | // Create normal registrations |
||
47 | $johnPays = new Payment(); |
||
48 | $johnPays->setTransactionId('johnpay'); |
||
49 | $johnPays->setMethod('cash'); |
||
50 | $em->persist($johnPays); |
||
51 | $john = new Registration(); |
||
52 | $john->setUuid('john'); |
||
53 | $john->setName('John'); |
||
54 | $john->setEvent($event); |
||
55 | $john->setEmail('[email protected]'); |
||
56 | $john->setSaturday(true); |
||
57 | $john->setPayment($johnPays); |
||
58 | $em->persist($john); |
||
59 | |||
60 | $maryPays = new Payment(); |
||
61 | $maryPays->setTransactionId('marypay'); |
||
62 | $maryPays->setMethod('cash'); |
||
63 | $em->persist($maryPays); |
||
64 | $mary = new Registration(); |
||
65 | $mary->setUuid('mary'); |
||
66 | $mary->setName('Mary'); |
||
67 | $mary->setEvent($event); |
||
68 | $mary->setEmail('[email protected]'); |
||
69 | $mary->setSaturday(true); |
||
70 | $mary->setPayment($maryPays); |
||
71 | $em->persist($mary); |
||
72 | |||
73 | $em->flush(); |
||
74 | |||
75 | $this->createTicketsCommand($container); |
||
|
|||
76 | |||
77 | $this->assertEquals(2, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
||
78 | 'event' => $event, |
||
79 | 'day' => Ticket::DAY_SATURDAY, |
||
80 | )))); |
||
81 | |||
82 | // Create VIP registration |
||
83 | $vip = new Registration(); |
||
84 | $vip->setUuid('VIP'); |
||
85 | $vip->setName('VIP'); |
||
86 | $vip->setEvent($event); |
||
87 | $vip->setEmail('[email protected]'); |
||
88 | $vip->setSaturday(true); |
||
89 | $vip->setType(Registration::TYPE_VIP); |
||
90 | $em->persist($vip); |
||
91 | |||
92 | // Create Sponsor registration |
||
93 | $sponsor = new Registration(); |
||
94 | $sponsor->setUuid('Sponsor'); |
||
95 | $sponsor->setName('Sponsor'); |
||
96 | $sponsor->setEvent($event); |
||
97 | $sponsor->setEmail('[email protected]'); |
||
98 | $sponsor->setSaturday(true); |
||
99 | $sponsor->setType(Registration::TYPE_SPONSOR); |
||
100 | $em->persist($sponsor); |
||
101 | |||
102 | $em->flush(); |
||
103 | |||
104 | $this->createTicketsCommand($container); |
||
105 | |||
106 | $this->assertEquals(4, count($em->getRepository('BCRMBackendBundle:Event\Ticket')->findBy(array( |
||
107 | 'event' => $event, |
||
108 | 'day' => Ticket::DAY_SATURDAY, |
||
109 | )))); |
||
110 | } |
||
111 | |||
205 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: