Skip to content

Commit

Permalink
Adopt PSR-2 coding style
Browse files Browse the repository at this point in the history
The Laravel framework adopts the PSR-2 coding style in version 5.1.
Laravel apps *should* adopt this coding style as well. Read the
[PSR-2 coding style guide][1] for more details and check out [PHPCS][2]
to use as a code formatting tool.

[1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[2]: https://github.com/squizlabs/PHP_CodeSniffer
  • Loading branch information
laravel-shift committed Jul 27, 2018
1 parent cb92637 commit a3184d5
Show file tree
Hide file tree
Showing 42 changed files with 237 additions and 511 deletions.
3 changes: 1 addition & 2 deletions app/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public function geocode()


$geocode = app('geocoder')->geocode($this->location)->get()->first();
if ($geocode)
{
if ($geocode) {
$this->latitude = $geocode->getCoordinates()->getLatitude();
$this->longitude = $geocode->getCoordinates()->getLongitude();
return true;
Expand Down
1 change: 0 additions & 1 deletion app/ActionUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public function user()
{
return $this->belongsTo('\App\User');
}

}
30 changes: 9 additions & 21 deletions app/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Activity extends Model
'user_id' => 'required|exists:users,id',
'group_id' => 'required|exists:groups,id',
'action' => 'required|in:created,updated,deleted,commented',
];
];


/**
Expand All @@ -41,23 +41,19 @@ public function group()

public function getType()
{
if ($this->model instanceof Discussion)
{
if ($this->model instanceof Discussion) {
return 'discussion';
}

if ($this->model instanceof File)
{
if ($this->model instanceof File) {
return 'file';
}

if ($this->model instanceof Action)
{
if ($this->model instanceof Action) {
return 'action';
}

if ($this->model instanceof Comment)
{
if ($this->model instanceof Comment) {
return 'comment';
}
}
Expand All @@ -69,28 +65,20 @@ public function getType()
public function linkToModel()
{

if ($this->model instanceof Discussion)
{
if ($this->model instanceof Discussion) {
return route('groups.discussions.show', [$this->group, $this->model]);
}

if ($this->model instanceof File)
{
if ($this->model instanceof File) {
return route('groups.files.show', [$this->group, $this->model]);
}

if ($this->model instanceof Action)
{
if ($this->model instanceof Action) {
return route('groups.actions.show', [$this->group, $this->model]);
}

if ($this->model instanceof Comment)
{
if ($this->model instanceof Comment) {
return route('groups.discussions.show', [$this->group, $this->model->discussion]);
}


}


}
2 changes: 1 addition & 1 deletion app/Console/Commands/ImportActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle()

// build a nice associative array from the csv
foreach ($res as $data) {
foreach ($headers as $key=>$header) {
foreach ($headers as $key => $header) {
$action[$header] = $data[$key];
}
$actions_data[] = $action;
Expand Down
7 changes: 2 additions & 5 deletions app/Console/Commands/PopulateFilesize.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ public function __construct()
*/
public function handle()
{
foreach (\App\File::all() as $file)
{
if (Storage::exists($file->path))
{
foreach (\App\File::all() as $file) {
if (Storage::exists($file->path)) {
$file->filesize = Storage::size($file->path);
$file->save();
}
}

}
}
2 changes: 1 addition & 1 deletion app/Discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Discussion extends Model
'body' => 'required|min:5',
'user_id' => 'required|exists:users,id',
'group_id' => 'required|exists:groups,id',
];
];

protected $dontKeepRevisionOf = ['total_comments'];

Expand Down
5 changes: 1 addition & 4 deletions app/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ public function isLink()

public function isImage()
{
if (in_array($this->mime, ['image/jpeg', 'image/png', 'image/gif']))
{
if (in_array($this->mime, ['image/jpeg', 'image/png', 'image/gif'])) {
return true;
}
return false;
}


}
10 changes: 4 additions & 6 deletions app/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function color()
*/
public function users()
{
return $this->belongsToMany('App\User', 'membership')->where('membership', '>=',\App\Membership::MEMBER)->withTimestamps()->withPivot('membership');
return $this->belongsToMany('App\User', 'membership')->where('membership', '>=', \App\Membership::MEMBER)->withTimestamps()->withPivot('membership');
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ public function activities()
}

/**
* Returns true if current user is a member of this group.
* Returns true if current user is a member of this group.
*/
public function isMember()
{
Expand Down Expand Up @@ -277,17 +277,15 @@ public function setSetting($key, $value)
*/
public function geocode()
{
if ($this->address == '')
{
if ($this->address == '') {
$this->latitude = 0;
$this->longitude = 0;
return true;
}

$geocode = app('geocoder')->geocode($this->address)->get()->first();

if ($geocode)
{
if ($geocode) {
$this->latitude = $geocode->getCoordinates()->getLatitude();
$this->longitude = $geocode->getCoordinates()->getLongitude();
return true;
Expand Down
23 changes: 6 additions & 17 deletions app/Helpers/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,17 @@ function setting($name, $default = false)

function sizeForHumans($bytes)
{
if ($bytes >= 1073741824)
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . 'GB';
}
elseif ($bytes >= 1048576)
{
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . 'MB';
}
elseif ($bytes >= 1024)
{
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . 'KB';
}
elseif ($bytes > 1)
{
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
}
else
{
} else {
$bytes = '0 bytes';
}

Expand Down
89 changes: 26 additions & 63 deletions app/Http/Controllers/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,35 @@ public function index(Request $request, Group $group)
{
$view = 'grid';

if (Auth::check())
{
if (Auth::user()->getPreference('calendar'))
{
if (Auth::user()->getPreference('calendar') == 'list')
{
if (Auth::check()) {
if (Auth::user()->getPreference('calendar')) {
if (Auth::user()->getPreference('calendar') == 'list') {
$view = 'list';
}
else
{
} else {
$view = 'grid';
}
}

if ($request->get('type') == 'list')
{
if ($request->get('type') == 'list') {
Auth::user()->setPreference('calendar', 'list');
$view = 'list';
}

if ($request->get('type') == 'grid')
{
if ($request->get('type') == 'grid') {
Auth::user()->setPreference('calendar', 'grid');
$view = 'grid';
}

}
else
{

if ($request->get('type') == 'list')
{
} else {
if ($request->get('type') == 'list') {
$view = 'list';
}

if ($request->get('type') == 'grid')
{
if ($request->get('type') == 'grid') {
$view = 'grid';
}

}

if ($view == 'list')
{
if ($view == 'list') {
$actions = $group->actions()
->orderBy('start', 'asc')
->where('start', '>=', Carbon::now()->subDays(1))
Expand Down Expand Up @@ -132,9 +117,7 @@ public function create(Request $request, Group $group)

if ($request->get('start')) {
$action->start = Carbon::createFromFormat('Y-m-d H:i', $request->get('start'));
}
else
{
} else {
$action->start = Carbon::now();
}

Expand All @@ -161,8 +144,7 @@ public function create(Request $request, Group $group)
public function store(Request $request, Group $group)
{
// if no group is in the route, it means user choose the group using the dropdown
if (!$group->exists)
{
if (!$group->exists) {
$group = \App\Group::findOrFail($request->get('group'));
}

Expand All @@ -173,54 +155,39 @@ public function store(Request $request, Group $group)
$action->name = $request->input('name');
$action->body = $request->input('body');

try
{
try {
$action->start = Carbon::createFromFormat('Y-m-d H:i', $request->input('start_date') . ' ' . $request->input('start_time'));
}
catch (\Exception $e)
{
} catch (\Exception $e) {
return redirect()->route('groups.actions.create', $group)
->withErrors($e->getMessage() . '. Incorrect format in the start date, use yyyy-mm-dd hh:mm')
->withInput();
}


if ($request->get('stop_time'))
{
if ($request->get('stop_time')) {
$stop_time = $request->get('stop_time');
}
else
{
} else {
$stop_time = $request->input('start_time');
}

try
{
if ($request->get('stop_date'))
{
if ($request->get('stop_time'))
{
try {
if ($request->get('stop_date')) {
if ($request->get('stop_time')) {
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('stop_date') . ' ' . $request->input('stop_time'));
}
else // asssume action will have a one hour duration
} else // asssume action will have a one hour duration
{
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('stop_date') . ' ' . $request->input('start_time'))->addHour();
}
}
else // assume it will be same day
} else // assume it will be same day
{
if ($request->get('stop_time'))
{
if ($request->get('stop_time')) {
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('start_date') . ' ' . $request->input('stop_time'));
}
else // asssume action will have a one hour duration
} else // asssume action will have a one hour duration
{
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('start_date') . ' ' . $request->input('start_time'))->addHour();
}
}
}
catch (\Exception $e)
{
} catch (\Exception $e) {
return redirect()->route('groups.actions.create', $group)
->withErrors($e->getMessage() . '. Incorrect format in the stop date, use yyyy-mm-dd hh:mm')
->withInput();
Expand Down Expand Up @@ -299,18 +266,14 @@ public function update(Request $request, Group $group, Action $action)

$action->start = Carbon::createFromFormat('Y-m-d H:i', $request->input('start_date') . ' ' . $request->input('start_time'));

if ($request->has('stop_date') && $request->get('stop_date')<>'')
{
if ($request->has('stop_date') && $request->get('stop_date')<>'') {
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('stop_date') . ' ' . $request->input('stop_time'));
}
else
{
} else {
$action->stop = Carbon::createFromFormat('Y-m-d H:i', $request->input('start_date') . ' ' . $request->input('stop_time'));
}


if ($action->location != $request->input('location')) {

// we need to update user address and geocode it
$action->location = $request->input('location');
if (!$action->geocode()) {
Expand Down
Loading

0 comments on commit a3184d5

Please sign in to comment.