| Conditions | 12 |
| Paths | 27 |
| Total Lines | 55 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 41 | public function getConfig(array $allMetadata) |
||
| 42 | { |
||
| 43 | $config = []; |
||
| 44 | |||
| 45 | foreach ($allMetadata as $metadata) { |
||
| 46 | $reflClass = new \ReflectionClass($metadata->name); |
||
| 47 | $classAnnotation = $this->annotationReader->getClassAnnotation($reflClass, AnonymizerTable::class); |
||
| 48 | if (!$classAnnotation instanceof AnonymizerTable) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | $tableName = $metadata->table['name']; |
||
| 53 | $config[$tableName] = [ |
||
| 54 | 'primary_key' => $metadata->identifier, |
||
| 55 | 'fields' => [], |
||
| 56 | ]; |
||
| 57 | |||
| 58 | if ($classAnnotation->truncate) { |
||
| 59 | $config[$tableName]['truncate'] = true; |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | |||
| 63 | foreach ($metadata->fieldMappings as $fieldName => $fieldMapping) { |
||
| 64 | if (in_array($fieldName, $metadata->identifier)) { |
||
| 65 | continue; |
||
| 66 | } |
||
| 67 | |||
| 68 | $reflProperty = $reflClass->getProperty($fieldName); |
||
| 69 | |||
| 70 | $fieldAnnotation = $this->annotationReader->getPropertyAnnotation($reflProperty, AnonymizerField::class); |
||
| 71 | $fieldConfig = null; |
||
| 72 | if ($fieldAnnotation instanceof AnonymizerField) { |
||
| 73 | $fieldConfig = $fieldAnnotation->getConfig(); |
||
| 74 | } elseif ($classAnnotation->guess) { |
||
| 75 | try { |
||
| 76 | $fieldConfig = $this->configGuesser::guessColumn($fieldName)->getConfigArray(); |
||
| 77 | } catch (GuesserMissingHintException $e) { |
||
| 78 | try { |
||
| 79 | $fieldConfig = $this->configGuesser::guessColumn($fieldMapping['columnName'])->getConfigArray(); |
||
| 80 | } catch (GuesserMissingHintException $e) { |
||
|
|
|||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($fieldConfig) { |
||
| 86 | $config[$tableName]['fields'][$fieldMapping['columnName']] = $fieldConfig; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if (empty($config[$tableName]['fields'])) { |
||
| 91 | unset($config[$tableName]); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | return ['tables' => $config]; |
||
| 96 | } |
||
| 98 |