| Conditions | 7 |
| Paths | 7 |
| Total Lines | 77 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| 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 |
||
| 116 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 117 | { |
||
| 118 | $project_key = $this->io->getArgument('project_key'); |
||
| 119 | |||
| 120 | if ( !in_array($project_key, $this->getProjectKeys()) ) { |
||
| 121 | throw new CommandException('The project with "' . $project_key . '" key does\'t exist.'); |
||
| 122 | } |
||
| 123 | |||
| 124 | $link_name = $this->io->getOption('link-name'); |
||
| 125 | |||
| 126 | if ( !in_array($link_name, $this->getLinkNames()) ) { |
||
| 127 | throw new CommandException('The "' . $link_name . '" link name doesn\'t exist.'); |
||
| 128 | } |
||
| 129 | |||
| 130 | $issue_key = $this->io->getArgument('issue_key'); |
||
| 131 | $issues = $this->issueCloner->getIssues( |
||
| 132 | 'key = ' . $issue_key, |
||
| 133 | $link_name, |
||
| 134 | ChangeLogIssueCloner::LINK_DIRECTION_OUTWARD |
||
| 135 | ); |
||
| 136 | $issue_count = count($issues); |
||
| 137 | |||
| 138 | if ( $issue_count !== 1 ) { |
||
| 139 | throw new CommandException('The "' . $issue_key . '" not found.'); |
||
| 140 | } |
||
| 141 | |||
| 142 | /** @var Issue[] $issue_pair */ |
||
| 143 | $issue_pair = reset($issues); |
||
| 144 | $issue = $issue_pair[0]; |
||
| 145 | $linked_issue = $issue_pair[1]; |
||
| 146 | |||
| 147 | $issue_project = $issue->get('project'); |
||
| 148 | |||
| 149 | if ( $issue_project['key'] === $project_key ) { |
||
| 150 | throw new CommandException('Creating of linked issue in same project is not supported.'); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ( is_object($linked_issue) ) { |
||
| 154 | $this->io->writeln(sprintf( |
||
| 155 | 'The "<info>%s</info>" issue already has "<info>%s</info>" link to "<info>%s</info>" issue.', |
||
| 156 | $issue->getKey(), |
||
| 157 | $link_name, |
||
| 158 | $linked_issue->getKey() |
||
| 159 | )); |
||
| 160 | |||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | $components = array(); |
||
| 165 | $project_components = $this->getProjectComponents($project_key); |
||
| 166 | |||
| 167 | if ( $project_components ) { |
||
|
1 ignored issue
–
show
|
|||
| 168 | $component_name = $this->io->choose( |
||
| 169 | 'Select linked issue component:', |
||
| 170 | $project_components, |
||
| 171 | '', |
||
| 172 | 'The component isn\'t valid' |
||
| 173 | ); |
||
| 174 | |||
| 175 | $components[] = array_search($component_name, $project_components); |
||
| 176 | } |
||
| 177 | |||
| 178 | $linked_issue_key = $this->issueCloner->createLinkedIssue( |
||
| 179 | $issue, |
||
| 180 | $project_key, |
||
| 181 | $link_name, |
||
| 182 | ChangeLogIssueCloner::LINK_DIRECTION_OUTWARD, |
||
| 183 | $components |
||
| 184 | ); |
||
| 185 | |||
| 186 | $this->io->writeln(sprintf( |
||
| 187 | 'The "<info>%s</info>" issue now has "<info>%s</info>" link to "<info>%s</info>" issue.', |
||
| 188 | $issue->getKey(), |
||
| 189 | $link_name, |
||
| 190 | $linked_issue_key |
||
| 191 | )); |
||
| 192 | } |
||
| 193 | |||
| 214 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.