| Conditions | 7 |
| Paths | 33 |
| Total Lines | 66 |
| Code Lines | 37 |
| 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 |
||
| 28 | public function load(ObjectManager $manager) |
||
| 29 | { |
||
| 30 | /** @var User $user */ |
||
| 31 | $user = $this->getReference(UserFixtures::TESTER_REFERENCE); |
||
| 32 | |||
| 33 | $entries = [ |
||
| 34 | [ |
||
| 35 | ['TheAlternative', 'Console Toolkit 2020', 'Learn how to master the console!', '2020-12-22T18:00:00', null], // event details |
||
| 36 | [null, null, null, false], // registration restrictions: no restrictions |
||
| 37 | ], |
||
| 38 | [ |
||
| 39 | ['TheAlternative', 'Free Software & Open Source 2020', 'The basics about Free Software & Open Source and why you should use it.', '2020-12-26T18:00:00', '2020-12-26T20:00:00'], // event details |
||
| 40 | [10, null, null, false], // registration restrictions: max 10 participants |
||
| 41 | ], |
||
| 42 | [ |
||
| 43 | ['TheAlternative', 'Bash Workshops 2020', 'Bash commands & Linux Basics to master your studies.', '2020-12-26T18:00:00', null], // event details |
||
| 44 | [10, '2019-12-26T18:00:00', '2022-12-26T18:00:00', false], // registration restrictions: open |
||
| 45 | ], |
||
| 46 | [ |
||
| 47 | ['TheAlternative', 'Bash Workshops 2019', 'Bash commands & Linux Basics to master your studies.', '2020-12-26T18:00:00', null], // event details |
||
| 48 | [10, '2019-12-26T18:00:00', '2019-12-26T20:00:00', false], // registration restrictions: closed |
||
| 49 | ], |
||
| 50 | [ |
||
| 51 | ['TheAlternative', 'Console Toolkit 2019', 'Learn how to master the console!', '2020-12-22T18:00:00', null], // event details |
||
| 52 | [null, null, null, true], // registration restrictions: closed |
||
| 53 | ], |
||
| 54 | [ |
||
| 55 | ['TheAlternative', 'Free Software & Open Source 2019', 'The basics about Free Software & Open Source and why you should use it.', '2020-12-26T18:00:00', '2020-12-26T20:00:00'], // event details |
||
| 56 | [null, null, null, true], // registration restrictions: max 10 participants |
||
| 57 | ], |
||
| 58 | ]; |
||
| 59 | |||
| 60 | foreach ($entries as $entry) { |
||
| 61 | $event = new Event(); |
||
| 62 | |||
| 63 | $eventDetails = $entry[0]; |
||
| 64 | $event->setOrganizer($eventDetails[0]); |
||
| 65 | $event->setName($eventDetails[1]); |
||
| 66 | $event->setDescription($eventDetails[2]); |
||
| 67 | $event->setStartDate(new \DateTime($eventDetails[3])); |
||
| 68 | if (null !== $eventDetails[4]) { |
||
| 69 | $event->setEndDate(new \DateTime($eventDetails[4])); |
||
| 70 | } |
||
| 71 | |||
| 72 | $registrationRestrictions = $entry[1]; |
||
| 73 | if (null !== $registrationRestrictions[0]) { |
||
| 74 | $event->setMaximumAttendeeCapacity($registrationRestrictions[0]); |
||
| 75 | } |
||
| 76 | if (null !== $registrationRestrictions[1]) { |
||
| 77 | $event->setRegistrationOpen(new \DateTime($registrationRestrictions[1])); |
||
| 78 | } |
||
| 79 | if (null !== $registrationRestrictions[2]) { |
||
| 80 | $event->setRegistrationClose(new \DateTime($registrationRestrictions[2])); |
||
| 81 | } |
||
| 82 | if ($registrationRestrictions[3]) { |
||
| 83 | $event->close(); |
||
| 84 | } |
||
| 85 | |||
| 86 | $manager->getRepository(Event::class)->save($event); |
||
| 87 | |||
| 88 | $registration = Registration::createFromUser($event, $user, true); |
||
| 89 | $registrationRepository = $manager->getRepository(Registration::class); |
||
| 90 | $registrationRepository->save($registration); |
||
| 91 | } |
||
| 92 | |||
| 93 | $manager->flush(); |
||
| 94 | } |
||
| 101 |