| Conditions | 4 |
| Paths | 8 |
| Total Lines | 84 |
| Code Lines | 54 |
| 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 |
||
| 23 | public function load(ObjectManager $manager): void |
||
| 24 | { |
||
| 25 | self::bootKernel(); |
||
| 26 | |||
| 27 | $container = $this->getContainer(); |
||
| 28 | $trans = $container->get('translator'); |
||
| 29 | |||
| 30 | $adminId = 1; |
||
| 31 | |||
| 32 | $ticketProject = new TicketProject(); |
||
| 33 | $ticketProject |
||
| 34 | ->setName('Ticket System') |
||
| 35 | ->setInsertUserId($adminId) |
||
| 36 | ; |
||
| 37 | |||
| 38 | $manager->persist($ticketProject); |
||
| 39 | $manager->flush(); |
||
| 40 | |||
| 41 | $categories = [ |
||
| 42 | $trans->trans('Enrollment') => $trans->trans('Tickets about enrollment'), |
||
| 43 | $trans->trans('General information') => $trans->trans('Tickets about general information'), |
||
| 44 | $trans->trans('Requests and paperwork') => $trans->trans('Tickets about requests and paperwork'), |
||
| 45 | $trans->trans('Academic Incidents') => $trans->trans('Tickets about academic incidents, like exams, practices, tasks, etc.'), |
||
| 46 | $trans->trans('Virtual campus') => $trans->trans('Tickets about virtual campus'), |
||
| 47 | $trans->trans('Online evaluation') => $trans->trans('Tickets about online evaluation'), |
||
| 48 | ]; |
||
| 49 | |||
| 50 | $i = 1; |
||
| 51 | foreach ($categories as $category => $description) { |
||
| 52 | // Online evaluation requires a course |
||
| 53 | $ticketCategory = new TicketCategory(); |
||
| 54 | $ticketCategory |
||
| 55 | ->setName($category) |
||
| 56 | ->setDescription($description) |
||
| 57 | ->setProject($ticketProject) |
||
| 58 | ->setInsertUserId($adminId) |
||
| 59 | ; |
||
| 60 | |||
| 61 | $isRequired = 6 === $i; |
||
| 62 | $ticketCategory->setCourseRequired($isRequired); |
||
| 63 | |||
| 64 | $manager->persist($ticketCategory); |
||
| 65 | $i++; |
||
| 66 | } |
||
| 67 | |||
| 68 | // Default Priorities |
||
| 69 | $defaultPriorities = [ |
||
| 70 | TicketManager::PRIORITY_NORMAL => $trans->trans('Normal'), |
||
| 71 | TicketManager::PRIORITY_HIGH => $trans->trans('High'), |
||
| 72 | TicketManager::PRIORITY_LOW => $trans->trans('Low'), |
||
| 73 | ]; |
||
| 74 | |||
| 75 | foreach ($defaultPriorities as $code => $priority) { |
||
| 76 | $ticketPriority = new TicketPriority(); |
||
| 77 | $ticketPriority |
||
| 78 | ->setName($priority) |
||
| 79 | ->setCode($code) |
||
| 80 | ->setInsertUserId($adminId) |
||
| 81 | ; |
||
| 82 | |||
| 83 | $manager->persist($ticketPriority); |
||
| 84 | } |
||
| 85 | |||
| 86 | $manager->flush(); |
||
| 87 | |||
| 88 | // Default status |
||
| 89 | $defaultStatus = [ |
||
| 90 | TicketManager::STATUS_NEW => $trans->trans('New'), |
||
| 91 | TicketManager::STATUS_PENDING => $trans->trans('Pending'), |
||
| 92 | TicketManager::STATUS_UNCONFIRMED => $trans->trans('Unconfirmed'), |
||
| 93 | TicketManager::STATUS_CLOSE => $trans->trans('Close'), |
||
| 94 | TicketManager::STATUS_FORWARDED => $trans->trans('Forwarded'), |
||
| 95 | ]; |
||
| 96 | |||
| 97 | foreach ($defaultStatus as $code => $status) { |
||
| 98 | $ticketStatus = new TicketStatus(); |
||
| 99 | $ticketStatus |
||
| 100 | ->setName($status) |
||
| 101 | ->setCode($code) |
||
| 102 | ; |
||
| 103 | $manager->persist($ticketStatus); |
||
| 104 | } |
||
| 105 | |||
| 106 | $manager->flush(); |
||
| 107 | } |
||
| 109 |