| Total Complexity | 41 |
| Total Lines | 255 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
Complex classes like UserGroupClass 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 UserGroupClass, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class UserGroupClass implements \JsonSerializable { |
||
| 33 | public const TYPE = 'generic'; |
||
| 34 | public const TYPE_PUBLIC = 'public'; |
||
| 35 | public const TYPE_EXTERNAL = 'external'; |
||
| 36 | public const TYPE_CIRCLE = Circle::TYPE; |
||
| 37 | public const TYPE_CONTACT = Contact::TYPE; |
||
| 38 | public const TYPE_CONTACTGROUP = ContactGroup::TYPE; |
||
| 39 | public const TYPE_EMAIL = Email::TYPE; |
||
| 40 | public const TYPE_GROUP = Group::TYPE; |
||
| 41 | public const TYPE_USER = User::TYPE; |
||
| 42 | |||
| 43 | private $l10n; |
||
| 44 | |||
| 45 | /** @var string */ |
||
| 46 | protected $id; |
||
| 47 | |||
| 48 | /** @var string */ |
||
| 49 | protected $type; |
||
| 50 | |||
| 51 | /** @var string */ |
||
| 52 | protected $displayName = ''; |
||
| 53 | |||
| 54 | /** @var string */ |
||
| 55 | protected $description = ''; |
||
| 56 | |||
| 57 | /** @var string */ |
||
| 58 | protected $emailAddress = ''; |
||
| 59 | |||
| 60 | /** @var string */ |
||
| 61 | protected $language = ''; |
||
| 62 | |||
| 63 | /** @var string */ |
||
| 64 | protected $organisation = ''; |
||
| 65 | |||
| 66 | /** @var string */ |
||
| 67 | protected $icon = ''; |
||
| 68 | |||
| 69 | /** @var bool */ |
||
| 70 | protected $isNoUser = true; |
||
| 71 | |||
| 72 | /** @var string[] */ |
||
| 73 | protected $categories = []; |
||
| 74 | |||
| 75 | public function __construct( |
||
| 89 | } |
||
| 90 | |||
| 91 | public function getId(): string { |
||
| 92 | return $this->id; |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | public function getPublicId(): string { |
||
| 99 | return $this->id; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getUser(): string { |
||
| 103 | return $this->id; |
||
| 104 | } |
||
| 105 | |||
| 106 | public function getType(): string { |
||
| 107 | return $this->type; |
||
| 108 | } |
||
| 109 | |||
| 110 | public function getLanguage(): string { |
||
| 111 | return $this->language; |
||
| 112 | } |
||
| 113 | |||
| 114 | public function getDisplayName(): string { |
||
| 115 | return $this->displayName; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function getDescription(): string { |
||
| 119 | return $this->description; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function getIcon(): string { |
||
| 123 | return $this->icon; |
||
| 124 | } |
||
| 125 | |||
| 126 | public function getEmailAddress(): string { |
||
| 127 | return $this->emailAddress ? $this->emailAddress : ''; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function getOrganisation(): string { |
||
| 131 | return $this->organisation; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return string[] |
||
| 136 | * |
||
| 137 | * @psalm-return array<array-key, string> |
||
| 138 | */ |
||
| 139 | public function getCategories(): array { |
||
| 140 | return $this->categories; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getIsNoUser(): bool { |
||
| 145 | } |
||
| 146 | |||
| 147 | public function setType(string $type): string { |
||
| 148 | $this->type = $type; |
||
| 149 | return $this->type; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function setDisplayName(string $displayName): string { |
||
| 153 | $this->displayName = $displayName; |
||
| 154 | return $this->displayName; |
||
| 155 | } |
||
| 156 | |||
| 157 | public function setDescription(string $description): string { |
||
| 158 | $this->description = $description; |
||
| 159 | return $this->description; |
||
| 160 | } |
||
| 161 | |||
| 162 | public function setEmailAddress(string $emailAddress) : string { |
||
| 163 | $this->emailAddress = $emailAddress; |
||
| 164 | return $this->emailAddress; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function setLanguage(string $language): string { |
||
| 168 | $this->language = $language; |
||
| 169 | return $this->language; |
||
| 170 | } |
||
| 171 | |||
| 172 | public function setOrganisation($organisation): string { |
||
| 173 | $this->organisation = $organisation; |
||
| 174 | return $this->organisation; |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * serach all sharees - use ISearch to respect autocomplete restrictions |
||
| 179 | * |
||
| 180 | * Undocumented function long description |
||
| 181 | * |
||
| 182 | * @param type var Description |
||
| 183 | * @return return type |
||
| 184 | */ |
||
| 185 | public static function search(string $query = ''): array { |
||
| 186 | $c = self::getContainer(); |
||
| 187 | $items = []; |
||
| 188 | $types = [ |
||
| 189 | IShare::TYPE_USER, |
||
| 190 | IShare::TYPE_GROUP |
||
| 191 | ]; |
||
| 192 | if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
||
| 193 | $types[] = IShare::TYPE_CIRCLE; |
||
| 194 | } |
||
| 195 | |||
| 196 | \OC::$server->getLogger()->alert('before ISearch ' . time()); |
||
| 197 | |||
| 198 | list($result, $more) = $c->query(ISearch::class)->search($query, $types, false, 200, 0); |
||
| 199 | |||
| 200 | \OC::$server->getLogger()->alert('after ISearch ' . time()); |
||
| 201 | |||
| 202 | foreach ($result['users'] as $item) { |
||
| 203 | $items[] = new User($item['value']['shareWith']); |
||
| 204 | } |
||
| 205 | |||
| 206 | foreach ($result['exact']['users'] as $item) { |
||
| 207 | $items[] = new User($item['value']['shareWith']); |
||
| 208 | } |
||
| 209 | |||
| 210 | foreach ($result['groups'] as $item) { |
||
| 211 | $items[] = new Group($item['value']['shareWith']); |
||
| 212 | } |
||
| 213 | |||
| 214 | foreach ($result['exact']['groups'] as $item) { |
||
| 215 | $items[] = new Group($item['value']['shareWith']); |
||
| 216 | } |
||
| 217 | |||
| 218 | $items = array_merge($items, Contact::search($query)); |
||
| 219 | $items = array_merge($items, ContactGroup::search($query)); |
||
| 220 | |||
| 221 | foreach ($result['circles'] as $item) { |
||
| 222 | $items[] = new Circle($item['value']['shareWith']); |
||
| 223 | } |
||
| 224 | |||
| 225 | foreach ($result['exact']['circles'] as $item) { |
||
| 226 | $items[] = new Circle($item['value']['shareWith']); |
||
| 227 | } |
||
| 228 | \OC::$server->getLogger()->alert('complete ' . time()); |
||
| 229 | |||
| 230 | return $items; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return UserGroupClass[] |
||
| 235 | */ |
||
| 236 | public function getMembers() { |
||
| 237 | return []; |
||
| 238 | } |
||
| 239 | |||
| 240 | protected static function getContainer() { |
||
| 241 | $app = \OC::$server->query(Application::class); |
||
| 242 | |||
| 243 | return $app->getContainer(); |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return Circle|Contact|ContactGroup|Email|GenericUser|Group|User |
||
| 248 | */ |
||
| 249 | public static function getUserGroupChild(string $type, string $id, string $displayName = '', string $emailAddress = '') { |
||
| 250 | switch ($type) { |
||
| 251 | case Group::TYPE: |
||
| 252 | return new Group($id); |
||
| 253 | case Circle::TYPE: |
||
| 254 | return new Circle($id); |
||
| 255 | case Contact::TYPE: |
||
| 256 | return new Contact($id); |
||
| 257 | case ContactGroup::TYPE: |
||
| 258 | return new ContactGroup($id); |
||
| 259 | case User::TYPE: |
||
| 260 | return new User($id); |
||
| 261 | case Email::TYPE: |
||
| 262 | return new Email($id); |
||
| 263 | case self::TYPE_PUBLIC: |
||
| 264 | return new GenericUser($id, self::TYPE_PUBLIC); |
||
| 265 | case self::TYPE_EXTERNAL: |
||
| 266 | return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress); |
||
| 267 | default: |
||
| 268 | throw new InvalidShareTypeException('Invalid share type (' . $type . ')'); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | public function jsonSerialize(): array { |
||
| 287 | ]; |
||
| 288 | } |
||
| 289 | } |
||
| 290 |
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