| Conditions | 9 |
| Paths | 16 |
| Total Lines | 70 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 59 | public function start() |
||
| 60 | { |
||
| 61 | $token = new File(CONFIG . 'updater'); |
||
| 62 | |||
| 63 | if ($token->exists()) { |
||
| 64 | $this->renderFailure(__d('installer', 'update.failure.explanation'), 1529737182); |
||
|
|
|||
| 65 | |||
| 66 | return; |
||
| 67 | } |
||
| 68 | |||
| 69 | $this->set('dbVersion', $this->dbVersion); |
||
| 70 | $this->set('saitoVersion', $this->saitoVersion); |
||
| 71 | |||
| 72 | if (empty($this->dbVersion)) { |
||
| 73 | $msg = __d('installer', 'update.failure.nodbversion'); |
||
| 74 | $this->renderFailure($msg, 1529737397); |
||
| 75 | $this->log($msg, LogLevel::ERROR, ['saito.install']); |
||
| 76 | |||
| 77 | return; |
||
| 78 | } |
||
| 79 | |||
| 80 | if (version_compare($this->dbVersion, '4.10.0', '<')) { |
||
| 81 | $msg = __d('installer', 'update.failure.wrongdbversion', ['v' => $this->dbVersion]); |
||
| 82 | $this->renderFailure($msg, 1529737648); |
||
| 83 | $this->log($msg, LogLevel::ERROR, ['saito.install']); |
||
| 84 | |||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | $startForm = new UpdaterStartForm(); |
||
| 89 | $this->set('startForm', $startForm); |
||
| 90 | |||
| 91 | if (!$this->getRequest()->is('post')) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!$startForm->execute($this->request->getData())) { |
||
| 96 | // don't emit errors in frontend in case form is accidental on live-installation |
||
| 97 | $startForm->setErrors([]); |
||
| 98 | $this->set('startAuthError', true); |
||
| 99 | |||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->logCurrentState('Pre-update state.'); |
||
| 104 | |||
| 105 | $token->write(''); |
||
| 106 | |||
| 107 | try { |
||
| 108 | if ( |
||
| 109 | version_compare($this->dbVersion, '4.10.0', '>=') |
||
| 110 | && version_compare($this->dbVersion, '5.0.0', '<') |
||
| 111 | ) { |
||
| 112 | $this->migrations->markMigrated('20180620081553'); |
||
| 113 | $this->logCurrentState('Marked version 4.10.0 migrated.'); |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->migrations->migrate(); |
||
| 117 | (new DbVersion($this->Settings))->set($this->saitoVersion); |
||
| 118 | $this->logCurrentState('Post upgrade state.'); |
||
| 119 | } catch (\Throwable $e) { |
||
| 120 | $this->logCurrentState('Migration failed: ' . $e->getMessage()); |
||
| 121 | |||
| 122 | return $this->redirect('/'); |
||
| 123 | } |
||
| 124 | |||
| 125 | $token->delete(); |
||
| 126 | $this->viewBuilder()->setTemplate('success'); |
||
| 127 | |||
| 128 | $this->logCurrentState('Update successfull.'); |
||
| 129 | } |
||
| 163 |