| Conditions | 13 |
| Paths | 1024 |
| Total Lines | 89 |
| Code Lines | 69 |
| 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 |
||
| 28 | public function getDeploymentData(\DNDeployment $deployment) { |
||
| 29 | if (empty(self::$_cache_current_build[$deployment->EnvironmentID])) { |
||
| 30 | self::$_cache_current_build[$deployment->EnvironmentID] = $deployment->Environment()->CurrentBuild(); |
||
| 31 | } |
||
| 32 | |||
| 33 | $environment = $deployment->Environment(); |
||
| 34 | $project = $environment->Project(); |
||
| 35 | |||
| 36 | $deployerData = $this->getStackMemberData($project, $deployment->DeployerID); |
||
| 37 | $approverData = $this->getStackMemberData($project, $deployment->ApproverID); |
||
| 38 | |||
| 39 | $started = null; |
||
| 40 | $startedNice = null; |
||
| 41 | $startedAgo = null; |
||
| 42 | // we check first, before we do a expensive ->Nice() and ->Ago() |
||
| 43 | if(!$deployment->DeployStarted) { |
||
| 44 | $started = $deployment->Created; |
||
| 45 | $startedNice = $deployment->obj('Created')->Nice(); |
||
| 46 | $startedAgo = $deployment->obj('Created')->Ago(); |
||
| 47 | } else { |
||
| 48 | $started = $deployment->DeployStarted; |
||
| 49 | $startedNice = $deployment->obj('DeployStarted')->Nice(); |
||
| 50 | $startedAgo = $deployment->obj('DeployStarted')->Ago(); |
||
| 51 | } |
||
| 52 | |||
| 53 | $isCurrentBuild = self::$_cache_current_build[$deployment->EnvironmentID] |
||
| 54 | ? ($deployment->ID === self::$_cache_current_build[$deployment->EnvironmentID]->ID) |
||
| 55 | : false; |
||
| 56 | |||
| 57 | $supportedOptions = $environment->getSupportedOptions(); |
||
| 58 | $setOptions = $deployment->getDeploymentStrategy() ? $deployment->getDeploymentStrategy()->getOptions() : []; |
||
| 59 | $options = []; |
||
| 60 | |||
| 61 | foreach ($supportedOptions as $option) { |
||
| 62 | if (!isset($setOptions[$option->getName()])) { |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | if ($setOptions[$option->getName()] === 'true' || $setOptions[$option->getName()] === true) { |
||
| 66 | $options[$option->getName()] = true; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $tags = []; |
||
| 71 | try { |
||
| 72 | $tags = $deployment->getTags()->toArray(); |
||
| 73 | } catch (\Exception $e) { |
||
| 74 | // gitonomy exception |
||
| 75 | } |
||
| 76 | |||
| 77 | $type = 'full'; |
||
| 78 | if ($deployment->getDeploymentStrategy()->getActionCode() === 'fast') { |
||
| 79 | $type = 'code-only'; |
||
| 80 | } |
||
| 81 | |||
| 82 | return [ |
||
| 83 | 'id' => $deployment->ID, |
||
| 84 | 'date_created' => $deployment->Created, |
||
| 85 | 'date_created_nice' => $deployment->obj('Created')->Nice(), |
||
| 86 | 'date_created_ago' => $deployment->obj('Created')->Ago(), |
||
| 87 | 'date_started' => $started, |
||
| 88 | 'date_started_nice' => $startedNice, |
||
| 89 | 'date_started_ago' => $startedAgo, |
||
| 90 | 'date_requested' => $deployment->DeployRequested, |
||
| 91 | 'date_requested_nice' => $deployment->obj('DeployRequested')->Nice(), |
||
| 92 | 'date_requested_ago' => $deployment->obj('DeployRequested')->Ago(), |
||
| 93 | 'date_updated' => $deployment->LastEdited, |
||
| 94 | 'date_updated_nice' => $deployment->obj('LastEdited')->Nice(), |
||
| 95 | 'date_updated_ago' => $deployment->obj('LastEdited')->Ago(), |
||
| 96 | 'title' => $deployment->Title, |
||
| 97 | 'summary' => $deployment->Summary, |
||
| 98 | 'branch' => $deployment->Branch, |
||
| 99 | 'rejected_reason' => $deployment->RejectedReason ?: '', |
||
| 100 | 'tags' => $tags, |
||
| 101 | 'changes' => $deployment->getDeploymentStrategy()->getChanges(), |
||
| 102 | 'deployment_type' => $type, |
||
| 103 | 'deployment_estimate' => $deployment->getDeploymentStrategy()->getEstimatedTime(), |
||
| 104 | 'sha' => $deployment->SHA, |
||
| 105 | 'short_sha' => substr($deployment->SHA, 0, 7), |
||
| 106 | 'ref_type' => $deployment->RefType, |
||
| 107 | 'options' => $options, |
||
| 108 | 'commit_message' => $deployment->getCommitMessage(), |
||
| 109 | 'commit_url' => $deployment->getCommitURL(), |
||
| 110 | 'deployer' => $deployerData, |
||
| 111 | 'approver_id' => $deployment->ApproverID ?: '', |
||
| 112 | 'approver' => $approverData, |
||
| 113 | 'state' => $deployment->State, |
||
| 114 | 'is_current_build' => $isCurrentBuild |
||
| 115 | ]; |
||
| 116 | } |
||
| 117 | |||
| 165 |
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.