Conditions | 3 |
Paths | 3 |
Total Lines | 70 |
Code Lines | 44 |
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 |
||
24 | public function load(ObjectManager $manager) |
||
25 | { |
||
26 | $faker = Factory::create(); |
||
27 | |||
28 | $user = new User(); |
||
29 | $user->setEmail('[email protected]') |
||
30 | ->setUserName('admin') |
||
31 | ->setPassword($this->passwordEncoder->encodePassword( |
||
32 | $user, |
||
33 | 'admin' |
||
34 | )) |
||
35 | ->setRoles(['ROLE_ADMIN']) |
||
36 | ->setImage($faker->image('public/uploads/user_images',400,300, null, false) ) |
||
37 | ->setVerified(true) |
||
38 | ->setVerifiedHash(bin2hex(random_bytes(16))); |
||
39 | |||
40 | // $product = new Product(); |
||
41 | $manager->persist($user); |
||
42 | |||
43 | $user = new User(); |
||
44 | $user->setEmail('[email protected]') |
||
45 | ->setUserName('user') |
||
46 | ->setPassword($this->passwordEncoder->encodePassword( |
||
47 | $user, |
||
48 | 'user' |
||
49 | )) |
||
50 | ->setImage($faker->image('public/uploads/user_images',400,300, null, false) ) |
||
51 | ->setVerified(true) |
||
52 | ->setVerifiedHash(bin2hex(random_bytes(16))); |
||
53 | |||
54 | // $product = new Product(); |
||
55 | $manager->persist($user); |
||
56 | |||
57 | $user = new User(); |
||
58 | $user->setEmail('[email protected]') |
||
59 | ->setUserName('usertest') |
||
60 | ->setPassword($this->passwordEncoder->encodePassword( |
||
61 | $user, |
||
62 | 'user' |
||
63 | )) |
||
64 | ->setVerified(false) |
||
65 | ->setVerifiedHash(bin2hex(random_bytes(16))); |
||
66 | |||
67 | $manager->persist($user); |
||
68 | |||
69 | |||
70 | |||
71 | //Adding extra users |
||
72 | |||
73 | for($i=0; $i<10; $i++){ |
||
74 | $user = new User(); |
||
75 | $user->setEmail('user'.$i.'@localhost.com') |
||
76 | ->setUserName('user'.$i) |
||
77 | ->setPassword($this->passwordEncoder->encodePassword( |
||
78 | $user, |
||
79 | 'user' |
||
80 | )) |
||
81 | |||
82 | ->setVerified(true) |
||
83 | ->setVerifiedHash(bin2hex(random_bytes(16))); |
||
84 | |||
85 | //Not all users will have an image |
||
86 | if(rand(0,2)>=1){ |
||
87 | $user->setImage($faker->image('public/uploads/user_images',400,300, null, false) ); |
||
88 | } |
||
89 | // $product = new Product(); |
||
90 | $manager->persist($user); |
||
91 | } |
||
92 | |||
93 | $manager->flush(); |
||
94 | |||
97 |