| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 42 |
| 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 |
||
| 29 | public function load(ObjectManager $manager): void |
||
| 30 | { |
||
| 31 | $timezone = 'Europe\Paris'; |
||
| 32 | $container = $this->container; |
||
| 33 | $toolChain = $container->get(ToolChain::class); |
||
| 34 | $toolChain->createTools(); |
||
| 35 | |||
| 36 | // Defined in AccessGroupFixtures.php. |
||
| 37 | $group = $this->getReference('GROUP_ADMIN'); |
||
| 38 | |||
| 39 | $admin = (new User()) |
||
| 40 | ->setSkipResourceNode(true) |
||
| 41 | ->setLastname('Doe') |
||
| 42 | ->setFirstname('Joe') |
||
| 43 | ->setUsername('admin') |
||
| 44 | ->setStatus(1) |
||
| 45 | ->setPlainPassword('admin') |
||
| 46 | ->setEmail('[email protected]') |
||
| 47 | ->setOfficialCode('ADMIN') |
||
| 48 | ->setCreatorId(1) |
||
| 49 | ->setAuthSource(PLATFORM_AUTH_SOURCE) |
||
| 50 | ->setTimezone($timezone) |
||
| 51 | ->addUserAsAdmin() |
||
| 52 | ->addRole('ROLE_GLOBAL_ADMIN') |
||
| 53 | ->addGroup($group) |
||
| 54 | ; |
||
| 55 | |||
| 56 | $manager->persist($admin); |
||
| 57 | |||
| 58 | /** @var UserRepository $userRepo */ |
||
| 59 | $userRepo = $container->get(UserRepository::class); |
||
| 60 | $userRepo->updateUser($admin); |
||
| 61 | |||
| 62 | $anon = (new User()) |
||
| 63 | ->setSkipResourceNode(true) |
||
| 64 | ->setLastname('Joe') |
||
| 65 | ->setFirstname('Anonymous') |
||
| 66 | ->setUsername('anon') |
||
| 67 | ->setStatus(ANONYMOUS) |
||
| 68 | ->setPlainPassword('anon') |
||
| 69 | ->setEmail('anonymous@localhost') |
||
| 70 | ->setOfficialCode('anonymous') |
||
| 71 | ->setCreatorId(1) |
||
| 72 | ->setAuthSource(PLATFORM_AUTH_SOURCE) |
||
| 73 | ->setTimezone($timezone) |
||
| 74 | ; |
||
| 75 | $manager->persist($anon); |
||
| 76 | $manager->flush(); |
||
| 77 | |||
| 78 | $userRepo->addUserToResourceNode($admin->getId(), $admin->getId()); |
||
| 79 | $userRepo->addUserToResourceNode($anon->getId(), $admin->getId()); |
||
| 80 | |||
| 81 | $manager->flush(); |
||
| 82 | |||
| 83 | $this->addReference(self::ADMIN_USER_REFERENCE, $admin); |
||
| 84 | $this->addReference(self::ANON_USER_REFERENCE, $anon); |
||
| 85 | } |
||
| 87 |