Skip to content

Commit

Permalink
Set /app PHP code to PSR-2 standard
Browse files Browse the repository at this point in the history
Also adde draw.io to attribution list.

Closes #649
  • Loading branch information
ssddanbrown committed Jan 28, 2018
1 parent 30b4f81 commit 6234243
Show file tree
Hide file tree
Showing 80 changed files with 593 additions and 335 deletions.
8 changes: 5 additions & 3 deletions app/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class Activity extends Model
*/
public function entity()
{
if ($this->entity_type === '') $this->entity_type = null;
if ($this->entity_type === '') {
$this->entity_type = null;
}
return $this->morphTo('entity');
}

Expand All @@ -43,8 +45,8 @@ public function getText()
* @param $activityB
* @return bool
*/
public function isSimilarTo($activityB) {
public function isSimilarTo($activityB)
{
return [$this->key, $this->entity_type, $this->entity_id] === [$activityB->key, $activityB->entity_type, $activityB->entity_id];
}

}
6 changes: 3 additions & 3 deletions app/Attachment.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack;


class Attachment extends Ownable
{
protected $fillable = ['name', 'order'];
Expand All @@ -11,7 +10,9 @@ class Attachment extends Ownable
*/
public function getFileName()
{
if (str_contains($this->name, '.')) return $this->name;
if (str_contains($this->name, '.')) {
return $this->name;
}
return $this->name . '.' . $this->extension;
}

Expand All @@ -32,5 +33,4 @@ public function getUrl()
{
return baseUrl('/attachments/' . $this->id);
}

}
5 changes: 3 additions & 2 deletions app/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function getUrl($path = false)
public function getBookCover($width = 440, $height = 250)
{
$default = baseUrl('/book_default_cover.png');
if (!$this->image_id) return $default;
if (!$this->image_id) {
return $default;
}

try {
$cover = $this->cover ? baseUrl($this->cover->getThumb($width, $height, false)) : $default;
Expand Down Expand Up @@ -91,5 +93,4 @@ public function entityRawQuery()
{
return "'BookStack\\\\Book' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text,'' as html, '0' as book_id, '0' as priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";
}

}
2 changes: 0 additions & 2 deletions app/Chapter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack;


class Chapter extends Entity
{
protected $fillable = ['name', 'description', 'priority', 'book_id'];
Expand Down Expand Up @@ -59,5 +58,4 @@ public function entityRawQuery()
{
return "'BookStack\\\\Chapter' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text, '' as html, book_id, priority, '0' as chapter_id, '0' as draft, created_by, updated_by, updated_at, created_at";
}

}
17 changes: 6 additions & 11 deletions app/Console/Commands/DeleteUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use BookStack\Repos\UserRepo;
use Illuminate\Console\Command;

class DeleteUsers extends Command{
class DeleteUsers extends Command
{

/**
* The name and signature of the console command.
Expand Down Expand Up @@ -37,26 +38,20 @@ public function handle()
{
$confirm = $this->ask('This will delete all users from the system that are not "admin" or system users. Are you sure you want to continue? (Type "yes" to continue)');
$numDeleted = 0;
if (strtolower(trim($confirm)) === 'yes')
{
if (strtolower(trim($confirm)) === 'yes') {
$totalUsers = $this->user->count();
$users = $this->user->where('system_name', '=', null)->with('roles')->get();
foreach ($users as $user)
{
if ($user->hasSystemRole('admin'))
{
foreach ($users as $user) {
if ($user->hasSystemRole('admin')) {
// don't delete users with "admin" role
continue;
}
$this->userRepo->destroy($user);
++$numDeleted;
}
$this->info("Deleted $numDeleted of $totalUsers total users.");
}
else
{
} else {
$this->info('Exiting...');
}
}

}
20 changes: 14 additions & 6 deletions app/Entity.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack;


use Illuminate\Database\Eloquent\Relations\MorphMany;

class Entity extends Ownable
Expand Down Expand Up @@ -28,7 +27,9 @@ public function matchesOrContains(Entity $entity)
{
$matches = [get_class($this), $this->id] === [get_class($entity), $entity->id];

if ($matches) return true;
if ($matches) {
return true;
}

if (($entity->isA('chapter') || $entity->isA('page')) && $this->isA('book')) {
return $entity->book_id === $this->id;
Expand Down Expand Up @@ -159,7 +160,9 @@ public static function getEntityInstance($type)
*/
public function getShortName($length = 25)
{
if (strlen($this->name) <= $length) return $this->name;
if (strlen($this->name) <= $length) {
return $this->name;
}
return substr($this->name, 0, $length - 3) . '...';
}

Expand All @@ -176,13 +179,18 @@ public function getText()
* Return a generalised, common raw query that can be 'unioned' across entities.
* @return string
*/
public function entityRawQuery(){return '';}
public function entityRawQuery()
{
return '';
}

/**
* Get the url of this entity
* @param $path
* @return string
*/
public function getUrl($path){return '/';}

public function getUrl($path)
{
return '/';
}
}
1 change: 0 additions & 1 deletion app/EntityPermission.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack;


class EntityPermission extends Model
{

Expand Down
4 changes: 3 additions & 1 deletion app/Exceptions/AuthException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class AuthException extends PrettyException
{

class AuthException extends PrettyException {}
}
4 changes: 3 additions & 1 deletion app/Exceptions/ConfirmationEmailException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class ConfirmationEmailException extends NotifyException
{

class ConfirmationEmailException extends NotifyException {}
}
4 changes: 3 additions & 1 deletion app/Exceptions/FileUploadException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class FileUploadException extends PrettyException
{

class FileUploadException extends PrettyException {}
}
10 changes: 7 additions & 3 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ protected function loadErrorMiddleware(Request $request, $callback)
* @param $type
* @return bool
*/
protected function isExceptionType(Exception $e, $type) {
protected function isExceptionType(Exception $e, $type)
{
do {
if (is_a($e, $type)) return true;
if (is_a($e, $type)) {
return true;
}
} while ($e = $e->getPrevious());
return false;
}
Expand All @@ -107,7 +110,8 @@ protected function isExceptionType(Exception $e, $type) {
* @param Exception $e
* @return string
*/
protected function getOriginalMessage(Exception $e) {
protected function getOriginalMessage(Exception $e)
{
do {
$message = $e->getMessage();
} while ($e = $e->getPrevious());
Expand Down
5 changes: 4 additions & 1 deletion app/Exceptions/ImageUploadException.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php namespace BookStack\Exceptions;

class ImageUploadException extends PrettyException {}
class ImageUploadException extends PrettyException
{

}
5 changes: 4 additions & 1 deletion app/Exceptions/LdapException.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php namespace BookStack\Exceptions;

class LdapException extends PrettyException {}
class LdapException extends PrettyException
{

}
6 changes: 3 additions & 3 deletions app/Exceptions/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace BookStack\Exceptions;


class NotFoundException extends PrettyException {
class NotFoundException extends PrettyException
{

/**
* NotFoundException constructor.
Expand All @@ -11,4 +11,4 @@ public function __construct($message = 'Item not found')
{
parent::__construct($message, 404);
}
}
}
3 changes: 1 addition & 2 deletions app/Exceptions/NotifyException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace BookStack\Exceptions;


class NotifyException extends \Exception
{

Expand All @@ -18,4 +17,4 @@ public function __construct($message, $redirectLocation)
$this->redirectLocation = $redirectLocation;
parent::__construct();
}
}
}
6 changes: 4 additions & 2 deletions app/Exceptions/PermissionsException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace BookStack\Exceptions;


use Exception;

class PermissionsException extends Exception {}
class PermissionsException extends Exception
{

}
5 changes: 4 additions & 1 deletion app/Exceptions/PrettyException.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php namespace BookStack\Exceptions;

class PrettyException extends \Exception {}
class PrettyException extends \Exception
{

}
4 changes: 3 additions & 1 deletion app/Exceptions/SocialDriverNotConfigured.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class SocialDriverNotConfigured extends PrettyException
{

class SocialDriverNotConfigured extends PrettyException {}
}
4 changes: 3 additions & 1 deletion app/Exceptions/SocialSignInException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class SocialSignInException extends NotifyException
{

class SocialSignInException extends NotifyException {}
}
4 changes: 3 additions & 1 deletion app/Exceptions/UserRegistrationException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace BookStack\Exceptions;

class UserRegistrationException extends NotifyException
{

class UserRegistrationException extends NotifyException {}
}
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ public function sendResetLinkEmail(Request $request)
['email' => trans($response)]
);
}

}
}
7 changes: 4 additions & 3 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public function username()
protected function authenticated(Request $request, Authenticatable $user)
{
// Explicitly log them out for now if they do no exist.
if (!$user->exists) auth()->logout($user);
if (!$user->exists) {
auth()->logout($user);
}

if (!$user->exists && $user->email === null && !$request->filled('email')) {
$request->flash();
Expand All @@ -83,7 +85,6 @@ protected function authenticated(Request $request, Authenticatable $user)
}

if (!$user->exists) {

// Check for users with same email already
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
if ($alreadyUser) {
Expand Down Expand Up @@ -130,4 +131,4 @@ public function getSocialLogin($socialDriver)
session()->put('social-callback', 'login');
return $this->socialAuthService->startLogIn($socialDriver);
}
}
}
14 changes: 9 additions & 5 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public function postRegister(Request $request)

if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
$request,
$validator
);
}

Expand Down Expand Up @@ -272,8 +273,12 @@ public function socialCallback($socialDriver, Request $request)
}

$action = session()->pull('social-callback');
if ($action == 'login') return $this->socialAuthService->handleLoginCallback($socialDriver);
if ($action == 'register') return $this->socialRegisterCallback($socialDriver);
if ($action == 'login') {
return $this->socialAuthService->handleLoginCallback($socialDriver);
}
if ($action == 'register') {
return $this->socialRegisterCallback($socialDriver);
}
return redirect()->back();
}

Expand Down Expand Up @@ -308,5 +313,4 @@ protected function socialRegisterCallback($socialDriver)
];
return $this->registerUser($userData, $socialAccount);
}

}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ protected function sendResetResponse($response)
return redirect($this->redirectPath())
->with('status', trans($response));
}
}
}
Loading

0 comments on commit 6234243

Please sign in to comment.