Conditions | 12 |
Paths | 130 |
Total Lines | 54 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
42 | public function perform() { |
||
43 | set_time_limit(0); |
||
44 | |||
45 | if(!empty($this->args['logfile'])) { |
||
46 | $this->log = new DeploynautLogFile($this->args['logfile']); |
||
47 | } |
||
48 | |||
49 | $this->project = DNProject::get()->byId($this->args['projectID']); |
||
50 | if(!($this->project && $this->project->exists())) { |
||
51 | throw new RuntimeException(sprintf('Project ID %s not found', $this->args['projectID'])); |
||
52 | } |
||
53 | |||
54 | $this->user = DNData::inst()->getGitUser() ?: null; |
||
55 | |||
56 | // Disallow concurrent git fetches on the same project. |
||
57 | // Only consider fetches started in the last 30 minutes (older jobs probably got stuck) |
||
58 | try { |
||
59 | if(!empty($this->args['fetchID'])) { |
||
60 | $runningFetches = DNGitFetch::get() |
||
61 | ->filter(array( |
||
62 | 'ProjectID' => $this->project->ID, |
||
63 | 'Status' => array('Queued', 'Started'), |
||
64 | 'Created:GreaterThan' => strtotime('-30 minutes') |
||
65 | )) |
||
66 | ->exclude('ID', $this->args['fetchID']); |
||
67 | |||
68 | if($runningFetches->count()) { |
||
69 | $runningFetch = $runningFetches->first(); |
||
70 | $message = sprintf( |
||
71 | 'Another fetch is in progress (started at %s by %s)', |
||
72 | $runningFetch->dbObject('Created')->Nice(), |
||
73 | $runningFetch->Deployer()->Title |
||
74 | ); |
||
75 | if($this->log) { |
||
76 | $this->log->write($message); |
||
77 | } |
||
78 | throw new RuntimeException($message); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // Decide whether we need to just update what we already have |
||
83 | // or initiate a clone if no local repo exists. |
||
84 | if($this->project->repoExists() && empty($this->args['forceClone'])) { |
||
|
|||
85 | $this->fetchRepo(); |
||
86 | } else { |
||
87 | $this->cloneRepo(); |
||
88 | } |
||
89 | } catch(Exception $e) { |
||
90 | if($this->log) { |
||
91 | $this->log->write($e->getMessage()); |
||
92 | } |
||
93 | throw $e; |
||
94 | } |
||
95 | } |
||
96 | |||
160 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.