| Conditions | 7 |
| Paths | 20 |
| Total Lines | 66 |
| Code Lines | 46 |
| 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 |
||
| 58 | private function processUserDirectory(string $userId, string $userDir, User $fallbackUser, bool $splitUsersUploadDirectory): void |
||
| 59 | { |
||
| 60 | $userEntity = $this->entityManager->getRepository(User::class)->find($userId); |
||
| 61 | $userToAssign = $userEntity ?? $fallbackUser; |
||
| 62 | |||
| 63 | if ($userEntity === null) { |
||
| 64 | error_log("User with ID {$userId} not found. Using fallback_user."); |
||
| 65 | } else { |
||
| 66 | error_log("Processing files for user with ID {$userId}."); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($splitUsersUploadDirectory) { |
||
| 70 | $baseDir = $userDir.'/'; |
||
| 71 | } else { |
||
| 72 | $baseDir = $this->getUpdateRootPath().'/app/upload/users/'.$userId.'/'; |
||
| 73 | } |
||
| 74 | |||
| 75 | error_log("Final path to check: {$baseDir}"); |
||
| 76 | |||
| 77 | if (!is_dir($baseDir)) { |
||
| 78 | error_log("Directory not found for user with ID {$userId}. Skipping."); |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | |||
| 82 | $myFilesDir = $baseDir.'my_files/'; |
||
| 83 | $files = glob($myFilesDir.'*'); |
||
| 84 | |||
| 85 | foreach ($files as $file) { |
||
| 86 | if (!is_file($file)) { |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | $title = basename($file); |
||
| 91 | error_log("Processing file: {$file} for user with ID {$userToAssign->getId()}."); |
||
| 92 | |||
| 93 | $queryBuilder = $this->entityManager->createQueryBuilder(); |
||
| 94 | $queryBuilder |
||
| 95 | ->select('p') |
||
| 96 | ->from(ResourceNode::class, 'n') |
||
| 97 | ->innerJoin(PersonalFile::class, 'p', Join::WITH, 'p.resourceNode = n.id') |
||
| 98 | ->where('n.title = :title') |
||
| 99 | ->andWhere('n.creator = :creator') |
||
| 100 | ->setParameter('title', $title) |
||
| 101 | ->setParameter('creator', $userToAssign->getId()); |
||
| 102 | |||
| 103 | $result = $queryBuilder->getQuery()->getOneOrNullResult(); |
||
| 104 | |||
| 105 | if ($result) { |
||
| 106 | error_log('MIGRATIONS :: '.$file.' (Skipped: Already exists) ...'); |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | error_log("MIGRATIONS :: Associating file {$file} to user with ID {$userToAssign->getId()}."); |
||
| 111 | $personalFile = new PersonalFile(); |
||
| 112 | $personalFile->setTitle($title); |
||
| 113 | $personalFile->setCreator($userToAssign); |
||
| 114 | $personalFile->setParentResourceNode($userToAssign->getResourceNode()->getId()); |
||
| 115 | $personalFile->setResourceName($title); |
||
| 116 | $mimeType = mime_content_type($file); |
||
| 117 | $uploadedFile = new UploadedFile($file, $title, $mimeType, null, true); |
||
| 118 | $personalFile->setUploadFile($uploadedFile); |
||
| 119 | $personalFile->addUserLink($userToAssign); |
||
| 120 | |||
| 121 | // Save the object to the database |
||
| 122 | $this->entityManager->persist($personalFile); |
||
| 123 | $this->entityManager->flush(); |
||
| 124 | } |
||
| 132 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.