| Conditions | 10 |
| Paths | 112 |
| Total Lines | 75 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 55 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 56 | { |
||
| 57 | $io = new SymfonyStyle(input: $input, output: $output); |
||
| 58 | |||
| 59 | $username = $this->stringOption(input: $input, name: 'username'); |
||
| 60 | $realname = $this->stringOption(input: $input, name: 'realname'); |
||
| 61 | $email = $this->stringOption(input: $input, name: 'email'); |
||
| 62 | $password = $this->stringOption(input: $input, name: 'password'); |
||
| 63 | $admin = $this->boolOption(input: $input, name: 'admin'); |
||
| 64 | $timezone = $this->stringOption(input: $input, name: 'timezone'); |
||
| 65 | $language = $this->stringOption(input: $input, name: 'language'); |
||
| 66 | |||
| 67 | $errors = false; |
||
| 68 | |||
| 69 | if ($username === '') { |
||
| 70 | $io->error(message: 'Missing required option: --username'); |
||
| 71 | $errors = true; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($realname === '') { |
||
| 75 | $io->error(message: 'Missing required option: --realname'); |
||
| 76 | $errors = true; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($email === '') { |
||
| 80 | $io->error(message: 'Missing required option: --email'); |
||
| 81 | $errors = true; |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($timezone === '') { |
||
| 85 | $io->error(message: 'Missing required option: --timezone'); |
||
| 86 | $errors = true; |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($errors) { |
||
| 90 | return Command::INVALID; |
||
| 91 | } |
||
| 92 | |||
| 93 | $user = $this->user_service->findByUserName(user_name: $username); |
||
| 94 | |||
| 95 | if ($user !== null) { |
||
| 96 | $io->error(message: 'A user with the username "' . $username . '" already exists.'); |
||
| 97 | |||
| 98 | return self::FAILURE; |
||
| 99 | } |
||
| 100 | |||
| 101 | $user = $this->user_service->findByEmail(email: $email); |
||
| 102 | |||
| 103 | if ($user !== null) { |
||
| 104 | $io->error(message: 'A user with the email "' . $email . '" already exists'); |
||
| 105 | |||
| 106 | return self::FAILURE; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($password === '') { |
||
| 110 | $password = bin2hex(string: random_bytes(length: 12)); |
||
| 111 | $io->info(message: 'Generated password: ' . $password); |
||
| 112 | } |
||
| 113 | |||
| 114 | $user = $this->user_service->create(user_name: $username, real_name: $realname, email: $email, password: $password); |
||
| 115 | $user->setPreference(setting_name: UserInterface::PREF_TIME_ZONE, setting_value: $timezone); |
||
| 116 | $user->setPreference(setting_name: UserInterface::PREF_LANGUAGE, setting_value: $language); |
||
| 117 | $user->setPreference(setting_name: UserInterface::PREF_IS_ACCOUNT_APPROVED, setting_value: '1'); |
||
| 118 | $user->setPreference(setting_name: UserInterface::PREF_IS_EMAIL_VERIFIED, setting_value: '1'); |
||
| 119 | $user->setPreference(setting_name: UserInterface::PREF_CONTACT_METHOD, setting_value: 'messaging'); |
||
| 120 | $io->success('User ' . $user->id() . ' created.'); |
||
| 121 | |||
| 122 | if ($admin) { |
||
| 123 | $user->setPreference(setting_name: UserInterface::PREF_IS_ADMINISTRATOR, setting_value: '1'); |
||
| 124 | $io->success(message: 'User granted administrator role.'); |
||
| 125 | } |
||
| 126 | |||
| 127 | DB::exec(sql: 'COMMIT'); |
||
| 128 | |||
| 129 | return self::SUCCESS; |
||
| 130 | } |
||
| 132 |
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