| Conditions | 33 |
| Paths | 189 |
| Total Lines | 100 |
| Code Lines | 80 |
| 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 |
||
| 139 | private function buildFactoryData(ClassMetadata $metaData): array |
||
| 140 | { |
||
| 141 | $data = []; |
||
| 142 | |||
| 143 | foreach ($metaData->fieldMappings as $fieldMapping) { |
||
| 144 | switch ($fieldMapping['type']) { |
||
| 145 | case 'smallint': |
||
| 146 | case 'integer': |
||
| 147 | case 'bigint': |
||
| 148 | $data[] = sprintf( |
||
| 149 | " '%s' => random_int(0, 65000),\n", |
||
| 150 | $fieldMapping['fieldName'] |
||
| 151 | ); |
||
| 152 | break; |
||
| 153 | case 'decimal': |
||
| 154 | case 'float': |
||
| 155 | $data[] = sprintf( |
||
| 156 | " '%s' => Faker::randomFloat(2),\n", |
||
| 157 | $fieldMapping['fieldName'] |
||
| 158 | ); |
||
| 159 | break; |
||
| 160 | case 'string': |
||
| 161 | $data[] = sprintf( |
||
| 162 | " '%s' => Faker::sentence(),\n", |
||
| 163 | $fieldMapping['fieldName'] |
||
| 164 | ); |
||
| 165 | break; |
||
| 166 | case 'text': |
||
| 167 | $data[] = sprintf( |
||
| 168 | " '%s' => Faker::paragraph(),\n", |
||
| 169 | $fieldMapping['fieldName'] |
||
| 170 | ); |
||
| 171 | break; |
||
| 172 | case 'guid': |
||
| 173 | $data[] = sprintf( |
||
| 174 | " '%s' => uniqid('', true)", |
||
| 175 | $fieldMapping['fieldName'] |
||
| 176 | ); |
||
| 177 | break; |
||
| 178 | case 'binary': |
||
| 179 | case 'blob': |
||
| 180 | break; |
||
| 181 | case 'boolean': |
||
| 182 | $data[] = sprintf( |
||
| 183 | " '%s' => (bool)random_int(0, 1),\n", |
||
| 184 | $fieldMapping['fieldName'] |
||
| 185 | ); |
||
| 186 | break; |
||
| 187 | case 'date': |
||
| 188 | case 'date_immutable': |
||
| 189 | case 'datetime': |
||
| 190 | case 'datetime_immutable': |
||
| 191 | case 'datetimetz': |
||
| 192 | case 'datetimetz_immutable': |
||
| 193 | case 'time': |
||
| 194 | case 'time_immutable': |
||
| 195 | $data[] = sprintf( |
||
| 196 | " '%s' => Faker::dateTime(),\n", |
||
| 197 | $fieldMapping['fieldName'] |
||
| 198 | ); |
||
| 199 | break; |
||
| 200 | case 'dateinterval': |
||
| 201 | case 'array': |
||
| 202 | case 'simple_array': |
||
| 203 | case 'json': |
||
| 204 | case 'json_array': |
||
| 205 | case 'object': |
||
| 206 | break; |
||
| 207 | default: |
||
| 208 | $data[] = sprintf( |
||
| 209 | " '%s' => Faker::word(),\n", |
||
| 210 | $fieldMapping['fieldName'] |
||
| 211 | ); |
||
| 212 | break; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | |||
| 216 | foreach ($metaData->associationMappings as $associationMapping) { |
||
| 217 | switch ($associationMapping['type']) { |
||
| 218 | case 1: |
||
| 219 | case 2: |
||
| 220 | case 3: |
||
| 221 | $data[] = sprintf( |
||
| 222 | " '%s' => 'entity|' . \\%s::class,\n", |
||
| 223 | $associationMapping['fieldName'], |
||
| 224 | $associationMapping['targetEntity'] |
||
| 225 | ); |
||
| 226 | break; |
||
| 227 | case 4: |
||
| 228 | // TODO one to many |
||
| 229 | break; |
||
| 230 | case 8: |
||
| 231 | // TODO many to many |
||
| 232 | break; |
||
| 233 | default: |
||
| 234 | break; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | return $data; |
||
| 239 | } |
||
| 267 | } |