Skip to content

Commit

Permalink
Clean some code
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Dec 17, 2014
1 parent 288bbe1 commit 5cd125c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 42 deletions.
6 changes: 3 additions & 3 deletions app/TeenQuotes/Newsletters/NewslettersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use TeenQuotes\Tools\Namespaces\NamespaceTrait;

class NewslettersServiceProvider extends ServiceProvider {

use NamespaceTrait;

/**
Expand All @@ -26,7 +26,7 @@ public function register()
}

private function registerBindings()
{
{
$this->app->bind(
$this->getNamespaceRepositories().'NewsletterRepository',
$this->getNamespaceRepositories().'DbNewsletterRepository'
Expand All @@ -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',
];

Expand Down
2 changes: 1 addition & 1 deletion app/TeenQuotes/Users/Composers/ProfileEditComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions app/TeenQuotes/Users/Console/EmailSpecialEventCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php namespace TeenQuotes\Users\Console;

use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Lang, Log, Mail;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -86,11 +84,12 @@ public function environment()
*/
public function fire()
{
if ($this->eventTypeIsValid()) {
if ($this->eventTypeIsValid())
{
$event = $this->getEvent();

$users = $this->userRepo->getAll();

$users->each(function($user) use($event)
{
// Log this info
Expand All @@ -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;
}
Expand All @@ -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()],
];
}

/**
Expand All @@ -147,6 +147,6 @@ protected function getArguments()
*/
protected function getOptions()
{
return array();
return [];
}
}
8 changes: 3 additions & 5 deletions app/TeenQuotes/Users/Console/SendBirthdayCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php namespace TeenQuotes\Users\Console;

use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Lang, Log, Mail;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use TeenQuotes\Mail\MailSwitcher;
Expand Down Expand Up @@ -95,7 +93,7 @@ public function fire()
*/
protected function getArguments()
{
return array();
return [];
}

/**
Expand All @@ -105,6 +103,6 @@ protected function getArguments()
*/
protected function getOptions()
{
return array();
return [];
}
}
26 changes: 13 additions & 13 deletions app/TeenQuotes/Users/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class UsersController extends BaseController {
*/
private $userValidator;

public function __construct(CommentRepository $commentRepo, CountryRepository $countryRepo,
QuoteRepository $quoteRepo, SettingRepository $settingRepo, UserRepository $userRepo,
public function __construct(CommentRepository $commentRepo, CountryRepository $countryRepo,
QuoteRepository $quoteRepo, SettingRepository $settingRepo, UserRepository $userRepo,
UserValidator $userValidator)
{
$this->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;
Expand Down Expand Up @@ -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']]));
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]));
Expand All @@ -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'));
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions app/TeenQuotes/Users/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -173,7 +173,7 @@ public function getAddedFavCount()

if (empty($idsQuotesPublished))
return 0;

return $this->favQuoteRepo->nbFavoritesForQuotes($idsQuotesPublished);
}

Expand Down Expand Up @@ -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()
{
Expand Down
10 changes: 5 additions & 5 deletions app/TeenQuotes/Users/Repositories/DbUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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))
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5cd125c

Please sign in to comment.