| Conditions | 2 |
| Paths | 2 |
| Total Lines | 94 |
| Code Lines | 77 |
| 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 |
||
| 55 | public function load(ObjectManager $manager) |
||
| 56 | { |
||
| 57 | $dataArray = array( |
||
| 58 | array( |
||
| 59 | 'name' => 'user1', |
||
| 60 | 'superadmin' => true, |
||
| 61 | 'enabled' => true, |
||
| 62 | 'locked' => false, |
||
| 63 | 'mine' => 'mine1-mine', |
||
| 64 | ), |
||
| 65 | array( |
||
| 66 | 'name' => 'user2', |
||
| 67 | 'superadmin' => false, |
||
| 68 | 'enabled' => true, |
||
| 69 | 'locked' => false, |
||
| 70 | 'mine' => 'mine2-mine', |
||
| 71 | ), |
||
| 72 | array( |
||
| 73 | 'name' => 'lock', |
||
| 74 | 'superadmin' => false, |
||
| 75 | 'enabled' => true, |
||
| 76 | 'locked' => true, |
||
| 77 | 'mine' => 'mine3-mine', |
||
| 78 | ), |
||
| 79 | array( |
||
| 80 | 'name' => 'disable', |
||
| 81 | 'superadmin' => false, |
||
| 82 | 'enabled' => false, |
||
| 83 | 'locked' => false, |
||
| 84 | 'mine' => 'mine4-mine', |
||
| 85 | ), |
||
| 86 | array( |
||
| 87 | 'name' => 'super', |
||
| 88 | 'superadmin' => true, |
||
| 89 | 'enabled' => true, |
||
| 90 | 'locked' => false, |
||
| 91 | 'mine' => 'mine5-mine', |
||
| 92 | ), |
||
| 93 | array( |
||
| 94 | 'name' => 'user6', |
||
| 95 | 'superadmin' => true, |
||
| 96 | 'enabled' => true, |
||
| 97 | 'locked' => false, |
||
| 98 | 'mine' => 'mine6-mine', |
||
| 99 | ), |
||
| 100 | array( |
||
| 101 | 'name' => 'user7', |
||
| 102 | 'superadmin' => true, |
||
| 103 | 'enabled' => true, |
||
| 104 | 'locked' => false, |
||
| 105 | 'mine' => 'mine7-mine', |
||
| 106 | ), |
||
| 107 | array( |
||
| 108 | 'name' => 'user8', |
||
| 109 | 'superadmin' => true, |
||
| 110 | 'enabled' => true, |
||
| 111 | 'locked' => false, |
||
| 112 | 'mine' => 'mine8-mine', |
||
| 113 | ), |
||
| 114 | array( |
||
| 115 | 'name' => 'user9', |
||
| 116 | 'superadmin' => true, |
||
| 117 | 'enabled' => true, |
||
| 118 | 'locked' => false, |
||
| 119 | 'mine' => 'mine9-mine', |
||
| 120 | ), |
||
| 121 | array( |
||
| 122 | 'name' => 'user10', |
||
| 123 | 'superadmin' => true, |
||
| 124 | 'enabled' => true, |
||
| 125 | 'locked' => false, |
||
| 126 | 'mine' => 'mine10-mine', |
||
| 127 | ), |
||
| 128 | ); |
||
| 129 | $userManager = $this->container->get('fos_user.user_manager'); |
||
| 130 | $objectList = array(); |
||
| 131 | |||
| 132 | foreach ($dataArray as $i => $data) { |
||
| 133 | $objectList[$i] = $userManager->createUser(); |
||
| 134 | $objectList[$i]->setUsername($data['name']); |
||
| 135 | $objectList[$i]->setEmail($data['name'].'@example.com'); |
||
| 136 | $objectList[$i]->setEnabled($data['enabled']); |
||
| 137 | $objectList[$i]->setPlainPassword('pass4'.$data['name']); |
||
| 138 | $objectList[$i]->setEmail($data['name'].'@example.com'); |
||
| 139 | $objectList[$i]->setSuperAdmin($data['superadmin']); |
||
| 140 | $objectList[$i]->setLocked($data['locked']); |
||
| 141 | $objectList[$i]->setMine($this->getReference($data['mine'])); |
||
|
|
|||
| 142 | |||
| 143 | $userManager->updateUser($objectList[$i]); |
||
| 144 | |||
| 145 | $ref = $data['name'].'-user'; |
||
| 146 | $this->addReference($ref, $objectList[$i]); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 175 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.