| Conditions | 13 |
| Paths | 384 |
| Total Lines | 77 |
| Code Lines | 58 |
| 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 |
||
| 22 | public function getDeploymentData(DNDeployment $deployment) { |
||
| 23 | if (empty(self::$_cache_current_build[$deployment->EnvironmentID])) { |
||
| 24 | self::$_cache_current_build[$deployment->EnvironmentID] = $deployment->Environment()->CurrentBuild(); |
||
| 25 | } |
||
| 26 | |||
| 27 | $environment = $deployment->Environment(); |
||
| 28 | $project = $environment->Project(); |
||
| 29 | |||
| 30 | $deployer = $deployment->Deployer(); |
||
| 31 | $deployerData = null; |
||
| 32 | if ($deployer && $deployer->exists()) { |
||
| 33 | $deployerData = $this->getStackMemberData($project, $deployer); |
||
| 34 | } |
||
| 35 | $approver = $deployment->Approver(); |
||
| 36 | $approverData = null; |
||
| 37 | if ($approver && $approver->exists()) { |
||
| 38 | $approverData = $this->getStackMemberData($project, $approver); |
||
| 39 | } |
||
| 40 | |||
| 41 | // failover for older deployments |
||
| 42 | $started = $deployment->Created; |
||
| 43 | $startedNice = $deployment->obj('Created')->Nice(); |
||
| 44 | if($deployment->DeployStarted) { |
||
| 45 | $started = $deployment->DeployStarted; |
||
| 46 | $startedNice = $deployment->obj('DeployStarted')->Nice(); |
||
| 47 | } |
||
| 48 | |||
| 49 | $isCurrentBuild = self::$_cache_current_build[$deployment->EnvironmentID] |
||
| 50 | ? ($deployment->ID === self::$_cache_current_build[$deployment->EnvironmentID]->ID) |
||
| 51 | : false; |
||
| 52 | |||
| 53 | $supportedOptions = $deployment->Environment()->Backend()->getDeployOptions($deployment->Environment()); |
||
| 54 | $setOptions = $deployment->getDeploymentStrategy() ? $deployment->getDeploymentStrategy()->getOptions() : []; |
||
| 55 | $options = []; |
||
| 56 | |||
| 57 | foreach ($supportedOptions as $option) { |
||
| 58 | if (isset($setOptions[$option->getName()]) && $setOptions[$option->getName()] === 'true') { |
||
| 59 | $options[$option->getName()] = 'true'; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | $tags = []; |
||
| 64 | try { |
||
| 65 | $tags = $deployment->getTags()->toArray(); |
||
| 66 | } catch (\Exception $e) { |
||
| 67 | // gitonomy exception |
||
| 68 | } |
||
| 69 | |||
| 70 | return [ |
||
| 71 | 'id' => $deployment->ID, |
||
| 72 | 'date_created' => $deployment->Created, |
||
| 73 | 'date_created_nice' => $deployment->obj('Created')->Nice(), |
||
| 74 | 'date_started' => $started, |
||
| 75 | 'date_started_nice' => $startedNice, |
||
| 76 | 'date_requested' => $deployment->DeployRequested, |
||
| 77 | 'date_requested_nice' => $deployment->obj('DeployRequested')->Nice(), |
||
| 78 | 'date_updated' => $deployment->LastEdited, |
||
| 79 | 'date_updated_nice' => $deployment->obj('LastEdited')->Nice(), |
||
| 80 | 'title' => $deployment->Title, |
||
| 81 | 'summary' => $deployment->Summary, |
||
| 82 | 'branch' => $deployment->Branch, |
||
| 83 | 'tags' => $tags, |
||
| 84 | 'changes' => $deployment->getDeploymentStrategy()->getChanges(), |
||
| 85 | 'deployment_type' => $deployment->getDeploymentStrategy()->getActionCode(), |
||
| 86 | 'deployment_estimate' => $deployment->getDeploymentStrategy()->getEstimatedTime(), |
||
| 87 | 'sha' => $deployment->SHA, |
||
| 88 | 'short_sha' => substr($deployment->SHA, 0, 7), |
||
| 89 | 'ref_type' => $deployment->RefType, |
||
| 90 | 'options' => $options, |
||
| 91 | 'commit_message' => $deployment->getCommitMessage(), |
||
| 92 | 'commit_url' => $deployment->getCommitURL(), |
||
| 93 | 'deployer' => $deployerData, |
||
| 94 | 'approver' => $approverData, |
||
| 95 | 'state' => $deployment->State, |
||
| 96 | 'is_current_build' => $isCurrentBuild |
||
| 97 | ]; |
||
| 98 | } |
||
| 99 | |||
| 131 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.