Bypassed phpcs warnings that shouldn't be there

This commit is contained in:
Marcin Kurczewski 2014-09-16 14:04:53 +02:00
parent bc8e1b05a6
commit 047c84ec3a
3 changed files with 51 additions and 34 deletions

View file

@ -31,7 +31,7 @@ class PostService
public function createPost(\Szurubooru\FormData\UploadFormData $formData) public function createPost(\Szurubooru\FormData\UploadFormData $formData)
{ {
return $this->transactionManager->commit(function() use ($formData) $transactionFunc = function() use ($formData)
{ {
$formData->validate($this->validator); $formData->validate($this->validator);
@ -48,7 +48,8 @@ class PostService
$this->updatePostContentFromStringOrUrl($post, $formData->content, $formData->url); $this->updatePostContentFromStringOrUrl($post, $formData->content, $formData->url);
return $this->postDao->save($post); return $this->postDao->save($post);
}); };
return $this->transactionManager->commit($transactionFunc);
} }
private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety) private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety)

View file

@ -16,34 +16,37 @@ class TokenService
public function getByName($tokenName) public function getByName($tokenName)
{ {
return $this->transactionManager->rollback(function() use ($tokenName) $transactionFunc = function() use ($tokenName)
{ {
$token = $this->tokenDao->findByName($tokenName); $token = $this->tokenDao->findByName($tokenName);
if (!$token) if (!$token)
throw new \InvalidArgumentException('Token with identifier "' . $tokenName . '" not found.'); throw new \InvalidArgumentException('Token with identifier "' . $tokenName . '" not found.');
return $token; return $token;
}); };
return $this->transactionManager->rollback($transactionFunc);
} }
public function invalidateByName($tokenName) public function invalidateByName($tokenName)
{ {
$this->transactionManager->commit(function() use ($tokenName) $transactionFunc = function() use ($tokenName)
{ {
$this->tokenDao->deleteByName($tokenName); $this->tokenDao->deleteByName($tokenName);
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function invalidateByAdditionalData($additionalData) public function invalidateByAdditionalData($additionalData)
{ {
$this->transactionManager->commit(function() use ($additionalData) $transactionFunc = function() use ($additionalData)
{ {
$this->tokenDao->deleteByAdditionalData($additionalData); $this->tokenDao->deleteByAdditionalData($additionalData);
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function createAndSaveToken($additionalData, $tokenPurpose) public function createAndSaveToken($additionalData, $tokenPurpose)
{ {
return $this->transactionManager->commit(function() use ($additionalData, $tokenPurpose) $transactionFunc = function() use ($additionalData, $tokenPurpose)
{ {
$token = new \Szurubooru\Entities\Token(); $token = new \Szurubooru\Entities\Token();
$token->setName(sha1(date('r') . uniqid() . microtime(true))); $token->setName(sha1(date('r') . uniqid() . microtime(true)));
@ -52,6 +55,7 @@ class TokenService
$this->invalidateByAdditionalData($additionalData); $this->invalidateByAdditionalData($additionalData);
$this->tokenDao->save($token); $this->tokenDao->save($token);
return $token; return $token;
}); };
return $this->transactionManager->commit($transactionFunc);
} }
} }

View file

@ -43,7 +43,7 @@ class UserService
public function getByNameOrEmail($userNameOrEmail, $allowUnconfirmed = false) public function getByNameOrEmail($userNameOrEmail, $allowUnconfirmed = false)
{ {
return $this->transactionManager->rollback(function() use ($userNameOrEmail, $allowUnconfirmed) $transactionFunc = function() use ($userNameOrEmail, $allowUnconfirmed)
{ {
$user = $this->userDao->findByName($userNameOrEmail); $user = $this->userDao->findByName($userNameOrEmail);
if ($user) if ($user)
@ -54,44 +54,48 @@ class UserService
return $user; return $user;
throw new \InvalidArgumentException('User "' . $userNameOrEmail . '" was not found.'); throw new \InvalidArgumentException('User "' . $userNameOrEmail . '" was not found.');
}); };
return $this->transactionManager->rollback($transactionFunc);
} }
public function getByName($userName) public function getByName($userName)
{ {
return $this->transactionManager->rollback(function() use ($userName) $transactionFunc = function() use ($userName)
{ {
$user = $this->userDao->findByName($userName); $user = $this->userDao->findByName($userName);
if (!$user) if (!$user)
throw new \InvalidArgumentException('User with name "' . $userName . '" was not found.'); throw new \InvalidArgumentException('User with name "' . $userName . '" was not found.');
return $user; return $user;
}); };
return $this->transactionManager->rollback($transactionFunc);
} }
public function getById($userId) public function getById($userId)
{ {
return $this->transactionManager->rollback(function() use ($userId) $transactionFunc = function() use ($userId)
{ {
$user = $this->userDao->findById($userId); $user = $this->userDao->findById($userId);
if (!$user) if (!$user)
throw new \InvalidArgumentException('User with id "' . $userId . '" was not found.'); throw new \InvalidArgumentException('User with id "' . $userId . '" was not found.');
return $user; return $user;
}); };
return $this->transactionManager->rollback($transactionFunc);
} }
public function getFiltered(\Szurubooru\FormData\SearchFormData $formData) public function getFiltered(\Szurubooru\FormData\SearchFormData $formData)
{ {
return $this->transactionManager->rollback(function() use ($formData) $transactionFunc = function() use ($formData)
{ {
$this->validator->validate($formData); $this->validator->validate($formData);
$searchFilter = new \Szurubooru\Dao\SearchFilter($this->config->users->usersPerPage, $formData); $searchFilter = new \Szurubooru\Dao\SearchFilter($this->config->users->usersPerPage, $formData);
return $this->userSearchService->getFiltered($searchFilter); return $this->userSearchService->getFiltered($searchFilter);
}); };
return $this->transactionManager->rollback($transactionFunc);
} }
public function createUser(\Szurubooru\FormData\RegistrationFormData $formData) public function createUser(\Szurubooru\FormData\RegistrationFormData $formData)
{ {
return $this->transactionManager->commit(function() use ($formData) $transactionFunc = function() use ($formData)
{ {
$formData->validate($this->validator); $formData->validate($this->validator);
@ -107,12 +111,13 @@ class UserService
$this->updateUserAvatarStyle($user, \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR); $this->updateUserAvatarStyle($user, \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR);
$this->updateUserEmail($user, $formData->email); $this->updateUserEmail($user, $formData->email);
return $this->userDao->save($user); return $this->userDao->save($user);
}); };
return $this->transactionManager->commit($transactionFunc);
} }
public function updateUser(\Szurubooru\Entities\User $user, \Szurubooru\FormData\UserEditFormData $formData) public function updateUser(\Szurubooru\Entities\User $user, \Szurubooru\FormData\UserEditFormData $formData)
{ {
return $this->transactionManager->commit(function() use ($user, $formData) $transactionFunc = function() use ($user, $formData)
{ {
$this->validator->validate($formData); $this->validator->validate($formData);
@ -138,33 +143,36 @@ class UserService
$this->updateUserBrowsingSettings($user, $formData->browsingSettings); $this->updateUserBrowsingSettings($user, $formData->browsingSettings);
return $this->userDao->save($user); return $this->userDao->save($user);
}); };
return $this->transactionManager->commit($transactionFunc);
} }
public function deleteUser(\Szurubooru\Entities\User $user) public function deleteUser(\Szurubooru\Entities\User $user)
{ {
$this->transactionManager->commit(function() use ($user) $transactionFunc = function() use ($user)
{ {
$this->userDao->deleteById($user->getId()); $this->userDao->deleteById($user->getId());
$avatarSource = $this->getCustomAvatarSourcePath($user); $avatarSource = $this->getCustomAvatarSourcePath($user);
$this->fileService->delete($avatarSource); $this->fileService->delete($avatarSource);
$this->thumbnailService->deleteUsedThumbnails($avatarSource); $this->thumbnailService->deleteUsedThumbnails($avatarSource);
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function sendPasswordResetEmail(\Szurubooru\Entities\User $user) public function sendPasswordResetEmail(\Szurubooru\Entities\User $user)
{ {
$this->transactionManager->commit(function() use ($user) $transactionFunc = function() use ($user)
{ {
$token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET); $token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET);
$this->emailService->sendPasswordResetEmail($user, $token); $this->emailService->sendPasswordResetEmail($user, $token);
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function finishPasswordReset(\Szurubooru\Entities\Token $token) public function finishPasswordReset(\Szurubooru\Entities\Token $token)
{ {
return $this->transactionManager->commit(function() use ($token) $transactionFunc = function() use ($token)
{ {
if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET) if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET)
throw new \Exception('This token is not a password reset token.'); throw new \Exception('This token is not a password reset token.');
@ -175,21 +183,23 @@ class UserService
$this->userDao->save($user); $this->userDao->save($user);
$this->tokenService->invalidateByName($token->getName()); $this->tokenService->invalidateByName($token->getName());
return $newPassword; return $newPassword;
}); };
return $this->transactionManager->commit($transactionFunc);
} }
public function sendActivationEmail(\Szurubooru\Entities\User $user) public function sendActivationEmail(\Szurubooru\Entities\User $user)
{ {
$this->transactionManager->commit(function() use ($user) $transactionFunc = function() use ($user)
{ {
$token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_ACTIVATE); $token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_ACTIVATE);
$this->emailService->sendActivationEmail($user, $token); $this->emailService->sendActivationEmail($user, $token);
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function finishActivation(\Szurubooru\Entities\Token $token) public function finishActivation(\Szurubooru\Entities\Token $token)
{ {
$this->transactionManager->commit(function() use ($token) $transactionFunc = function() use ($token)
{ {
if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_ACTIVATE) if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_ACTIVATE)
throw new \Exception('This token is not an activation token.'); throw new \Exception('This token is not an activation token.');
@ -198,7 +208,8 @@ class UserService
$user = $this->confirmUserEmail($user); $user = $this->confirmUserEmail($user);
$this->userDao->save($user); $this->userDao->save($user);
$this->tokenService->invalidateByName($token->getName()); $this->tokenService->invalidateByName($token->getName());
}); };
$this->transactionManager->commit($transactionFunc);
} }
public function getCustomAvatarSourcePath(\Szurubooru\Entities\User $user) public function getCustomAvatarSourcePath(\Szurubooru\Entities\User $user)
@ -260,11 +271,12 @@ class UserService
public function updateUserLastLoginTime(\Szurubooru\Entities\User $user) public function updateUserLastLoginTime(\Szurubooru\Entities\User $user)
{ {
$this->transactionManager->commit(function() use ($user) $transactionFunc = function() use ($user)
{ {
$user->setLastLoginTime($this->timeService->getCurrentTime()); $user->setLastLoginTime($this->timeService->getCurrentTime());
$this->userDao->save($user); $this->userDao->save($user);
}); };
$this->transactionManager->commit($transactionFunc);
} }
private function sendActivationEmailIfNeeded(\Szurubooru\Entities\User $user) private function sendActivationEmailIfNeeded(\Szurubooru\Entities\User $user)