| Conditions | 7 |
| Paths | 16 |
| Total Lines | 59 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 39 | public function warmUp($cacheDirectory): array |
||
| 40 | { |
||
| 41 | /** @var mixed $entitiesFolder */ |
||
| 42 | $entitiesFolder = sprintf( |
||
| 43 | '%s/%s', |
||
| 44 | $cacheDirectory, |
||
| 45 | $this->folderNameInCache |
||
| 46 | ); |
||
| 47 | |||
| 48 | $codeGenerator = new BlackMagicEntityCodeGenerator( |
||
| 49 | $entitiesFolder, |
||
| 50 | $this->dataLoader |
||
| 51 | ); |
||
| 52 | |||
| 53 | /** @var array<int, array{0:string, 1:string> $classmap */ |
||
| 54 | $classmap = array(); |
||
| 55 | |||
| 56 | foreach ($this->doctrineMappingDriver->getAllClassNames() as $entityClass) { |
||
| 57 | |||
| 58 | /** @var EntityMappingInterface|null $mapping */ |
||
| 59 | $mapping = $this->rdmMappingDriver->loadRDMMetadataForClass($entityClass); |
||
| 60 | |||
| 61 | if (is_object($mapping)) { |
||
| 62 | /** @var string|null $processedEntityFilePath */ |
||
| 63 | $processedEntityFilePath = $codeGenerator->processMapping( |
||
| 64 | $mapping, |
||
| 65 | AddiksRDMBundle::classLoader() |
||
| 66 | ); |
||
| 67 | |||
| 68 | if (!empty($this->projectRootFolder)) { |
||
| 69 | $processedEntityFilePath = realpath($processedEntityFilePath); |
||
| 70 | |||
| 71 | if (str_starts_with($processedEntityFilePath, $this->projectRootFolder)) { |
||
| 72 | $processedEntityFilePath = substr( |
||
| 73 | $processedEntityFilePath, |
||
| 74 | strlen($this->projectRootFolder) |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | if (is_string($processedEntityFilePath)) { |
||
| 80 | $classmap[] = [$entityClass, $processedEntityFilePath]; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if (!is_dir($entitiesFolder)) { |
||
| 86 | mkdir($entitiesFolder, 0777, true); |
||
| 87 | } |
||
| 88 | |||
| 89 | file_put_contents( |
||
| 90 | $entitiesFolder . '/classmap', |
||
| 91 | implode("\n", array_map( |
||
| 92 | fn ($l) => $l[0] . ':' . $l[1], |
||
| 93 | $classmap |
||
| 94 | )) |
||
| 95 | ); |
||
| 96 | |||
| 97 | return []; # Files to preload |
||
| 98 | } |
||
| 106 |