| Total Complexity | 41 |
| Total Lines | 208 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Complex classes like FileUtils often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FileUtils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | class FileUtils { |
||
| 46 | private IRootFolder $rootFolder; |
||
| 47 | private IUserMountCache $userMountCache; |
||
| 48 | private IMountManager $mountManager; |
||
| 49 | private SetupManager $setupManager; |
||
| 50 | |||
| 51 | public function __construct( |
||
| 52 | IRootFolder $rootFolder, |
||
| 53 | IUserMountCache $userMountCache, |
||
| 54 | IMountManager $mountManager, |
||
| 55 | SetupManager $setupManager |
||
| 56 | ) { |
||
| 57 | $this->rootFolder = $rootFolder; |
||
| 58 | $this->userMountCache = $userMountCache; |
||
| 59 | $this->mountManager = $mountManager; |
||
| 60 | $this->setupManager = $setupManager; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param FileInfo $file |
||
| 65 | * @return array<string, Node[]> |
||
| 66 | * @throws \OCP\Files\NotPermittedException |
||
| 67 | * @throws \OC\User\NoUserException |
||
| 68 | */ |
||
| 69 | public function getFilesByUser(FileInfo $file): array { |
||
| 70 | $id = $file->getId(); |
||
| 71 | if (!$id) { |
||
| 72 | return []; |
||
| 73 | } |
||
| 74 | |||
| 75 | $mounts = $this->userMountCache->getMountsForFileId($id); |
||
| 76 | $result = []; |
||
| 77 | foreach ($mounts as $mount) { |
||
| 78 | if (isset($result[$mount->getUser()->getUID()])) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | $userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID()); |
||
| 83 | $result[$mount->getUser()->getUID()] = $userFolder->getById($id); |
||
| 84 | } |
||
| 85 | |||
| 86 | return $result; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get file by either id of path |
||
| 91 | * |
||
| 92 | * @param string $fileInput |
||
| 93 | * @return Node|null |
||
| 94 | */ |
||
| 95 | public function getNode(string $fileInput): ?Node { |
||
| 96 | if (is_numeric($fileInput)) { |
||
| 97 | $mounts = $this->userMountCache->getMountsForFileId((int)$fileInput); |
||
| 98 | if (!$mounts) { |
||
| 99 | return null; |
||
| 100 | } |
||
| 101 | $mount = $mounts[0]; |
||
| 102 | $userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID()); |
||
| 103 | $nodes = $userFolder->getById((int)$fileInput); |
||
| 104 | if (!$nodes) { |
||
| 105 | return null; |
||
| 106 | } |
||
| 107 | return $nodes[0]; |
||
| 108 | } else { |
||
| 109 | try { |
||
| 110 | return $this->rootFolder->get($fileInput); |
||
| 111 | } catch (NotFoundException $e) { |
||
| 112 | return null; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | public function formatPermissions(string $type, int $permissions): string { |
||
| 118 | if ($permissions == Constants::PERMISSION_ALL || ($type === 'file' && $permissions == (Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE))) { |
||
| 119 | return "full permissions"; |
||
| 120 | } |
||
| 121 | |||
| 122 | $perms = []; |
||
| 123 | $allPerms = [Constants::PERMISSION_READ => "read", Constants::PERMISSION_UPDATE => "update", Constants::PERMISSION_CREATE => "create", Constants::PERMISSION_DELETE => "delete", Constants::PERMISSION_SHARE => "share"]; |
||
| 124 | foreach ($allPerms as $perm => $name) { |
||
| 125 | if (($permissions & $perm) === $perm) { |
||
| 126 | $perms[] = $name; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | return implode(", ", $perms); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @psalm-suppress UndefinedClass |
||
| 135 | * @psalm-suppress UndefinedInterfaceMethod |
||
| 136 | */ |
||
| 137 | public function formatMountType(IMountPoint $mountPoint): string { |
||
| 165 | } |
||
| 166 | |||
| 167 | public function formatShareType(IShare $share): ?string { |
||
| 168 | switch ($share->getShareType()) { |
||
| 169 | case IShare::TYPE_GROUP: |
||
| 170 | return "group"; |
||
| 171 | case IShare::TYPE_CIRCLE: |
||
| 172 | return "circle"; |
||
| 173 | case IShare::TYPE_DECK: |
||
| 174 | return "deck"; |
||
| 175 | case IShare::TYPE_ROOM: |
||
| 176 | return "room"; |
||
| 177 | case IShare::TYPE_USER: |
||
| 178 | return null; |
||
| 179 | default: |
||
| 180 | return "Unknown (" . $share->getShareType() . ")"; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Print out the largest count($sizeLimits) files in the directory tree |
||
| 186 | * |
||
| 187 | * @param OutputInterface $output |
||
| 188 | * @param Folder $node |
||
| 189 | * @param string $prefix |
||
| 190 | * @param array $sizeLimits largest items that are still in the queue to be printed, ordered ascending |
||
| 191 | * @return int how many items we've printed |
||
| 192 | */ |
||
| 193 | public function outputLargeFilesTree( |
||
| 253 | } |
||
| 254 | } |
||
| 255 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths