Conditions | 8 |
Paths | 26 |
Total Lines | 59 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
33 | public function __construct($identifier, $script, $schedule, $log = null) |
||
34 | { |
||
35 | /* Make sure the scheduled script file exists... */ |
||
36 | if (file_exists($script)) { |
||
37 | /* try to make the identifier truly unique to this instance */ |
||
38 | $_identifier = $identifier . '.' . md5($identifier . __FILE__ . __CLASS__); |
||
39 | |||
40 | /* ensure that we're working with a valid Cron job */ |
||
41 | $newJob = null; |
||
42 | if (is_string($schedule)) { |
||
43 | $newJob = \TiBeN\CrontabManager\CrontabJob::createFromCrontabLine($schedule . " php $script"); |
||
44 | } elseif ($schedule instanceof \TiBeN\CrontabManager\CrontabJob) { |
||
45 | $newJob = $schedule; |
||
46 | } else { |
||
47 | throw new AutoCrontabJobException( |
||
48 | 'Expected a string or TiBeN\CrontabManager\CrontabJob, received ' . print_r($schedule, true), |
||
49 | AutoCrontabJobException::CONSTRUCTOR_ERROR |
||
50 | ); |
||
51 | } |
||
52 | $newJob->comments = implode(' ', [ |
||
53 | $newJob->comments, |
||
54 | "Created by $script:" . get_class($this) . ' ' . date('Y-m-d h:ia') . " (Job ID $_identifier)" |
||
55 | ]); |
||
56 | |||
57 | |||
58 | /* update cron if this job already exists */ |
||
59 | $this->cron = new \TiBeN\CrontabManager\CrontabRepository(new \TiBeN\CrontabManager\CrontabAdapter()); |
||
60 | $jobs = $this->cron->getJobs(); |
||
61 | $jobExists = false; |
||
62 | // TODO Rewrite whenever this is fixed: https://github.com/TiBeN/CrontabManager/issues/3 |
||
63 | foreach ($jobs as $job) { |
||
64 | if (preg_match("/$_identifier/", $job->formatCrontabLine())) { |
||
65 | $jobExists = true; |
||
66 | $job->minutes = $newJob->minutes; |
||
67 | $job->hours = $newJob->hours; |
||
68 | $job->dayOfMonth = $newJob->dayOfMonth; |
||
69 | $job->months = $newJob->months; |
||
70 | $job->dayOfWeek = $newJob->dayOfWeek; |
||
71 | break; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /* ... or add this as a new job if it doesn't exist */ |
||
76 | if (!$jobExists) { |
||
77 | $this->cron->addJob($newJob); |
||
78 | } |
||
79 | |||
80 | /* set up log file */ |
||
81 | if (empty($log)) { |
||
82 | $log = dirname($script) . '/' . basename($script, '.php') . '.log'; |
||
83 | } |
||
84 | $this->log = \Log::singleton('file', $log); |
||
85 | |||
86 | /* update cron to enable scheduled jobs */ |
||
87 | $this->cron->persist(); |
||
88 | } else { |
||
89 | throw new AutoCrontabJobException( |
||
90 | "PHP script '$script' does not exist", |
||
91 | AutoCrontabJobException::CONSTRUCTOR_ERROR |
||
92 | ); |
||
105 |
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