| Conditions | 11 |
| Paths | 20 |
| Total Lines | 40 |
| Code Lines | 30 |
| 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 declare(strict_types=1); |
||
| 71 | public function rename(int $ticketid, int $responseid = 0): bool |
||
| 72 | { |
||
| 73 | $helper = Helper::getInstance(); |
||
| 74 | $ticketid = $ticketid; |
||
| 75 | $responseid = $responseid; |
||
| 76 | $old_ticketid = $this->getVar('ticketid'); |
||
| 77 | $old_responseid = $this->getVar('responseid'); |
||
| 78 | |||
| 79 | $filename = $this->getVar('filename'); |
||
| 80 | $newFilename = ''; |
||
| 81 | if ((0 != $old_responseid) && (0 != $responseid)) { // Was a response and is going to be a response |
||
| 82 | $newFilename = \str_replace('_' . $old_responseid . '_', '_' . $responseid . '_', $filename); |
||
| 83 | $newFilename = \str_replace($old_ticketid . '_', $ticketid . '_', $newFilename); |
||
| 84 | } elseif ((0 != $old_responseid) && (0 == $responseid)) { // Was a response and is part of the ticket now |
||
| 85 | $newFilename = \str_replace('_' . $old_responseid . '_', '_', $filename); |
||
| 86 | $newFilename = \str_replace($old_ticketid . '_', $ticketid . '_', $newFilename); |
||
| 87 | } elseif ((0 == $old_responseid) && (0 != $responseid)) { // Was part of the ticket, now going to a response |
||
| 88 | $newFilename = \str_replace($old_ticketid . '_', $ticketid . '_' . $responseid . '_', $filename); |
||
| 89 | } elseif ((0 == $old_responseid) |
||
| 90 | && (0 == $responseid)) { // Was part of the ticket, and is part of the ticket now |
||
| 91 | $newFilename = \str_replace($old_ticketid . '_', $ticketid . '_', $filename); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** @var \XoopsModules\Xhelp\FileHandler $fileHandler */ |
||
| 95 | $fileHandler = $helper->getHandler('File'); |
||
| 96 | $this->setVar('filename', $newFilename); |
||
| 97 | $this->setVar('ticketid', $ticketid); |
||
| 98 | $this->setVar('responseid', $responseid); |
||
| 99 | if ($fileHandler->insert($this, true)) { |
||
| 100 | $success = true; |
||
| 101 | } else { |
||
| 102 | $success = false; |
||
| 103 | } |
||
| 104 | |||
| 105 | $ret = false; |
||
| 106 | if ($success) { |
||
| 107 | $ret = $this->renameAtFS($filename, $newFilename); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $ret; |
||
| 111 | } |
||
| 125 |