Code cleanup for all controllers.

This commit is contained in:
James Cole
2015-01-17 08:57:55 +01:00
parent d9c2df5b0d
commit fa7a59572a
14 changed files with 99 additions and 652 deletions

View File

@@ -1,7 +1,6 @@
<?php
/**
* @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
*
* Class ProfileController
*/
@@ -39,19 +38,9 @@ class ProfileController extends BaseController
return View::make('profile.change-password');
}
if (strlen(Input::get('new1')) == 0 || strlen(Input::get('new2')) == 0) {
Session::flash('error', 'Do fill in a password!');
return View::make('profile.change-password');
}
if (Input::get('new1') == Input::get('old')) {
Session::flash('error', 'The idea is to change your password.');
return View::make('profile.change-password');
}
if (Input::get('new1') !== Input::get('new2')) {
Session::flash('error', 'New passwords do not match!');
$result = $this->_validatePassword(Input::get('old'), Input::get('new1'), Input::get('new2'));
if (!($result === true)) {
Session::flash('error', $result);
return View::make('profile.change-password');
}
@@ -66,4 +55,29 @@ class ProfileController extends BaseController
return Redirect::route('profile');
}
/**
* @param string $old
* @param string $new1
* @param string $new2
*
* @return string|bool
*/
protected function _validatePassword($old, $new1, $new2)
{
if (strlen($new1) == 0 || strlen($new2) == 0) {
return 'Do fill in a password!';
}
if ($new1 == $old) {
return 'The idea is to change your password.';
}
if ($new1 !== $new2) {
return 'New passwords do not match!';
}
return true;
}
}