| Conditions | 16 |
| Paths | 15 |
| Total Lines | 115 |
| Code Lines | 67 |
| 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 |
||
| 44 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 45 | { |
||
| 46 | $quiet = (bool) $input->getOption(name: 'quiet'); |
||
| 47 | $list = (bool) $input->getOption(name: 'list'); |
||
| 48 | $delete = (bool) $input->getOption(name: 'delete'); |
||
| 49 | |||
| 50 | /** @var string|null $setting_name */ |
||
| 51 | $setting_name = $input->getArgument(name: 'setting-name'); |
||
| 52 | |||
| 53 | /** @var string|null $setting_value */ |
||
| 54 | $setting_value = $input->getArgument(name: 'setting-value'); |
||
| 55 | |||
| 56 | $io = new SymfonyStyle(input: $input, output: $output); |
||
| 57 | |||
| 58 | if ($list) { |
||
| 59 | if ($delete) { |
||
| 60 | $io->error(message: 'Cannot specify --list and --delete together.'); |
||
| 61 | |||
| 62 | return Command::FAILURE; |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($setting_value !== null) { |
||
| 66 | $io->error(message: 'Cannot specify --list and a new value together.'); |
||
| 67 | |||
| 68 | return Command::FAILURE; |
||
| 69 | } |
||
| 70 | |||
| 71 | $table = new Table(output: $output); |
||
| 72 | $table->setHeaders(headers: ['Setting name', 'Setting value']); |
||
| 73 | |||
| 74 | /** @var array<object{setting_name:string,setting_value:string}> $settings */ |
||
| 75 | $settings = DB::table(table: 'site_setting') |
||
| 76 | ->orderBy(column: 'setting_name') |
||
| 77 | ->select(columns: ['setting_name', 'setting_value']) |
||
| 78 | ->get() |
||
| 79 | ->all(); |
||
| 80 | |||
| 81 | foreach ($settings as $setting) { |
||
| 82 | if ($setting_name === null || str_contains(haystack: $setting->setting_name, needle: $setting_name)) { |
||
| 83 | $table->addRow(row: [$setting->setting_name, $setting->setting_value]); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $table->render(); |
||
| 88 | |||
| 89 | return Command::SUCCESS; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** @var string|null $old_setting_value */ |
||
| 93 | $old_setting_value = DB::table('site_setting') |
||
| 94 | ->where(column: 'setting_name', operator: '=', value: $setting_name) |
||
| 95 | ->value(column: 'setting_value'); |
||
| 96 | |||
| 97 | if ($delete) { |
||
| 98 | if ($setting_value !== null) { |
||
| 99 | $io->error(message: 'Cannot specify --delete and a new value together.'); |
||
| 100 | |||
| 101 | return Command::FAILURE; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($old_setting_value === null) { |
||
| 105 | $io->warning(message: 'Site setting ‘' . $setting_name . '’ not found. Nothing to delete.'); |
||
| 106 | } else { |
||
| 107 | DB::table('site_setting') |
||
| 108 | ->where('setting_name', '=', $setting_name) |
||
| 109 | ->delete(); |
||
| 110 | |||
| 111 | $io->success(message: 'Site setting ‘' . $setting_name . '’ deleted. Previous value was ‘' . $old_setting_value . '’.'); |
||
| 112 | } |
||
| 113 | |||
| 114 | return Command::SUCCESS; |
||
| 115 | } |
||
| 116 | |||
| 117 | |||
| 118 | if ($setting_name === null) { |
||
| 119 | $io->error(message: 'A setting name is required, unless the --list option is used.'); |
||
| 120 | |||
| 121 | return Command::FAILURE; |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($setting_value === null) { |
||
| 125 | if ($old_setting_value === null) { |
||
| 126 | $io->info(message: 'Site setting ‘' . $setting_name . '’ is not currently set.'); |
||
| 127 | } elseif ($quiet) { |
||
| 128 | $verbosity = $io->getVerbosity(); |
||
| 129 | $io->setVerbosity(level: OutputInterface::VERBOSITY_NORMAL); |
||
| 130 | $io->writeln(messages: $old_setting_value); |
||
| 131 | $io->setVerbosity(level: $verbosity); |
||
| 132 | } else { |
||
| 133 | $io->info(message: 'Site setting ‘' . $setting_name . '’ is currently set to ‘' . $old_setting_value . '’.'); |
||
| 134 | } |
||
| 135 | |||
| 136 | return Command::SUCCESS; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($old_setting_value === $setting_value) { |
||
| 140 | $io->warning(message: 'Site setting ' . $setting_name . ' is already set to ' . $setting_value); |
||
| 141 | |||
| 142 | return Command::SUCCESS; |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($old_setting_value === null) { |
||
| 146 | DB::table('site_setting') |
||
| 147 | ->insert(['setting_name' => $setting_name, 'setting_value' => $setting_value]); |
||
| 148 | |||
| 149 | $io->success(message: 'Site setting ‘' . $setting_name . '’ was created as ‘' . $setting_value . '’.'); |
||
| 150 | } else { |
||
| 151 | DB::table('site_setting') |
||
| 152 | ->where(column: 'setting_name', operator: '=', value: $setting_name) |
||
| 153 | ->update(values: ['setting_value' => $setting_value]); |
||
| 154 | |||
| 155 | $io->success(message: 'Site setting ‘' . $setting_name . '’ was changed from ‘' . $old_setting_value . '’ to ‘' . $setting_value . '’.'); |
||
| 156 | } |
||
| 157 | |||
| 158 | return Command::SUCCESS; |
||
| 159 | } |
||
| 161 |
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