| Total Complexity | 42 |
| Total Lines | 261 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like User 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 User, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | final class User implements ModuleConfigurationInterface |
||
| 31 | { |
||
| 32 | public function addConfig(NodeBuilder $nodeBuilder): void |
||
| 74 | } |
||
| 75 | |||
| 76 | public function handleDefaultParameters(ContainerBuilder $container): void |
||
| 92 | } |
||
| 93 | |||
| 94 | public function handleConfiguration(array $config, ContainerBuilder $container): void |
||
| 95 | { |
||
| 96 | if (!isset($config['user']) || !isset($config['user']['enabled']) || false == $config['user']['enabled']) { |
||
| 97 | return; |
||
| 98 | } |
||
| 99 | $container->setParameter('parthenon_user_enabled', true); |
||
| 100 | |||
| 101 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config')); |
||
| 102 | $bundles = $container->getParameter('kernel.bundles'); |
||
| 103 | |||
| 104 | $this->configureMongoDb($bundles, $loader); |
||
| 105 | $this->configureDoctrine($bundles, $loader); |
||
| 106 | |||
| 107 | $loader->load('services/user.xml'); |
||
| 108 | |||
| 109 | $this->configureAutotagging($container); |
||
| 110 | $config = $this->configureUserClass($config, $container); |
||
| 111 | $config = $this->configureSignupSuccessRoute($config, $container); |
||
| 112 | $config = $this->configureLoginRoute($config, $container); |
||
| 113 | $config = $this->configureUserInvitesEnabled($config, $container); |
||
| 114 | $config = $this->configureTeamsInviteEnabled($config, $container); |
||
| 115 | $config = $this->configureGdprFormatterType($config, $container); |
||
| 116 | $config = $this->configureRoles($config, $container); |
||
| 117 | $config = $this->configureSelfSignup($config, $container); |
||
| 118 | $config = $this->configureEmailConfirmation($config, $container); |
||
| 119 | $config = $this->configureSignedInAfterSignup($config, $container); |
||
| 120 | $config = $this->configureFirewall($config, $container); |
||
| 121 | |||
| 122 | $this->configureTeams($config, $container); |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @throws NonExistentClass |
||
| 127 | * @throws ParameterNotSetException |
||
| 128 | */ |
||
| 129 | private function configureTeams(array $config, ContainerBuilder $container): void |
||
| 130 | { |
||
| 131 | if (isset($config['user']['teams_enabled']) && $config['user']['teams_enabled']) { |
||
| 132 | $container->setParameter('parthenon_user_teams_enabled_flag', true); |
||
| 133 | $container->setParameter('parthenon_user_teams_enabled', $config['user']['teams_enabled']); |
||
| 134 | if (!isset($config['user']['team_class']) || empty($config['user']['team_class'])) { |
||
| 135 | throw new ParameterNotSetException('When the user module is enabled and teams are enabled the team_class must be defined'); |
||
| 136 | } |
||
| 137 | |||
| 138 | if (!class_exists($config['user']['team_class'])) { |
||
| 139 | throw new NonExistentClass(sprintf("The class '%s' does not exist.", $config['user']['team_class'])); |
||
| 140 | } |
||
| 141 | |||
| 142 | $teamDdfinition = $container->getDefinition(TeamInterface::class); |
||
| 143 | $teamDdfinition->setClass($config['user']['team_class']); |
||
| 144 | $container->setDefinition(TeamInterface::class, $teamDdfinition); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | private function configureGdprFormatterType(array $config, ContainerBuilder $container): array |
||
| 149 | { |
||
| 150 | if (isset($config['user']['gdpr']['export']['formatter_type']) && !empty($config['user']['gdpr']['export']['formatter_type'])) { |
||
| 151 | $container->setParameter('parthenon_user_gdpr_formatter_type', $config['user']['gdpr']['export']['formatter_type']); |
||
| 152 | } |
||
| 153 | |||
| 154 | return $config; |
||
| 155 | } |
||
| 156 | |||
| 157 | private function configureTeamsInviteEnabled(array $config, ContainerBuilder $container): array |
||
| 158 | { |
||
| 159 | if (isset($config['user']['teams_invites_enabled'])) { |
||
| 160 | $container->setParameter('parthenon_user_teams_invites_enabled', $config['user']['teams_invites_enabled']); |
||
| 161 | } |
||
| 162 | |||
| 163 | return $config; |
||
| 164 | } |
||
| 165 | |||
| 166 | private function configureUserInvitesEnabled(array $config, ContainerBuilder $container): array |
||
| 167 | { |
||
| 168 | if (isset($config['user']['user_invites_enabled'])) { |
||
| 169 | $container->setParameter('parthenon_user_users_invites_enabled', $config['user']['user_invites_enabled']); |
||
| 170 | } |
||
| 171 | |||
| 172 | return $config; |
||
| 173 | } |
||
| 174 | |||
| 175 | private function configureRoles(array $config, ContainerBuilder $containerBuilder): array |
||
| 176 | { |
||
| 177 | if (!isset($config['user']['roles'])) { |
||
| 178 | return $config; |
||
| 179 | } |
||
| 180 | |||
| 181 | $containerBuilder->setParameter('parthenon_user_roles_default_role', $config['user']['roles']['default_role'] ?? 'ROLE_USER'); |
||
| 182 | $containerBuilder->setParameter('parthenon_user_roles_user_assignable_roles', $config['user']['roles']['user_assignable'] ?? []); |
||
| 183 | $containerBuilder->setParameter('parthenon_user_roles_athena_assignable_roles', $config['user']['roles']['athena_assignable'] ?? []); |
||
| 184 | |||
| 185 | return $config; |
||
| 186 | } |
||
| 187 | |||
| 188 | private function configureLoginRoute(array $config, ContainerBuilder $container): array |
||
| 189 | { |
||
| 190 | if (isset($config['user']['login_route'])) { |
||
| 191 | $container->setParameter('parthenon_user_login_route', $config['user']['login_route']); |
||
| 192 | } |
||
| 193 | |||
| 194 | return $config; |
||
| 195 | } |
||
| 196 | |||
| 197 | private function configureSignupSuccessRoute(array $config, ContainerBuilder $container): array |
||
| 198 | { |
||
| 199 | if (isset($config['user']['signup_success_route'])) { |
||
| 200 | $container->setParameter('parthenon_user_signup_success_route', $config['user']['signup_success_route']); |
||
| 201 | } |
||
| 202 | |||
| 203 | return $config; |
||
| 204 | } |
||
| 205 | |||
| 206 | private function configureEmailConfirmation(array $config, ContainerBuilder $container): array |
||
| 207 | { |
||
| 208 | if (isset($config['user']['email_confirmation'])) { |
||
| 209 | $container->setParameter('parthenon_user_email_confirmation', $config['user']['email_confirmation']); |
||
| 210 | } |
||
| 211 | |||
| 212 | return $config; |
||
| 213 | } |
||
| 214 | |||
| 215 | private function configureFirewall(array $config, ContainerBuilder $container): array |
||
| 216 | { |
||
| 217 | if (isset($config['user']['firewall_name'])) { |
||
| 218 | $container->setParameter('parthenon_user_firewall_name', $config['user']['firewall_name']); |
||
| 219 | } |
||
| 220 | |||
| 221 | return $config; |
||
| 222 | } |
||
| 223 | |||
| 224 | private function configureSignedInAfterSignup(array $config, ContainerBuilder $container): array |
||
| 225 | { |
||
| 226 | if (isset($config['user']['signed_in_after_signup'])) { |
||
| 227 | $container->setParameter('parthenon_user_signed_in_after_signup', $config['user']['signed_in_after_signup']); |
||
| 228 | } |
||
| 229 | |||
| 230 | return $config; |
||
| 231 | } |
||
| 232 | |||
| 233 | private function configureSelfSignup(array $config, ContainerBuilder $container): array |
||
| 234 | { |
||
| 235 | if (isset($config['user']['self_signup_enabled'])) { |
||
| 236 | $container->setParameter('parthenon_user_self_signup_enabled', $config['user']['self_signup_enabled']); |
||
| 237 | } |
||
| 238 | |||
| 239 | return $config; |
||
| 240 | } |
||
| 241 | |||
| 242 | private function configureAutotagging(ContainerBuilder $container): void |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @throws \Exception |
||
| 252 | */ |
||
| 253 | private function configureDoctrine(float|array|bool|int|string|null $bundles, XmlFileLoader $loader): string|int|bool|array|float|null |
||
| 254 | { |
||
| 255 | if (isset($bundles['DoctrineBundle'])) { |
||
| 256 | $loader->load('services/orm/user.xml'); |
||
| 257 | } |
||
| 258 | |||
| 259 | return $bundles; |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @throws \Exception |
||
| 264 | */ |
||
| 265 | private function configureMongoDb(float|int|bool|array|string|null $bundles, XmlFileLoader $loader): void |
||
| 269 | } |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @throws NonExistentClass |
||
| 274 | * @throws ParameterNotSetException |
||
| 275 | */ |
||
| 276 | private function configureUserClass(array $config, ContainerBuilder $container): array |
||
| 277 | { |
||
| 291 | } |
||
| 292 | } |
||
| 293 |