Conditions | 16 |
Paths | 8192 |
Total Lines | 77 |
Code Lines | 32 |
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 |
||
66 | public function create(array $options = []): JobInterface |
||
67 | { |
||
68 | $options = $this->optionsResolver->resolve($options); |
||
69 | |||
70 | /** @var JobInterface $job */ |
||
71 | $job = $this->jobFactory->createNew(); |
||
72 | |||
73 | if (isset($options['schedule'])) { |
||
74 | $job->setSchedule($options['schedule']); |
||
75 | } |
||
76 | $job->setCommand($options['command']); |
||
77 | |||
78 | if (isset($options['args'])) { |
||
79 | $job->setArgs($options['args']); |
||
80 | } |
||
81 | if (isset($options['state'])) { |
||
82 | $job->setState($options['state']); |
||
83 | } |
||
84 | if (isset($options['queue'])) { |
||
85 | $job->setQueue($options['queue']); |
||
86 | } |
||
87 | if (isset($options['priority'])) { |
||
88 | $job->setPriority((int) $options['priority']); |
||
89 | } |
||
90 | // if (isset($options['created_at'])) { |
||
91 | // $job->setCreatedAt(new \DateTime($options['created_at'])); |
||
92 | // } |
||
93 | // if (isset($options['started_at'])) { |
||
94 | // $job->setStartedAt(new \DateTime($options['started_at'])); |
||
95 | // } |
||
96 | // if (isset($options['checked_at'])) { |
||
97 | // $job->setCheckedAt(new \DateTime($options['checked_at'])); |
||
98 | // } |
||
99 | // if (isset($options['closed_at'])) { |
||
100 | // $job->setClosedAt(new \DateTime($options['closed_at'])); |
||
101 | // } |
||
102 | if (isset($options['execute_after'])) { |
||
103 | $job->setExecuteAfter(new \DateTime($options['execute_after'])); |
||
104 | } |
||
105 | |||
106 | // /** @var JobInterface $dependencyJob */ |
||
107 | // foreach ($options['dependencies'] as $dependencyJob) { |
||
108 | // $job->addDependency($dependencyJob); |
||
109 | // } |
||
110 | |||
111 | if (isset($options['worker_name'])) { |
||
112 | $job->setWorkerName($options['worker_name']); |
||
113 | } |
||
114 | if (isset($options['output'])) { |
||
115 | $job->setOutput($options['output']); |
||
116 | } |
||
117 | if (isset($options['error_output'])) { |
||
118 | $job->setErrorOutput($options['error_output']); |
||
119 | } |
||
120 | if (isset($options['exit_code'])) { |
||
121 | $job->setExitCode($options['exit_code']); |
||
122 | } |
||
123 | if (isset($options['max_runtime'])) { |
||
124 | $job->setMaxRuntime($options['max_runtime']); |
||
125 | } |
||
126 | if (isset($options['max_retries'])) { |
||
127 | $job->setMaxRetries($options['max_retries']); |
||
128 | } |
||
129 | |||
130 | // if (isset($options['original_job'])) { |
||
131 | // $job->setOriginalJob($options['original_job']); |
||
132 | // } |
||
133 | |||
134 | if (isset($options['retry_jobs']) && is_int($options['retry_jobs'])) { |
||
135 | /** @var JobInterface $retryJob */ |
||
136 | for ($i = 0; $i < $options['retry_jobs']; ++$i) { |
||
137 | $retryJob = $this->jobFactory->createRetryJob($job); |
||
138 | $job->addRetryJob($retryJob); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | return $job; |
||
143 | } |
||
226 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.