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