| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 40 |
| 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 |
||
| 30 | public function load(ObjectManager $manager): void |
||
| 31 | { |
||
| 32 | $timezone = 'Europe\Paris'; |
||
| 33 | |||
| 34 | $container = $this->container; |
||
| 35 | |||
| 36 | $toolChain = $container->get(ToolChain::class); |
||
| 37 | $toolChain->createTools($manager); |
||
| 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 | ; |
||
| 54 | |||
| 55 | $manager->persist($admin); |
||
| 56 | |||
| 57 | /** @var UserRepository $userRepo */ |
||
| 58 | $userRepo = $container->get(UserRepository::class); |
||
| 59 | $userRepo->updateUser($admin); |
||
| 60 | |||
| 61 | $anon = (new User()) |
||
| 62 | ->setSkipResourceNode(true) |
||
| 63 | ->setLastname('Joe') |
||
| 64 | ->setFirstname('Anonymous') |
||
| 65 | ->setUsername('anon') |
||
| 66 | ->setStatus(ANONYMOUS) |
||
| 67 | ->setPlainPassword('anon') |
||
| 68 | ->setEmail('anonymous@localhost') |
||
| 69 | ->setOfficialCode('anonymous') |
||
| 70 | ->setCreatorId(1) |
||
| 71 | ->setAuthSource(PLATFORM_AUTH_SOURCE) |
||
| 72 | ->setTimezone($timezone) |
||
| 73 | ; |
||
| 74 | $manager->persist($anon); |
||
| 75 | $manager->flush(); |
||
| 76 | |||
| 77 | $userRepo->addUserToResourceNode($admin->getId(), $admin->getId()); |
||
| 78 | $userRepo->addUserToResourceNode($anon->getId(), $admin->getId()); |
||
| 79 | |||
| 80 | $manager->flush(); |
||
| 81 | |||
| 82 | $this->addReference(self::ADMIN_USER_REFERENCE, $admin); |
||
| 83 | $this->addReference(self::ANON_USER_REFERENCE, $anon); |
||
| 84 | } |
||
| 86 |