From 5cd125c133909b4ec8bc7fcb4310da744e38fda4 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Wed, 17 Dec 2014 18:31:16 +0100 Subject: [PATCH] Clean some code --- .../NewslettersServiceProvider.php | 6 ++--- .../Users/Composers/ProfileEditComposer.php | 2 +- .../Console/EmailSpecialEventCommand.php | 20 +++++++------- .../Users/Console/SendBirthdayCommand.php | 8 +++--- .../Users/Controllers/UsersController.php | 26 +++++++++---------- app/TeenQuotes/Users/Models/User.php | 10 +++---- .../Users/Repositories/DbUserRepository.php | 10 +++---- 7 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/TeenQuotes/Newsletters/NewslettersServiceProvider.php b/app/TeenQuotes/Newsletters/NewslettersServiceProvider.php index 7440b963..606f3f27 100644 --- a/app/TeenQuotes/Newsletters/NewslettersServiceProvider.php +++ b/app/TeenQuotes/Newsletters/NewslettersServiceProvider.php @@ -4,7 +4,7 @@ use TeenQuotes\Tools\Namespaces\NamespaceTrait; class NewslettersServiceProvider extends ServiceProvider { - + use NamespaceTrait; /** @@ -26,7 +26,7 @@ public function register() } private function registerBindings() - { + { $this->app->bind( $this->getNamespaceRepositories().'NewsletterRepository', $this->getNamespaceRepositories().'DbNewsletterRepository' @@ -36,7 +36,7 @@ private function registerBindings() private function registerCommands() { $commands = [ - 'newsletters.console.sendNewsletter' => $this->getNamespaceConsole().'SendNewsletterCommand', + 'newsletters.console.sendNewsletter' => $this->getNamespaceConsole().'SendNewsletterCommand', 'newsletters.console.unsubscribeUsers' => $this->getNamespaceConsole().'UnsubscribeUsersCommand', ]; diff --git a/app/TeenQuotes/Users/Composers/ProfileEditComposer.php b/app/TeenQuotes/Users/Composers/ProfileEditComposer.php index eb6f9bd9..5557d02d 100644 --- a/app/TeenQuotes/Users/Composers/ProfileEditComposer.php +++ b/app/TeenQuotes/Users/Composers/ProfileEditComposer.php @@ -10,7 +10,7 @@ class ProfileEditComposer extends AbstractDeepLinksComposer { public function compose($view) { $data = $view->getData(); - $user = $data['user']; + $user = $data['user']; $login = $user->login; // For deep links diff --git a/app/TeenQuotes/Users/Console/EmailSpecialEventCommand.php b/app/TeenQuotes/Users/Console/EmailSpecialEventCommand.php index cabb1fb5..5e074a9d 100644 --- a/app/TeenQuotes/Users/Console/EmailSpecialEventCommand.php +++ b/app/TeenQuotes/Users/Console/EmailSpecialEventCommand.php @@ -1,8 +1,6 @@ eventTypeIsValid()) { + if ($this->eventTypeIsValid()) + { $event = $this->getEvent(); $users = $this->userRepo->getAll(); - + $users->each(function($user) use($event) { // Log this info @@ -110,7 +109,8 @@ private function eventTypeIsValid() { $event = $this->getEvent(); - if (is_null($event) OR !in_array($event, $this->possibleEvents)) { + if (is_null($event) or ! in_array($event, $this->possibleEvents)) + { $this->error('Wrong type of event! Got '.$event.'. Possible values are: '.$this->presentPossibleEvents().'.'); return false; } @@ -135,9 +135,9 @@ private function presentPossibleEvents() */ protected function getArguments() { - return array( - array('event', InputArgument::REQUIRED, 'The name of the event. '.$this->presentPossibleEvents()), - ); + return [ + ['event', InputArgument::REQUIRED, 'The name of the event. '.$this->presentPossibleEvents()], + ]; } /** @@ -147,6 +147,6 @@ protected function getArguments() */ protected function getOptions() { - return array(); + return []; } } diff --git a/app/TeenQuotes/Users/Console/SendBirthdayCommand.php b/app/TeenQuotes/Users/Console/SendBirthdayCommand.php index 94e8193d..617f03f8 100644 --- a/app/TeenQuotes/Users/Console/SendBirthdayCommand.php +++ b/app/TeenQuotes/Users/Console/SendBirthdayCommand.php @@ -1,8 +1,6 @@ beforeFilter('guest', ['only' => 'store']); $this->beforeFilter('auth', ['only' => ['edit', 'update', 'putPassword', 'putSettings']]); - + $this->api = App::make('TeenQuotes\Api\V1\Controllers\UsersController'); $this->commentRepo = $commentRepo; $this->countryRepo = $countryRepo; @@ -123,14 +123,14 @@ public function store() // Call the API - skip the API validator $response = $this->api->store(false); - if ($response->getStatusCode() == 201) { - + if ($response->getStatusCode() == 201) + { // Log the user in Auth::login($response->getOriginalData()); if (Session::has('url.intended')) return Redirect::intended('/')->with('success', Lang::get('auth.signupSuccessfull', ['login' => $data['login']])); - + return Redirect::route('users.show', $data['login'])->with('success', Lang::get('auth.signupSuccessfull', ['login' => $data['login']])); } } @@ -147,7 +147,7 @@ private function redirectUserIfContentNotAvailable($user, $type) $publishPossible = $user->hasPublishedQuotes(); $favoritesPossible = $user->hasFavoriteQuotes(); $commentsPossible = $user->hasPostedComments(); - + // Check if we have content to display // If we have nothing to show, try to redirect somewhere else switch ($type) { @@ -198,7 +198,7 @@ public function show($user_id, $type = 'published') { // Get the user $user = $this->userRepo->getByLogin($user_id); - + if (is_null($user)) throw new UserNotFoundException; // Try to redirect to a better place if content is available @@ -399,7 +399,7 @@ public function putPassword($id) $user = $this->userRepo->getByLogin($id); if (! $this->userIsAllowedToEdit($user)) App::abort(401, 'Refused'); - + $this->userRepo->updatePassword($user, $data['password']); return Redirect::back()->with('success', Lang::get('users.updatePasswordSuccessfull', ['login' => $user->login])); @@ -416,13 +416,13 @@ public function putSettings($id) $user = $this->userRepo->getByLogin($id); if ( ! $this->userIsAllowedToEdit($user)) App::abort(401, 'Refused'); - + $response = $this->api->putSettings($user); // Handle error if ($response->getStatusCode() == 400) { $json = json_decode($response->getContent()); - + // If the color was wrong if ($json->status == 'wrong_color') return Redirect::back()->with('warning', Lang::get('users.colorNotAllowed')); @@ -447,7 +447,7 @@ public function destroy() // We will use a custom message for the delete confirmation input $messages = [ - 'delete-confirmation.in' => Lang::get('users.writeDeleteHere'), + 'delete-confirmation.in' => Lang::get('users.writeDeleteHere'), ]; try { @@ -459,7 +459,7 @@ public function destroy() ->withErrors($e->getErrors()) ->withInput(Input::except('password')); } - + unset($data['delete-confirmation']); if ( ! Auth::validate($data)) return $this->redirectToDeleteAccount(Auth::user()->login) diff --git a/app/TeenQuotes/Users/Models/User.php b/app/TeenQuotes/Users/Models/User.php index b509ee7e..26622570 100644 --- a/app/TeenQuotes/Users/Models/User.php +++ b/app/TeenQuotes/Users/Models/User.php @@ -19,7 +19,7 @@ use TeenQuotes\Users\Models\Scopes\UserTrait as UserScopesTrait; class User extends Eloquent implements UserInterface, RemindableInterface { - + use PresentableTrait, RemindableTrait, UserTrait, UserRelationsTrait, UserScopesTrait; protected $presenter = 'TeenQuotes\Users\Presenters\UserPresenter'; @@ -80,10 +80,10 @@ class User extends Eloquent implements UserInterface, RemindableInterface { */ private $quoteRepo; - function __construct($attributes = []) + public function __construct($attributes = []) { parent::__construct($attributes); - + $this->favQuoteRepo = App::make('TeenQuotes\Quotes\Repositories\FavoriteQuoteRepository'); $this->settingRepo = App::make('TeenQuotes\Settings\Repositories\SettingRepository'); $this->newsletterRepo = App::make('TeenQuotes\Newsletters\Repositories\NewsletterRepository'); @@ -173,7 +173,7 @@ public function getAddedFavCount() if (empty($idsQuotesPublished)) return 0; - + return $this->favQuoteRepo->nbFavoritesForQuotes($idsQuotesPublished); } @@ -235,7 +235,7 @@ public function getURLAvatarAttribute() /** * Returns the array of the ID of the quotes in the favorites of the user - * @return array + * @return array */ public function arrayIDFavoritesQuotes() { diff --git a/app/TeenQuotes/Users/Repositories/DbUserRepository.php b/app/TeenQuotes/Users/Repositories/DbUserRepository.php index 8c9a8e8f..b3342cc5 100644 --- a/app/TeenQuotes/Users/Repositories/DbUserRepository.php +++ b/app/TeenQuotes/Users/Repositories/DbUserRepository.php @@ -29,13 +29,13 @@ public function getByEmails(array $emails) /** * Retrieve a user by its login - * @param string $login + * @param string $login * @return TeenQuotes\Users\Models\User */ public function getByLogin($login) { return User::whereLogin($login) - ->first(); + ->first(); } /** @@ -75,7 +75,7 @@ public function updatePassword($u, $password) public function updateProfile($u, $gender, $country, $city, $about_me, $birthdate, $avatar) { $user = $this->retrieveUser($u); - + if ( ! empty($gender)) $user->gender = $gender; if ( ! empty($country)) @@ -84,7 +84,7 @@ public function updateProfile($u, $gender, $country, $city, $about_me, $birthdat $user->city = $city; if ( ! empty($about_me)) $user->about_me = $about_me; - $user->birthdate = empty($birthdate) ? NULL : $birthdate; + $user->birthdate = empty($birthdate) ? null : $birthdate; if ( ! is_null($avatar)) { $filename = $user->id.'.'.$avatar->getClientOriginalExtension(); @@ -247,7 +247,7 @@ private function computeSkip($page, $pagesize) { return $pagesize * ($page - 1); } - + /** * Retrieve a user by its ID or just the user instance * @param TeenQuotes\Users\Models\User|int $u