| Conditions | 11 |
| Paths | 19 |
| Total Lines | 64 |
| Code Lines | 48 |
| 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 |
||
| 57 | public function actionAdd($args) |
||
| 58 | { |
||
| 59 | $module = $this->getCronModule(); |
||
| 60 | $taskName = $args[1] ?? null; |
||
| 61 | $id = $args[2] ?? null; |
||
| 62 | $schedule = $args[3] ?? null; |
||
| 63 | |||
| 64 | if (!$taskName) { |
||
| 65 | $this->_outWriter->writeError("Cannot add a task without a name"); |
||
| 66 | return true; |
||
| 67 | } |
||
| 68 | if (!$id) { |
||
| 69 | $this->_outWriter->writeError("Cannot add a task without a task id"); |
||
| 70 | return true; |
||
| 71 | } |
||
| 72 | if (!$schedule) { |
||
| 73 | $this->_outWriter->writeError("Cannot add a task without a schedule"); |
||
| 74 | return true; |
||
| 75 | } |
||
| 76 | |||
| 77 | $exists = $module->taskExists($taskName); |
||
| 78 | if ($exists) { |
||
| 79 | $this->_outWriter->writeError("'{$taskName}' already exists in the database"); |
||
| 80 | return true; |
||
| 81 | } |
||
| 82 | $infos = $module->getTaskInfos(); |
||
| 83 | $info = null; |
||
| 84 | foreach ($infos as $i) { |
||
| 85 | if ($i->getName() == $id) { |
||
| 86 | $info = $i; |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | if (!$info) { |
||
| 91 | $this->_outWriter->writeError("Task ID '{$id}' could not be found"); |
||
| 92 | return true; |
||
| 93 | } |
||
| 94 | $s = new TTimeScheduler(); |
||
| 95 | try { |
||
| 96 | $s->setSchedule($schedule); |
||
| 97 | } catch (TInvalidDataValueException $e) { |
||
| 98 | $this->_outWriter->writeError("Schedule '{$schedule}' is not a valid schedule"); |
||
| 99 | return true; |
||
| 100 | } |
||
| 101 | |||
| 102 | $task = $module->instanceTask($info->getTask()); |
||
| 103 | $task->setName($taskName); |
||
| 104 | $task->setSchedule($schedule); |
||
| 105 | for ($i = 4; $i < count($args); $i++) { |
||
| 106 | $parts = explode('=', $args[$i]); |
||
| 107 | $parts[0] = trim($parts[0]); |
||
| 108 | $property = strtolower($parts[0]); |
||
| 109 | if ($task->canSetProperty($property)) { |
||
| 110 | $property = 'set' . $property; |
||
| 111 | $task->$property(trim($parts[1])); |
||
| 112 | } else { |
||
| 113 | $this->_outWriter->writeError("Task Property '{$parts[0]}' is not found"); |
||
| 114 | return true; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | $module->addTask($task); |
||
| 118 | |||
| 119 | $this->_outWriter->writeLine("Task '{$taskName}' was added to the database\n", [TShellWriter::GREEN, TShellWriter::BOLD]); |
||
| 120 | return true; |
||
| 121 | } |
||
| 196 |
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