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