| Conditions | 6 | 
| Paths | 8 | 
| Total Lines | 69 | 
| Code Lines | 32 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 1 | Features | 1 | 
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 | ||
| 33 | public function processMapping( | ||
| 34 | EntityMappingInterface $mapping, | ||
| 35 | ClassLoader $loader | ||
| 36 |     ): string|null { | ||
| 37 | /** @var array<array-key, Column> $columns */ | ||
| 38 | $columns = $mapping->collectDBALColumns(); | ||
| 39 | |||
| 40 |         if (empty($columns)) { | ||
| 41 | return null; | ||
| 42 | } | ||
| 43 | |||
| 44 | /** @var string $fullClassName */ | ||
| 45 | $fullClassName = $mapping->getEntityClassName(); | ||
| 46 | |||
| 47 | /** @var string|false $filePath */ | ||
| 48 | $filePath = $loader->findFile($fullClassName); | ||
| 49 | |||
| 50 |         if ($filePath === false) { | ||
| 51 | return null; | ||
| 52 | } | ||
| 53 | |||
| 54 | /** @var string $entityPHP */ | ||
| 55 | $entityPHP = file_get_contents($filePath); | ||
| 56 | |||
| 57 | /** @var int $classStartPosition */ | ||
| 58 | $classStartPosition = self::findClassStartPosition($fullClassName, $entityPHP); | ||
| 59 | |||
| 60 | /** @var array<string, Column> $writtenFieldNames */ | ||
| 61 | $writtenFieldNames = array(); | ||
| 62 | |||
| 63 |         foreach ($columns as $column) { | ||
| 64 | |||
| 65 | /** @var string $fieldName */ | ||
| 66 | $fieldName = $this->dataLoader->columnToFieldName($column); | ||
| 67 | |||
| 68 |             if (isset($writtenFieldNames[$fieldName])) { | ||
| 69 | continue; | ||
| 70 | } | ||
| 71 | |||
| 72 | $writtenFieldNames[$fieldName] = $column; | ||
| 73 | |||
| 74 | /** @var string $fieldPHP */ | ||
| 75 | $fieldPHP = sprintf( | ||
| 76 | "\n%spublic $%s;\n", | ||
| 77 | $this->indenting, | ||
| 78 | $fieldName | ||
| 79 | ); | ||
| 80 | |||
| 81 | $entityPHP = sprintf( | ||
| 82 | '%s%s%s', | ||
| 83 | substr($entityPHP, 0, $classStartPosition), | ||
| 84 | $fieldPHP, | ||
| 85 | substr($entityPHP, $classStartPosition) | ||
| 86 | ); | ||
| 87 | } | ||
| 88 | |||
| 89 | $targetFilePath = sprintf( | ||
| 90 | '%s/%s.php', | ||
| 91 | $this->targetDirectory, | ||
| 92 |             str_replace('\\', '_', $fullClassName) | ||
| 93 | ); | ||
| 94 | |||
| 95 |         if (!is_dir($this->targetDirectory)) { | ||
| 96 | mkdir($this->targetDirectory, 0777, true); | ||
| 97 | } | ||
| 98 | |||
| 99 | file_put_contents($targetFilePath, $entityPHP); | ||
| 100 | |||
| 101 | return $targetFilePath; | ||
| 102 | } | ||
| 195 |