From 8233afa8254076bc52d39a8579aa02cd26f31442 Mon Sep 17 00:00:00 2001 From: James Collins Date: Fri, 20 Oct 2023 11:10:33 +1000 Subject: [PATCH] codesniffer fixes --- app/Conductors/Conductor.php | 49 +++--- app/Conductors/EventConductor.php | 1 + app/Conductors/MediaConductor.php | 15 +- app/Conductors/SubscriptionConductor.php | 8 +- app/Conductors/UserConductor.php | 6 +- app/Console/Commands/CleanupTempFiles.php | 11 +- app/Console/Commands/RemoveStaleMediaJobs.php | 5 +- app/Console/Kernel.php | 3 + app/Enum/Enum.php | 2 + app/Exceptions/Handler.php | 14 +- app/Helpers/Array.php | 6 +- app/Helpers/Temp.php | 15 +- .../Controllers/Api/AnalyticsController.php | 6 +- .../Controllers/Api/AttachmentController.php | 84 ---------- app/Http/Controllers/Api/AuthController.php | 8 +- app/Http/Controllers/Api/EventController.php | 46 +++++- app/Http/Controllers/Api/LogController.php | 53 ++++++- app/Http/Controllers/Api/MediaController.php | 110 ++++++++----- .../Controllers/Api/MediaJobController.php | 5 +- app/Http/Controllers/Api/OCRController.php | 5 +- .../Controllers/Api/ShortlinkController.php | 12 +- .../Api/SubscriptionController.php | 146 ------------------ app/Http/Controllers/Api/UserController.php | 14 +- app/Http/Middleware/LogRequest.php | 4 +- .../Middleware/RedirectIfAuthenticated.php | 7 +- app/Http/Middleware/UnmangleRequest.php | 6 +- app/Http/Middleware/UseSanctumGuard.php | 4 +- app/Http/Requests/BaseRequest.php | 15 +- app/Http/Requests/MediaRequest.php | 5 + app/Http/Requests/SubscriptionRequest.php | 2 + app/Http/Requests/UserRequest.php | 8 +- app/Jobs/MediaWorkerJob.php | 6 +- app/Jobs/SendEmailJob.php | 2 + app/Mail/ChangeEmailVerify.php | 4 + app/Mail/ChangedEmail.php | 4 + app/Mail/ChangedPassword.php | 4 + app/Mail/Contact.php | 4 + app/Mail/EmailVerify.php | 4 + app/Mail/ExceptionMail.php | 4 + app/Mail/ForgotPassword.php | 4 + app/Mail/SubscriptionConfirm.php | 4 + app/Mail/SubscriptionUnsubscribed.php | 4 + app/Models/EventUsers.php | 5 + app/Models/Media.php | 63 ++++++-- app/Models/MediaJob.php | 22 +-- app/Models/Permission.php | 3 + app/Models/UserLogins.php | 3 + app/Providers/AuthServiceProvider.php | 2 + app/Providers/BroadcastServiceProvider.php | 2 + app/Providers/EventServiceProvider.php | 4 + app/Providers/RouteServiceProvider.php | 7 +- app/Rules/Recaptcha.php | 3 + app/Rules/UniqueFileName.php | 8 +- app/Rules/Uniqueish.php | 6 +- app/Traits/HasGallery.php | 5 + app/Traits/Uuids.php | 6 + config/broadcasting.php | 2 +- config/clamav.php | 3 +- config/database.php | 2 +- tests/CreatesApplication.php | 2 + tests/Feature/ArticlesApiTest.php | 26 ++++ tests/Feature/AuthApiTest.php | 16 ++ tests/Feature/ContactFormTest.php | 13 ++ tests/Feature/EventsApiTest.php | 31 ++++ tests/Feature/UsersApiTest.php | 42 +++++ tests/TestCase.php | 5 + tests/Unit/ExampleTest.php | 2 + 67 files changed, 608 insertions(+), 394 deletions(-) delete mode 100644 app/Http/Controllers/Api/AttachmentController.php delete mode 100644 app/Http/Controllers/Api/SubscriptionController.php diff --git a/app/Conductors/Conductor.php b/app/Conductors/Conductor.php index 4ca2cc4..5ed9823 100644 --- a/app/Conductors/Conductor.php +++ b/app/Conductors/Conductor.php @@ -191,7 +191,7 @@ class Conductor if ($separatorPos !== false) { $operator = '=='; $valueList = explode('|', $value); - foreach($valueList as $valueItem) { + foreach ($valueList as $valueItem) { $this->appendFilter($field, $operator, $valueItem, 'OR'); } continue 2; @@ -289,14 +289,14 @@ class Conductor } } } else { - if(count($condition) < 3 && $condition[0] !== '') { - if(count($condition) < 2) { + if (count($condition) < 3 && $condition[0] !== '') { + if (count($condition) < 2) { $condition[1] = 'LIKE'; } $condition[2] = '%'; } - - if(count($condition) === 3) { + + if (count($condition) === 3) { list($field, $operator, $value) = $condition; if ($item !== null) { @@ -609,7 +609,7 @@ class Conductor $requestIncludes = []; $modelFields = $conductor->fields(new $conductor->class()); - + // Limit fields $limitFields = $modelFields; if ($fields instanceof Request) { @@ -781,8 +781,11 @@ class Conductor * @param string $outerJoin The join for this filter group. * @return void */ - final public function appendFilterString(string $rawFilter, array|null $limitFields = null, string $outerJoin = 'AND'): void - { + final public function appendFilterString( + string $rawFilter, + array|null $limitFields = null, + string $outerJoin = 'AND' + ): void { if ($rawFilter === '') { return; } @@ -924,18 +927,26 @@ class Conductor */ public function fields(Model $model): array { - $visibleFields = Cache::remember("model:{$model->getTable()}:visible", now()->addDays(28), function () use ($model) { - $fields = $model->getVisible(); - if (empty($fields) === true) { - $fields = Cache::remember("schema:{$model->getTable()}:columns", now()->addDays(28), function () use ($model) { - return $model->getConnection() - ->getSchemaBuilder() - ->getColumnListing($model->getTable()); - }); - } + $visibleFields = Cache::remember( + "model:{$model->getTable()}:visible", + now()->addDays(28), + function () use ($model) { + $fields = $model->getVisible(); + if (empty($fields) === true) { + $fields = Cache::remember( + "schema:{$model->getTable()}:columns", + now()->addDays(28), + function () use ($model) { + return $model->getConnection() + ->getSchemaBuilder() + ->getColumnListing($model->getTable()); + } + ); + } - return $fields; - }); + return $fields; + } + ); $appends = $model->getAppends(); if (is_array($appends) === true) { diff --git a/app/Conductors/EventConductor.php b/app/Conductors/EventConductor.php index f30d7b3..d91c14e 100644 --- a/app/Conductors/EventConductor.php +++ b/app/Conductors/EventConductor.php @@ -34,6 +34,7 @@ class EventConductor extends Conductor * Run a scope query on the collection before anything else. * * @param Builder $builder The builder in use. + * @return void */ public function scope(Builder $builder): void { diff --git a/app/Conductors/MediaConductor.php b/app/Conductors/MediaConductor.php index def1340..f627744 100644 --- a/app/Conductors/MediaConductor.php +++ b/app/Conductors/MediaConductor.php @@ -96,7 +96,7 @@ class MediaConductor extends Conductor if ($user === null || $user->hasPermission($model->security_data) === false) { return false; } - } else if($model->security_type !== '' && strcasecmp('password', $model->security_type) !== 0) { + } elseif ($model->security_type !== '' && strcasecmp('password', $model->security_type) !== 0) { return false; } @@ -168,8 +168,17 @@ class MediaConductor extends Conductor return UserConductor::includeModel(request(), 'user', $user); } - public function includeJobs(Model $model) { - $jobs = $model->jobs()->select(['id','created_at','updated_at','user_id','status','status_text','progress'])->orderBy('created_at', 'desc')->get(); + /** + * Include job models in Media + * + * @param Model $model The reference model. + * @return mixed + */ + public function includeJobs(Model $model) + { + $jobs = $model->jobs() + ->select(['id','created_at','updated_at','user_id','status','status_text','progress']) + ->orderBy('created_at', 'desc')->get(); return $jobs; } } diff --git a/app/Conductors/SubscriptionConductor.php b/app/Conductors/SubscriptionConductor.php index ed07d52..5bc3a3a 100644 --- a/app/Conductors/SubscriptionConductor.php +++ b/app/Conductors/SubscriptionConductor.php @@ -23,7 +23,10 @@ class SubscriptionConductor extends Conductor { /** @var \App\Models\User */ $user = auth()->user(); - return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true)); + return ($user !== null && ( + (strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || + $user->hasPermission('admin/subscriptions') === true + )); } /** @@ -36,6 +39,7 @@ class SubscriptionConductor extends Conductor { /** @var \App\Models\User */ $user = auth()->user(); - return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true)); + return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && + $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true)); } } diff --git a/app/Conductors/UserConductor.php b/app/Conductors/UserConductor.php index 89bdb19..4222de9 100644 --- a/app/Conductors/UserConductor.php +++ b/app/Conductors/UserConductor.php @@ -43,7 +43,11 @@ class UserConductor extends Conductor $data = $model->toArray(); $limit = $this->fields($model); - if ($user === null || ($user->hasPermission('admin/users') === false && strcasecmp($user->id, $model->id) !== 0)) { + if ( + $user === null || ( + $user->hasPermission('admin/users') === false && strcasecmp($user->id, $model->id) !== 0 + ) + ) { $limit = ['id', 'display_name']; } else { $data['permissions'] = $user->permissions; diff --git a/app/Console/Commands/CleanupTempFiles.php b/app/Console/Commands/CleanupTempFiles.php index b07137a..a68ad2f 100644 --- a/app/Console/Commands/CleanupTempFiles.php +++ b/app/Console/Commands/CleanupTempFiles.php @@ -21,23 +21,26 @@ class CleanupTempFiles extends Command */ protected $description = 'Delete temporary files that are older that 1 day'; + /** * Execute the console command. + * + * @return void */ - public function handle() + public function handle(): void { - $keepTime = 1 * 24 * 60 * 60; // 1 Day + $keepTime = (1 * 24 * 60 * 60); // 1 Day $currentTimeStamp = time(); $deletedFileCount = 0; foreach (glob(storage_path('app/tmp/*')) as $filename) { $fileModifiedTimeStamp = filemtime($filename); - if($currentTimeStamp - $fileModifiedTimeStamp > $keepTime) { + if (($currentTimeStamp - $fileModifiedTimeStamp) > $keepTime) { unlink($filename); $deletedFileCount++; } } - + $this->comment('Deleted ' . $deletedFileCount . ' files'); } } diff --git a/app/Console/Commands/RemoveStaleMediaJobs.php b/app/Console/Commands/RemoveStaleMediaJobs.php index a0c2e32..48aee29 100644 --- a/app/Console/Commands/RemoveStaleMediaJobs.php +++ b/app/Console/Commands/RemoveStaleMediaJobs.php @@ -21,10 +21,13 @@ class RemoveStaleMediaJobs extends Command */ protected $description = 'Remove media_jobs that have not been modified for 48 hours'; + /** * Execute the console command. + * + * @return void */ - public function handle() + public function handle(): void { $threshold = now()->subHours(48); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0e4e8c1..61d0d1a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,6 +11,7 @@ class Kernel extends ConsoleKernel * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule The schedule. + * @return void */ protected function schedule(Schedule $schedule): void { @@ -21,6 +22,8 @@ class Kernel extends ConsoleKernel /** * Register the commands for the application. + * + * @return void */ protected function commands(): void { diff --git a/app/Enum/Enum.php b/app/Enum/Enum.php index 5596e01..9217845 100644 --- a/app/Enum/Enum.php +++ b/app/Enum/Enum.php @@ -58,6 +58,8 @@ class Enum /** * Returns a message from the enum subclass * + * @param integer $messageIndex The message index to retrieve. + * @param string $defaultMessage Message to use if index does not exist. * @return string */ public static function getMessage(int $messageIndex, string $defaultMessage = 'Unknown'): string diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 8e5b394..74672f9 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,14 +2,11 @@ namespace App\Exceptions; -use App\Mail\ExceptionMail; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; use PDOException; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; -use Exception; -use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; @@ -31,6 +28,8 @@ class Handler extends ExceptionHandler /** * Register the exception handling callbacks for the application. + * + * @return void */ public function register(): void { @@ -65,14 +64,19 @@ class Handler extends ExceptionHandler $this->reportable(function (Throwable $e) { if ($this->shouldReport($e) === true) { - if(App::runningUnitTests() === false) { + if (App::runningUnitTests() === false) { $this->sendEmail($e); } } }); } - + /** + * Send email + * + * @param Throwable $exception Throwable object. + * @return void + */ public function sendEmail(Throwable $exception) { try { diff --git a/app/Helpers/Array.php b/app/Helpers/Array.php index d56b794..76e0103 100644 --- a/app/Helpers/Array.php +++ b/app/Helpers/Array.php @@ -58,10 +58,10 @@ function arrayDefaultValue(string $key, array $arr, mixed $value): mixed /** * Return if an item exists in an array, case insensitive - * + * * @param string $val The value to check. * @param array $arr The array to check. - * @return bool + * @return boolean */ function existsInArray(string $val, array $arr): bool { @@ -75,4 +75,4 @@ function existsInArray(string $val, array $arr): bool } return $exists; -} \ No newline at end of file +} diff --git a/app/Helpers/Temp.php b/app/Helpers/Temp.php index 111e438..86e48d5 100644 --- a/app/Helpers/Temp.php +++ b/app/Helpers/Temp.php @@ -2,7 +2,6 @@ /* Temp File Helper Functions */ -use Illuminate\Support\Facades\Log; /** * Generate a temporary file path. @@ -18,7 +17,8 @@ function generateTempFilePath(string $extension = '', string $part = ''): string mkdir($temporaryDir, 0777, true); } - return $temporaryDir . DIRECTORY_SEPARATOR . uniqid('upload_', true) . ($extension !== '' ? ".{$extension}" : '') . ($part !== '' ? ".part-{$part}" : ''); + return $temporaryDir . DIRECTORY_SEPARATOR . uniqid('upload_', true) . ($extension !== '' ? ".{$extension}" : '') . + ($part !== '' ? ".part-{$part}" : ''); } /** @@ -32,7 +32,7 @@ function tempFileInfo(string $filePath): array $part = ''; // Extract the part if it's present - if (preg_match('/\.part-(\d+)$/', $filePath, $matches)) { + if (preg_match('/\.part-(\d+)$/', $filePath, $matches) !== false) { $part = $matches[1]; $filePath = substr($filePath, 0, -strlen($matches[0])); } @@ -44,7 +44,7 @@ function tempFileInfo(string $filePath): array $extension = ''; // If there's an extension, separate it - if (isset($info['extension'])) { + if (isset($info['extension']) === true) { $extension = $info['extension']; } @@ -64,13 +64,13 @@ function tempFileInfo(string $filePath): array * @param string $name The file name. * @param string $extension The file extension to use. * @param string $part The file part number. - * @return bool If the file exists. + * @return boolean If the file exists. */ function tempFileExists(string $dir, string $name, string $extension = '', string $part = ''): bool { $filename = constructTempFileName($dir, $name, $extension, $part); $exists = file_exists($filename); - + return $exists; } @@ -85,7 +85,8 @@ function tempFileExists(string $dir, string $name, string $extension = '', strin */ function constructTempFileName(string $dir, string $name, string $extension = '', string $part = ''): string { - $filename = $dir . DIRECTORY_SEPARATOR . $name . ($extension !== '' ? ".{$extension}" : '') . ($part !== "" ? ".part-{$part}" : ''); + $filename = $dir . DIRECTORY_SEPARATOR . $name . ($extension !== '' ? ".{$extension}" : '') . + ($part !== "" ? ".part-{$part}" : ''); return $filename; } diff --git a/app/Http/Controllers/Api/AnalyticsController.php b/app/Http/Controllers/Api/AnalyticsController.php index f78413b..003b50e 100644 --- a/app/Http/Controllers/Api/AnalyticsController.php +++ b/app/Http/Controllers/Api/AnalyticsController.php @@ -99,7 +99,11 @@ class AnalyticsController extends ApiController 'ip' => $request->ip() ]; - if ($user !== null && $user->hasPermission('admin/analytics') === true && $request->has('session') === true) { + if ( + $user !== null && + $user->hasPermission('admin/analytics') === true && + $request->has('session') === true + ) { $data['session_id'] = $request->input('session_id'); $analytics = AnalyticsItemRequest::create($data); } else { diff --git a/app/Http/Controllers/Api/AttachmentController.php b/app/Http/Controllers/Api/AttachmentController.php deleted file mode 100644 index 6586734..0000000 --- a/app/Http/Controllers/Api/AttachmentController.php +++ /dev/null @@ -1,84 +0,0 @@ -middleware('auth:sanctum') - ->except(['store', 'destroyByEmail']); - } - - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() - { - // - } - - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) - { - // - } - - /** - * Display the specified resource. - * - * @param \App\Models\Attachment $attachment - * @return \Illuminate\Http\Response - */ - public function show(Attachment $attachment) - { - // - } - - /** - * Show the form for editing the specified resource. - * - * @param \App\Models\Attachment $attachment - * @return \Illuminate\Http\Response - */ - public function edit(Attachment $attachment) - { - // - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param \App\Models\Attachment $attachment - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Attachment $attachment) - { - // - } - - /** - * Remove the specified resource from storage. - * - * @param \App\Models\Attachment $attachment - * @return \Illuminate\Http\Response - */ - public function destroy(Attachment $attachment) - { - // - } -} diff --git a/app/Http/Controllers/Api/AuthController.php b/app/Http/Controllers/Api/AuthController.php index 3fab72d..0fe1851 100644 --- a/app/Http/Controllers/Api/AuthController.php +++ b/app/Http/Controllers/Api/AuthController.php @@ -31,6 +31,7 @@ class AuthController extends ApiController * Current User details * * @param Request $request Current request data. + * @return JsonResponse */ public function me(Request $request): JsonResponse { @@ -48,7 +49,11 @@ class AuthController extends ApiController { $user = User::where('email', '=', $request->input('email'))->first(); - if ($user !== null && strlen($user->password) > 0 && Hash::check($request->input('password'), $user->password) === true) { + if ( + $user !== null && + strlen($user->password) > 0 && + Hash::check($request->input('password'), $user->password) === true + ) { if ($user->email_verified_at === null) { return $this->respondWithErrors([ 'email' => 'Email address has not been verified.' @@ -86,6 +91,7 @@ class AuthController extends ApiController * Logout current user * * @param Request $request Current request data. + * @return JsonResponse */ public function logout(Request $request): JsonResponse { diff --git a/app/Http/Controllers/Api/EventController.php b/app/Http/Controllers/Api/EventController.php index 34644be..31b562c 100644 --- a/app/Http/Controllers/Api/EventController.php +++ b/app/Http/Controllers/Api/EventController.php @@ -10,8 +10,10 @@ use App\Conductors\UserConductor; use App\Http\Requests\EventRequest; use App\Models\Media; use App\Models\User; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; class EventController extends ApiController { @@ -120,7 +122,13 @@ class EventController extends ApiController } } - public function userList(Request $request, Event $event) + /** + * List users of Event + * @param Request $request The HTTP request. + * @param Event $event Event model. + * @return JsonResponse + */ + public function userList(Request $request, Event $event): JsonResponse { $authUser = $request->user(); $eventUsers = $event->users; @@ -136,16 +144,28 @@ class EventController extends ApiController }); } - return $this->respondAsResource(UserConductor::collection($request, $eventUsers), ['isCollection' => true, 'resourceName' => 'users']); + return $this->respondAsResource( + UserConductor::collection($request, $eventUsers), + [ + 'isCollection' => true, + 'resourceName' => 'users' + ] + ); } return $this->respondNotFound(); - } + }//end if return $this->respondForbidden(); } - public function userAdd(Request $request, Event $event) + /** + * Add user to Event + * @param Request $request The HTTP request. + * @param Event $event Event model. + * @return JsonResponse + */ + public function userAdd(Request $request, Event $event): JsonResponse { $authUser = $request->user(); if ($authUser !== null && $authUser->hasPermission('admin/events') === true) { @@ -177,12 +197,26 @@ class EventController extends ApiController return $this->respondForbidden(); } - public function userUpdate(Request $request, Event $event) + /** + * Update user + * @param Request $request The HTTP request. + * @param Event $event Event model. + * @return void + */ + public function userUpdate(Request $request, Event $event): void { // only admin/events permitted } - public function userDelete(Request $request, Event $event, User $user) + /** + * Delete user from event + * + * @param Request $request The HTTP request. + * @param Event $event Event model. + * @param User $user User model. + * @return JsonResponse + */ + public function userDelete(Request $request, Event $event, User $user): JsonResponse { $authUser = $request->user(); if ($authUser !== null && $authUser->hasPermission('admin/events') === true) { diff --git a/app/Http/Controllers/Api/LogController.php b/app/Http/Controllers/Api/LogController.php index f169ddd..c81c802 100644 --- a/app/Http/Controllers/Api/LogController.php +++ b/app/Http/Controllers/Api/LogController.php @@ -45,7 +45,12 @@ class LogController extends ApiController $before = $request->get('before'); if ($before !== null) { - $before = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $before, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $before = preg_split( + "/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", + $before, + -1, + (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) + ); if (count($before) !== 6) { $before = null; } @@ -53,7 +58,12 @@ class LogController extends ApiController $after = $request->get('after'); if ($after !== null) { - $after = preg_split("/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", $after, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $after = preg_split( + "/([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/", + $after, + -1, + (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) + ); if (count($after) !== 6) { $after = null; } @@ -77,30 +87,59 @@ class LogController extends ApiController $logContent = file_get_contents($logFile['path']); } - $logArray = preg_split("/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", $logContent, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $logArray = preg_split( + // phpcs:ignore Generic.Files.LineLength.TooLong + "/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: (?:(?!\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}: )[\s\S])*)/", + $logContent, + -1, + (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) + ); $logContent = ''; $logLineCount = 0; $logLineSkip = false; foreach (array_reverse($logArray) as $logLine) { - $lineDate = preg_split("/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}): /", $logLine, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); + $lineDate = preg_split( + "/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}): /", + $logLine, + -1, + (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) + ); if (count($lineDate) >= 6) { $logLineSkip = false; // Is line before - if ($before !== null && ($lineDate[0] > $before[0] || $lineDate[1] > $before[1] || $lineDate[2] > $before[2] || $lineDate[3] > $before[3] || $lineDate[4] > $before[4] || $lineDate[5] > $before[5])) { + if ( + $before !== null && ( + $lineDate[0] > $before[0] || + $lineDate[1] > $before[1] || + $lineDate[2] > $before[2] || + $lineDate[3] > $before[3] || + $lineDate[4] > $before[4] || + $lineDate[5] > $before[5] + ) + ) { $logLineSkip = true; continue; } // Is line after - if ($after !== null && ($after[0] > $lineDate[0] || $after[1] > $lineDate[1] || $after[2] > $lineDate[2] || $after[3] > $lineDate[3] || $after[4] > $lineDate[4] || $after[5] > $lineDate[5])) { + if ( + $after !== null && ( + $after[0] > $lineDate[0] || + $after[1] > $lineDate[1] || + $after[2] > $lineDate[2] || + $after[3] > $lineDate[3] || + $after[4] > $lineDate[4] || + $after[5] > $lineDate[5] + ) + ) { $logLineSkip = true; continue; } $logLineCount += 1; - } + }//end if if ($logLineCount > $lines) { break; diff --git a/app/Http/Controllers/Api/MediaController.php b/app/Http/Controllers/Api/MediaController.php index c6ffce8..7e6b87c 100644 --- a/app/Http/Controllers/Api/MediaController.php +++ b/app/Http/Controllers/Api/MediaController.php @@ -10,6 +10,7 @@ use App\Models\Media; use App\Models\MediaJob; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Http\UploadedFile; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; @@ -123,7 +124,9 @@ class MediaController extends ApiController case UPLOAD_ERR_PARTIAL: return $this->respondWithErrors([$file => 'The file upload was interrupted.']); default: - return $this->respondWithErrors([$file => 'An error occurred uploading the file to the server.']); + return $this->respondWithErrors( + [$file => 'An error occurred uploading the file to the server.'] + ); } } @@ -151,12 +154,16 @@ class MediaController extends ApiController } if ($request->has('name') === true || $file !== null) { - $data['name'] = $request->has('chunk') === true ? $request->get('name', '') : $file->getClientOriginalName(); + $data['name'] = ( + $request->has('chunk') === true ? $request->get('name', '') : $file->getClientOriginalName() + ); } if ($file !== null) { $data['size'] = $request->has('chunk') === true ? intval($request->get('size', 0)) : $file->getSize(); - $data['mime_type'] = $request->has('chunk') === true ? $request->get('mime_type', '') : $file->getMimeType(); + $data['mime_type'] = ( + $request->has('chunk') === true ? $request->get('mime_type', '') : $file->getMimeType() + ); } if ($request->has('storage') === true || $file !== null) { @@ -167,36 +174,42 @@ class MediaController extends ApiController $data['security']['type'] = $request->get('security_type', ''); $data['security']['data'] = $request->get('security_data', ''); - if($data['security']['type'] === '') { + if ($data['security']['type'] === '') { $data['security']['data'] = ''; } - if($medium === null || strcasecmp($data['security']['type'], $medium->security_type) !== 0) { - if($request->has('storage') === false) { + if ($medium === null || strcasecmp($data['security']['type'], $medium->security_type) !== 0) { + if ($request->has('storage') === false) { $mime_type = $request->get('mime_type', $medium === null ? '' : $medium->mime_type); $data['storage'] = Media::recommendedStorage($mime_type, $data['security']['type']); } } } - if(array_key_exists('storage', $data) === true && - (array_key_exists('security', $data) === true && array_key_exists('type', $data['security']) === true) && - array_key_exists('mime_type', $data) === true && - $data['mime_type'] !== "") { + if ( + array_key_exists('storage', $data) === true && ( + array_key_exists('security', $data) === true && + array_key_exists('type', $data['security']) === true + ) && + array_key_exists('mime_type', $data) === true && + $data['mime_type'] !== "" + ) { $error = Media::verifyStorage($data['mime_type'], $data['security']['type'], $data['storage']); // Log::error($data['mime_type'] . ' - ' . $data['security']['type'] . ' - ' . $data['storage']); - switch($error) { - case Media::STORAGE_VALID: - break; - case Media::STORAGE_MIME_MISSING: - return $this->respondWithErrors(['mime_type' => 'The file type is required.']); - case Media::STORAGE_NOT_FOUND: - return $this->respondWithErrors(['storage' => 'Storage was not found.']); - case Media::STORAGE_INVALID_SECURITY: - return $this->respondWithErrors(['storage' => 'Storage invalid for this security requirement.']); - default: - return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']); - } + switch ($error) { + case Media::STORAGE_VALID: + break; + case Media::STORAGE_MIME_MISSING: + return $this->respondWithErrors(['mime_type' => 'The file type is required.']); + case Media::STORAGE_NOT_FOUND: + return $this->respondWithErrors(['storage' => 'Storage was not found.']); + case Media::STORAGE_INVALID_SECURITY: + return $this->respondWithErrors( + ['storage' => 'Storage invalid for this security requirement.'] + ); + default: + return $this->respondWithErrors(['storage' => 'Storage verification error occurred.']); + } } if ($request->has('transform') === true) { @@ -211,7 +224,12 @@ class MediaController extends ApiController } elseif (preg_match('/^crop-(\d+)-(\d+)$/', $value, $matches) !== false) { $transform['crop'] = ['width' => $matches[1], 'height' => $matches[2]]; } elseif (preg_match('/^crop-(\d+)-(\d+)-(\d+)-(\d+)$/', $value, $matches) !== false) { - $transform['crop'] = ['width' => $matches[1], 'height' => $matches[2], 'x' => $matches[3], 'y' => $matches[4]]; + $transform['crop'] = [ + 'width' => $matches[1], + 'height' => $matches[2], + 'x' => $matches[3], + 'y' => $matches[4] + ]; } } } @@ -252,7 +270,10 @@ class MediaController extends ApiController return $this->respondServerError(); } - $temporaryFilePath = generateTempFilePath(pathinfo($data['name'], PATHINFO_EXTENSION), $request->get('chunk', '')); + $temporaryFilePath = generateTempFilePath( + pathinfo($data['name'], PATHINFO_EXTENSION), + $request->get('chunk', '') + ); copy($file->path(), $temporaryFilePath); if ($request->has('chunk') === true) { @@ -293,18 +314,18 @@ class MediaController extends ApiController * Display the specified resource. * * @param \Illuminate\Http\Request $request The endpoint request. - * @param \App\Models\Media $medium Specified media. + * @param \App\Models\Media $media Specified media. * @return \Illuminate\Http\Response */ - public function download(Request $request, Media $media) + public function download(Request $request, Media $media): Response { $headers = []; - + /* Check file exists */ - if(Storage::disk($media->storage)->exists($media->name) === false) { + if (Storage::disk($media->storage)->exists($media->name) === false) { return $this->respondNotFound(); } - + $updated_at = Carbon::parse(Storage::disk($media->storage)->lastModified($media->name)); $headerPragma = 'no-cache'; @@ -328,17 +349,22 @@ class MediaController extends ApiController /* no security */ $headerPragma = 'public'; $headerExpires = $updated_at->addMonth()->toRfc2822String(); - } else if (strcasecmp('password', $media->security_type) === 0) { + } elseif (strcasecmp('password', $media->security_type) === 0) { /* password */ - if( - ($user === null || $user->hasPermission('admin/media') === false) && - ($request->has('password') === false || $request->get('password') !== $media->security_data)) { + if ( + ($user === null || $user->hasPermission('admin/media') === false) && + ($request->has('password') === false || $request->get('password') !== $media->security_data) + ) { return $this->respondForbidden(); } - } else if (strcasecmp('permission', $media->security_type) === 0) { + } elseif (strcasecmp('permission', $media->security_type) === 0) { /* permission */ - if( - $user === null || ($user->hasPermission('admin/media') === false && $user->hasPermission($media->security_data) === false)) { + if ( + $user === null || ( + $user->hasPermission('admin/media') === false && + $user->hasPermission($media->security_data) === false + ) + ) { return $this->respondForbidden(); } }//end if @@ -374,10 +400,12 @@ class MediaController extends ApiController $stream = Storage::disk($media->storage)->readStream($media->name); return response()->stream( - function() use($stream) { - while(ob_get_level() > 0) ob_end_flush(); + function () use ($stream) { + while (ob_get_level() > 0) { + ob_end_flush(); + } fpassthru($stream); - }, + }, 200, $headers ); @@ -400,7 +428,9 @@ class MediaController extends ApiController case UPLOAD_ERR_PARTIAL: return $this->respondWithErrors([$errorKey => 'The file upload was interrupted.']); default: - return $this->respondWithErrors([$errorKey => 'An error occurred uploading the file to the server.']); + return $this->respondWithErrors( + [$errorKey => 'An error occurred uploading the file to the server.'] + ); } } diff --git a/app/Http/Controllers/Api/MediaJobController.php b/app/Http/Controllers/Api/MediaJobController.php index 926aca0..daa1c22 100644 --- a/app/Http/Controllers/Api/MediaJobController.php +++ b/app/Http/Controllers/Api/MediaJobController.php @@ -41,7 +41,10 @@ class MediaJobController extends ApiController public function show(Request $request, MediaJob $mediaJob) { if (MediaJobConductor::viewable($mediaJob) === true) { - return $this->respondAsResource(MediaJobConductor::model($request, $mediaJob), ['resourceName' => 'media_job']); + return $this->respondAsResource( + MediaJobConductor::model($request, $mediaJob), + ['resourceName' => 'media_job'] + ); } return $this->respondForbidden(); diff --git a/app/Http/Controllers/Api/OCRController.php b/app/Http/Controllers/Api/OCRController.php index 045f18d..7c2cce5 100644 --- a/app/Http/Controllers/Api/OCRController.php +++ b/app/Http/Controllers/Api/OCRController.php @@ -101,7 +101,10 @@ class OCRController extends ApiController $tesseractImageFilterFunc = function ($filter, $options = null) use ($curlResult, $curlSize, $ocr) { $result = ''; $img = imagecreatefromstring($curlResult); - if ($img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || ($options === null && imagefilter($img, $filter) === true))) { + if ( + $img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || + ($options === null && imagefilter($img, $filter) === true)) + ) { ob_start(); imagepng($img); $imgData = ob_get_contents(); diff --git a/app/Http/Controllers/Api/ShortlinkController.php b/app/Http/Controllers/Api/ShortlinkController.php index 6cbc898..a8d1c23 100644 --- a/app/Http/Controllers/Api/ShortlinkController.php +++ b/app/Http/Controllers/Api/ShortlinkController.php @@ -2,17 +2,11 @@ namespace App\Http\Controllers\Api; -use App\Conductors\MediaConductor; use App\Conductors\ShortlinkConductor; use App\Enum\HttpResponseCodes; -use App\Http\Requests\MediaRequest; use App\Http\Requests\ShortlinkRequest; -use App\Models\Media; use App\Models\Shortlink; use Illuminate\Http\Request; -use Illuminate\Support\Carbon; -use Illuminate\Support\Facades\Log; -use Laravel\Sanctum\PersonalAccessToken; class ShortlinkController extends ApiController { @@ -85,8 +79,8 @@ class ShortlinkController extends ApiController /** * Update the media resource in storage. * - * @param \App\Http\Requests\ShortlinkRequest $request The update request. - * @param \App\Models\Shortlink $medium The specified shortlink. + * @param \App\Http\Requests\ShortlinkRequest $request The update request. + * @param \App\Models\Shortlink $shortlink The specified shortlink. * @return \Illuminate\Http\Response */ public function update(ShortlinkRequest $request, Shortlink $shortlink) @@ -102,7 +96,7 @@ class ShortlinkController extends ApiController /** * Remove the specified resource from storage. * - * @param \App\Models\Shortlink $medium Specified shortlink. + * @param \App\Models\Shortlink $shortlink Specified shortlink. * @return \Illuminate\Http\Response */ public function destroy(Shortlink $shortlink) diff --git a/app/Http/Controllers/Api/SubscriptionController.php b/app/Http/Controllers/Api/SubscriptionController.php deleted file mode 100644 index 4ff80c6..0000000 --- a/app/Http/Controllers/Api/SubscriptionController.php +++ /dev/null @@ -1,146 +0,0 @@ -middleware('auth:sanctum') - ->except(['store', 'destroyByEmail']); - } - - /** - * Display a listing of subscribers. - * - * @param \Illuminate\Http\Request $request The endpoint request. - * @return \Illuminate\Http\Response - */ - public function index(Request $request) - { - list($collection, $total) = SubscriptionConductor::request($request); - - return $this->respondAsResource( - $collection, - ['isCollection' => true, - 'appendData' => ['total' => $total] - ] - ); - } - - /** - * Display the specified user. - * - * @param \Illuminate\Http\Request $request The endpoint request. - * @param \App\Models\Subscription $subscription The subscription model. - * @return \Illuminate\Http\Response - */ - public function show(Request $request, Subscription $subscription) - { - if (SubscriptionConductor::viewable($subscription) === true) { - return $this->respondAsResource(SubscriptionConductor::model($request, $subscription)); - } - - return $this->respondForbidden(); - } - - /** - * Store a subscriber email in the database. - * - * @param \App\Http\Requests\SubscriptionRequest $request The subscriber update request. - * @return \Illuminate\Http\Response - */ - public function store(SubscriptionRequest $request) - { - if (SubscriptionConductor::creatable() === true) { - Subscription::create($request->all()); - dispatch((new SendEmailJob($request->email, new SubscriptionConfirm($request->email))))->onQueue('mail'); - - return $this->respondCreated(); - } else { - return $this->respondForbidden(); - } - } - - /** - * Update the specified resource in storage. - * - * @param \App\Http\Requests\SubscriptionRequest $request The subscription update request. - * @param \App\Models\Subscription $subscription The specified subscription. - * @return \Illuminate\Http\Response - */ - public function update(SubscriptionRequest $request, Subscription $subscription) - { - // if (EventConductor::updatable($event) === true) { - // $event->update($request->all()); - // return $this->respondAsResource(EventConductor::model($request, $event)); - // } - - // return $this->respondForbidden(); - - - // $input = []; - // $updatable = ['username', 'first_name', 'last_name', 'email', 'phone', 'password']; - - // if ($request->user()->hasPermission('admin/user') === true) { - // $updatable = array_merge($updatable, ['email_verified_at']); - // } elseif ($request->user()->is($user) !== true) { - // return $this->respondForbidden(); - // } - - // $input = $request->only($updatable); - // if (array_key_exists('password', $input) === true) { - // $input['password'] = Hash::make($request->input('password')); - // } - - // $user->update($input); - - // return $this->respondAsResource((new UserFilter($request))->filter($user)); - } - - - /** - * Remove the user from the database. - * - * @param Subscription $subscription The specified subscription. - * @return \Illuminate\Http\Response - */ - public function destroy(Subscription $subscription) - { - if (SubscriptionConductor::destroyable($subscription) === true) { - $subscription->delete(); - return $this->respondNoContent(); - } else { - return $this->respondForbidden(); - } - } - - /** - * Remove the user from the database. - * - * @param SubscriptionRequest $request The specified subscription. - * @return \Illuminate\Http\Response - */ - public function destroyByEmail(SubscriptionRequest $request) - { - $subscription = Subscription::where('email', $request->email)->first(); - if ($subscription !== null) { - $subscription->delete(); - dispatch((new SendEmailJob($request->email, new SubscriptionUnsubscribed($request->email))))->onQueue('mail'); - } - - return $this->respondNoContent(); - } -} diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 052ae26..3cea08a 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -73,7 +73,10 @@ class UserController extends ApiController { if (UserConductor::creatable() === true) { $user = User::create($request->all()); - return $this->respondAsResource(UserConductor::model($request, $user), ['respondCode' => HttpResponseCodes::HTTP_CREATED]); + return $this->respondAsResource( + UserConductor::model($request, $user), + ['respondCode' => HttpResponseCodes::HTTP_CREATED] + ); } else { return $this->respondForbidden(); } @@ -145,6 +148,7 @@ class UserController extends ApiController * Register a new user * * @param \App\Http\Requests\UserRegisterRequest $request The register user request. + * @return JsonResponse */ public function register(UserRegisterRequest $request): JsonResponse { @@ -285,6 +289,7 @@ class UserController extends ApiController * Resend a new verify email * * @param \App\Http\Requests\UserResendVerifyEmailRequest $request The resend verify email request. + * @return JsonResponse */ public function resendVerifyEmail(UserResendVerifyEmailRequest $request): JsonResponse { @@ -338,10 +343,15 @@ class UserController extends ApiController * * @param Request $request The http request. * @param User $user The specified user. + * @return JsonResponse */ public function eventList(Request $request, User $user): JsonResponse { - if ($request->user() !== null && ($request->user() === $user || $request->user()->hasPermission('admin/events') === true)) { + if ( + $request->user() !== null && ( + $request->user() === $user || $request->user()->hasPermission('admin/events') === true + ) + ) { $collection = $user->events; $total = $collection->count(); diff --git a/app/Http/Middleware/LogRequest.php b/app/Http/Middleware/LogRequest.php index b10c4c7..07e984c 100644 --- a/app/Http/Middleware/LogRequest.php +++ b/app/Http/Middleware/LogRequest.php @@ -12,8 +12,8 @@ class LogRequest /** * Handle an incoming request. * - * @param Illuminate\Http\Request $request HTTP Request. - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next Closure. + * @param Illuminate\Http\Request $request HTTP Request. + * @param \Closure $next Closure. * @return Symfony\Component\HttpFoundation\Response */ public function handle(Request $request, Closure $next): Response diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index ddefde7..5ee6f4b 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -13,9 +13,10 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param Request $request Request. - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next - * @param string|null ...$guards Guards. + * @param Request $request Request. + * @param \Closure $next Closure. + * @param string|null ...$guards Guards. + * @return Response */ public function handle(Request $request, Closure $next, string ...$guards): Response { diff --git a/app/Http/Middleware/UnmangleRequest.php b/app/Http/Middleware/UnmangleRequest.php index 5d5adf6..a903651 100644 --- a/app/Http/Middleware/UnmangleRequest.php +++ b/app/Http/Middleware/UnmangleRequest.php @@ -13,9 +13,9 @@ class UnmangleRequest /** * Handle an incoming request. * - * @param Request $request Request. - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next Next. - * @param string|null ...$guards Guards. + * @param Request $request Request. + * @param \Closure $next Next. + * @param string|null ...$guards Guards. * @return Response response. */ public function handle(Request $request, Closure $next, string ...$guards): Response diff --git a/app/Http/Middleware/UseSanctumGuard.php b/app/Http/Middleware/UseSanctumGuard.php index f7abf14..24a6c21 100644 --- a/app/Http/Middleware/UseSanctumGuard.php +++ b/app/Http/Middleware/UseSanctumGuard.php @@ -12,7 +12,9 @@ class UseSanctumGuard /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @param Request $request Request object. + * @param \Closure $next Closure object. + * @return Response */ public function handle(Request $request, Closure $next): Response { diff --git a/app/Http/Requests/BaseRequest.php b/app/Http/Requests/BaseRequest.php index be6c197..ac1e009 100644 --- a/app/Http/Requests/BaseRequest.php +++ b/app/Http/Requests/BaseRequest.php @@ -9,12 +9,18 @@ class BaseRequest extends FormRequest { /** * Determine if the user is authorized to make this request. + * + * @return boolean */ public function authorize(): bool { if (request()->isMethod('post') === true && method_exists($this, 'postAuthorize') === true) { return $this->postAuthorize(); - } elseif ((request()->isMethod('put') === true || request()->isMethod('patch') === true) && method_exists($this, 'putAuthorize') === true) { + } elseif ( + ( + request()->isMethod('put') === true || request()->isMethod('patch') === true + ) && method_exists($this, 'putAuthorize') === true + ) { return $this->putAuthorize(); } elseif (request()->isMethod('delete') === true && method_exists($this, 'destroyAuthorize') === true) { return $this->deleteAuthorize(); @@ -38,7 +44,11 @@ class BaseRequest extends FormRequest if (method_exists($this, 'postRules') === true && request()->isMethod('post') === true) { $rules = $this->mergeRules($rules, $this->postRules()); - } elseif (method_exists($this, 'putRules') === true && (request()->isMethod('put') === true || request()->isMethod('patch') === true)) { + } elseif ( + method_exists($this, 'putRules') === true && ( + request()->isMethod('put') === true || request()->isMethod('patch') === true + ) + ) { $rules = $this->mergeRules($rules, $this->putRules()); } elseif (method_exists($this, 'destroyRules') === true && request()->isMethod('delete') === true) { $rules = $this->mergeRules($rules, $this->destroyRules()); @@ -52,6 +62,7 @@ class BaseRequest extends FormRequest * * @param array $collection1 The first collection of rules. * @param array $collection2 The second collection of rules to merge. + * @return array */ private function mergeRules(array $collection1, array $collection2): array { diff --git a/app/Http/Requests/MediaRequest.php b/app/Http/Requests/MediaRequest.php index d7120cf..5becd25 100644 --- a/app/Http/Requests/MediaRequest.php +++ b/app/Http/Requests/MediaRequest.php @@ -6,6 +6,11 @@ use Illuminate\Validation\Rule; class MediaRequest extends BaseRequest { + /** + * POST request rules + * + * @return array + */ public function postRules(): array { return [ diff --git a/app/Http/Requests/SubscriptionRequest.php b/app/Http/Requests/SubscriptionRequest.php index 387c14a..7395fe8 100644 --- a/app/Http/Requests/SubscriptionRequest.php +++ b/app/Http/Requests/SubscriptionRequest.php @@ -34,6 +34,8 @@ class SubscriptionRequest extends BaseRequest /** * Get the custom error messages. + * + * @return array */ public function messages(): array { diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php index 95e32f0..bcaf651 100644 --- a/app/Http/Requests/UserRequest.php +++ b/app/Http/Requests/UserRequest.php @@ -21,8 +21,12 @@ class UserRequest extends BaseRequest $isAdminUser = $user->hasPermission('admin/users'); return [ - 'first_name' => ($isAdminUser === true ? 'required_with:last_name,display_name,phone' : 'required') . '|string|max:255|min:2', - 'last_name' => ($isAdminUser === true ? 'required_with:first_name,display_name,phone' : 'required') . '|string|max:255|min:2', + 'first_name' => ( + $isAdminUser === true ? 'required_with:last_name,display_name,phone' : 'required' + ) . '|string|max:255|min:2', + 'last_name' => ( + $isAdminUser === true ? 'required_with:first_name,display_name,phone' : 'required' + ) . '|string|max:255|min:2', 'display_name' => [ $isAdminUser === true ? 'required_with:first_name,last_name,phone' : 'required', 'string', diff --git a/app/Jobs/MediaWorkerJob.php b/app/Jobs/MediaWorkerJob.php index af5d150..69e1c8a 100644 --- a/app/Jobs/MediaWorkerJob.php +++ b/app/Jobs/MediaWorkerJob.php @@ -107,7 +107,7 @@ class MediaWorkerJob implements ShouldQueue } if ($storage === '') { - if(count($security) === 0 || $security['type'] === '') { + if (count($security) === 0 || $security['type'] === '') { if (strpos($data['mime_type'], 'image/') === 0) { $storage = 'local'; } else { @@ -126,7 +126,7 @@ class MediaWorkerJob implements ShouldQueue } } - if($exists === true) { + if ($exists === true) { $pathInfo = pathinfo($data['name']); $basename = $pathInfo['filename']; $extension = $pathInfo['extension']; @@ -302,7 +302,7 @@ class MediaWorkerJob implements ShouldQueue $media->security_type = $data['security']['type']; $media->security_data = $data['security']['data']; } - + if (array_key_exists('storage', $data) === true) { if ($media->storage !== $data['storage']) { $media->createStagingFile(); diff --git a/app/Jobs/SendEmailJob.php b/app/Jobs/SendEmailJob.php index dcbe010..89d7d1f 100644 --- a/app/Jobs/SendEmailJob.php +++ b/app/Jobs/SendEmailJob.php @@ -47,6 +47,8 @@ class SendEmailJob implements ShouldQueue /** * Execute the job. + * + * @return void */ public function handle(): void { diff --git a/app/Mail/ChangeEmailVerify.php b/app/Mail/ChangeEmailVerify.php index 0365ee5..dc7618f 100644 --- a/app/Mail/ChangeEmailVerify.php +++ b/app/Mail/ChangeEmailVerify.php @@ -54,6 +54,8 @@ class ChangeEmailVerify extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -64,6 +66,8 @@ class ChangeEmailVerify extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/ChangedEmail.php b/app/Mail/ChangedEmail.php index 71dbe36..ded99d1 100644 --- a/app/Mail/ChangedEmail.php +++ b/app/Mail/ChangedEmail.php @@ -54,6 +54,8 @@ class ChangedEmail extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -64,6 +66,8 @@ class ChangedEmail extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/ChangedPassword.php b/app/Mail/ChangedPassword.php index 00451c9..ecc62c2 100644 --- a/app/Mail/ChangedPassword.php +++ b/app/Mail/ChangedPassword.php @@ -36,6 +36,8 @@ class ChangedPassword extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -46,6 +48,8 @@ class ChangedPassword extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/Contact.php b/app/Mail/Contact.php index cce5a36..db4924e 100644 --- a/app/Mail/Contact.php +++ b/app/Mail/Contact.php @@ -53,6 +53,8 @@ class Contact extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -63,6 +65,8 @@ class Contact extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/EmailVerify.php b/app/Mail/EmailVerify.php index e8b8097..4f23fd4 100644 --- a/app/Mail/EmailVerify.php +++ b/app/Mail/EmailVerify.php @@ -45,6 +45,8 @@ class EmailVerify extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -55,6 +57,8 @@ class EmailVerify extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/ExceptionMail.php b/app/Mail/ExceptionMail.php index 0dbf5c3..1728ee2 100644 --- a/app/Mail/ExceptionMail.php +++ b/app/Mail/ExceptionMail.php @@ -25,6 +25,8 @@ class ExceptionMail extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -35,6 +37,8 @@ class ExceptionMail extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/ForgotPassword.php b/app/Mail/ForgotPassword.php index 52f5370..f182c43 100644 --- a/app/Mail/ForgotPassword.php +++ b/app/Mail/ForgotPassword.php @@ -45,6 +45,8 @@ class ForgotPassword extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -55,6 +57,8 @@ class ForgotPassword extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/SubscriptionConfirm.php b/app/Mail/SubscriptionConfirm.php index 6a534ad..3eca6dd 100644 --- a/app/Mail/SubscriptionConfirm.php +++ b/app/Mail/SubscriptionConfirm.php @@ -36,6 +36,8 @@ class SubscriptionConfirm extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -46,6 +48,8 @@ class SubscriptionConfirm extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Mail/SubscriptionUnsubscribed.php b/app/Mail/SubscriptionUnsubscribed.php index bef9bb4..552c4a4 100644 --- a/app/Mail/SubscriptionUnsubscribed.php +++ b/app/Mail/SubscriptionUnsubscribed.php @@ -36,6 +36,8 @@ class SubscriptionUnsubscribed extends Mailable /** * Get the message envelope. + * + * @return Illuminate\Mail\Mailables\Envelope */ public function envelope(): Envelope { @@ -46,6 +48,8 @@ class SubscriptionUnsubscribed extends Mailable /** * Get the message content definition. + * + * @return Illuminate\Mail\Mailables\Content */ public function content(): Content { diff --git a/app/Models/EventUsers.php b/app/Models/EventUsers.php index 31a9d1f..5ba5daa 100644 --- a/app/Models/EventUsers.php +++ b/app/Models/EventUsers.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Traits\Uuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class EventUser extends Model { @@ -24,6 +25,8 @@ class EventUser extends Model /** * Get the event for this attachment. + * + * @return Illuminate\Database\Eloquent\Relations\BelongsTo */ public function event(): BelongsTo { @@ -32,6 +35,8 @@ class EventUser extends Model /** * Get the user for this attachment. + * + * @return Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user(): BelongsTo { diff --git a/app/Models/Media.php b/app/Models/Media.php index e951c4b..2bcb6e8 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -21,6 +21,8 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Intervention\Image\Facades\Image; +use Psr\Container\NotFoundExceptionInterface; +use Psr\Container\ContainerExceptionInterface; use SplFileInfo; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -155,8 +157,8 @@ class Media extends Model /** * Variants Get Mutator. * - * @param mixed $value The value to mutate. - * @param bool $raw Values are not run through urlencode. + * @param mixed $value The value to mutate. + * @param boolean $raw Values are not run through urlencode. * @return array|null The mutated value. */ public function getVariantsAttribute(mixed $value, bool $raw = false): array|null @@ -165,15 +167,15 @@ class Media extends Model $decodedValue = json_decode($value, true); // Check if the decoded value is an array - if ($raw == false && is_array($decodedValue)) { + if ($raw === false && is_array($decodedValue) === true) { // Loop through the array and encode each value foreach ($decodedValue as &$item) { - if (is_string($item)) { + if (is_string($item) === true) { $item = rawurlencode($item); } } } - + return $decodedValue; } @@ -278,7 +280,10 @@ class Media extends Model */ public function deleteFile(): void { - if (strlen($this->storage) > 0 && strlen($this->name) > 0 && Storage::disk($this->storage)->exists($this->name) === true) { + if ( + strlen($this->storage) > 0 && strlen($this->name) > 0 && + Storage::disk($this->storage)->exists($this->name) === true + ) { Storage::disk($this->storage)->delete($this->name); } @@ -322,19 +327,20 @@ class Media extends Model /** * Get URL path * + * @param array $replacements Replace variables in URL. * @return string */ public function getUrlPath(array $replacements = []): string { $url = config("filesystems.disks.$this->storage.url"); - - if (!empty($replacements)) { + + if (empty($replacements) !== true) { foreach ($replacements as $key => $value) { $placeholder = '{' . $key . '}'; $url = str_replace($placeholder, $value, $url); } } - + // Remove any remaining {x} placeholders $url = preg_replace('/\{[^}]+\}/', '', $url); @@ -992,12 +998,26 @@ class Media extends Model $this->save(); } - public function jobs(): HasMany { + /** + * Get the associated job models + * + * @return HasMany + */ + public function jobs(): HasMany + { return $this->hasMany(MediaJob::class, 'media_id'); } - public static function recommendedStorage(string $mime_type, string $security_type): string { - if($security_type === '') { + /** + * Get the recommended storage ID based on mime and security + * + * @param string $mime_type The file mime type. + * @param string $security_type The security requested. + * @return string + */ + public static function recommendedStorage(string $mime_type, string $security_type): string + { + if ($security_type === '') { if (strpos($mime_type, 'image/') === 0) { return('local'); } else { @@ -1008,9 +1028,18 @@ class Media extends Model return('private'); } - public static function verifyStorage($mime_type, $security_type, &$storage): int { - if($storage === '') { - if($security_type === '') { + /** + * Verify the storage exists. May change the storage value. + * + * @param mixed $mime_type File mime type. + * @param mixed $security_type Requested security type. + * @param mixed $storage Reference to the requested storage type. + * @return integer Error code. + */ + public static function verifyStorage(mixed $mime_type, mixed $security_type, mixed &$storage): int + { + if ($storage === '') { + if ($security_type === '') { if (strpos($mime_type, 'image/') === 0) { $storage = 'local'; } else { @@ -1021,11 +1050,11 @@ class Media extends Model } } else { $disks = config('filesystems.disks'); - if(array_key_exists($storage, $disks) === false) { + if (array_key_exists($storage, $disks) === false) { return Media::STORAGE_NOT_FOUND; } - if($security_type !== '' && strcasecmp($storage, 'private') !== 0) { + if ($security_type !== '' && strcasecmp($storage, 'private') !== 0) { return Media::STORAGE_INVALID_SECURITY; } } diff --git a/app/Models/MediaJob.php b/app/Models/MediaJob.php index 8edd02d..5ff16b0 100644 --- a/app/Models/MediaJob.php +++ b/app/Models/MediaJob.php @@ -102,9 +102,9 @@ class MediaJob extends Model /** * Set MediaJob status details. * - * @param string $status The status string. - * @param string $text The status text. - * @param integer $progress The status progress value. + * @param string $status The status string. + * @param string $text The status text. + * @param integer $progress The status progress value. * @param integer $progress_max The status progress maximum value. * @return void */ @@ -180,12 +180,14 @@ class MediaJob extends Model $data['size'] = filesize($newFile); $data['mime_type'] = $mime; - if(array_key_exists('storage', $data) === true && - array_key_exists('security_type', $data) === true && - array_key_exists('mime_type', $data) === true && - $data['mime_type'] !== "") { + if ( + array_key_exists('storage', $data) === true && + array_key_exists('security_type', $data) === true && + array_key_exists('mime_type', $data) === true && + $data['mime_type'] !== "" + ) { $error = Media::verifyStorage($data['mime_type'], $data['security_type'], $data['storage']); - switch($error) { + switch ($error) { case Media::STORAGE_VALID: break; case Media::STORAGE_MIME_MISSING: @@ -202,11 +204,11 @@ class MediaJob extends Model return; } } - + $this->data = json_encode($data); $this->setStatusQueued(); MediaWorkerJob::dispatch($this)->onQueue('media'); - } + }//end if }//end if } else { $this->setStatusQueued(); diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 38f3f29..30321da 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Traits\Uuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Permission extends Model { @@ -24,6 +25,8 @@ class Permission extends Model /** * Get the User associated with this model + * + * @return Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user(): BelongsTo { diff --git a/app/Models/UserLogins.php b/app/Models/UserLogins.php index 8b9a479..10efe16 100644 --- a/app/Models/UserLogins.php +++ b/app/Models/UserLogins.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Traits\Uuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class UserLogins extends Model { @@ -28,6 +29,8 @@ class UserLogins extends Model /** * Get the file user + * + * @return Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user(): BelongsTo { diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 8e67de0..1f84312 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -19,6 +19,8 @@ class AuthServiceProvider extends ServiceProvider /** * Register any authentication / authorization services. + * + * @return void */ public function boot(): void { diff --git a/app/Providers/BroadcastServiceProvider.php b/app/Providers/BroadcastServiceProvider.php index 2be04f5..229284c 100644 --- a/app/Providers/BroadcastServiceProvider.php +++ b/app/Providers/BroadcastServiceProvider.php @@ -9,6 +9,8 @@ class BroadcastServiceProvider extends ServiceProvider { /** * Bootstrap any application services. + * + * @return void */ public function boot(): void { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index f77570e..95217e4 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -26,6 +26,8 @@ class EventServiceProvider extends ServiceProvider /** * Register any events for your application. + * + * @return void */ public function boot(): void { @@ -34,6 +36,8 @@ class EventServiceProvider extends ServiceProvider /** * Determine if events and listeners should be automatically discovered. + * + * @return boolean */ public function shouldDiscoverEvents(): bool { diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 692cc89..7113be9 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -23,6 +23,8 @@ class RouteServiceProvider extends ServiceProvider /** * Define your route model bindings, pattern filters, and other route configuration. + * + * @return void */ public function boot(): void { @@ -31,9 +33,10 @@ class RouteServiceProvider extends ServiceProvider // }); $rateLimitEnabled = true; + /** @var \App\Models\User */ $user = auth()->user(); - if (app()->environment('testing')) { + if (app()->environment('testing') === true) { $rateLimitEnabled = false; } elseif ($user !== null && $user->hasPermission('admin/ratelimit') === true) { // Admin users with the "admin/ratelimit" permission are not rate limited @@ -42,7 +45,7 @@ class RouteServiceProvider extends ServiceProvider if ($rateLimitEnabled === true) { RateLimiter::for('api', function (Request $request) { - return Limit::perMinute(800)->by($request->user()?->id ?: $request->ip()); + return Limit::perMinute(800)->by(isset($request->user()->id) === true ?: $request->ip()); }); } else { RateLimiter::for('api', function () { diff --git a/app/Rules/Recaptcha.php b/app/Rules/Recaptcha.php index 29a8030..eb0f865 100644 --- a/app/Rules/Recaptcha.php +++ b/app/Rules/Recaptcha.php @@ -22,6 +22,7 @@ class Recaptcha implements Rule * * @param mixed $attribute Attribute name. * @param mixed $value Attribute value. + * @return boolean */ public function passes(mixed $attribute, mixed $value): bool { @@ -41,6 +42,8 @@ class Recaptcha implements Rule /** * Get the validation error message. + * + * @return string */ public function message(): string { diff --git a/app/Rules/UniqueFileName.php b/app/Rules/UniqueFileName.php index c04c388..54f2f65 100644 --- a/app/Rules/UniqueFileName.php +++ b/app/Rules/UniqueFileName.php @@ -20,15 +20,19 @@ class UniqueFileName implements Rule /** * Determine if the validation rule passes. * - * @param mixed $value + * @param mixed $attribute Attribute name. + * @param mixed $value Attribute value. + * @return boolean */ - public function passes(string $attribute, $value): bool + public function passes(mixed $attribute, mixed $value): bool { return (Media::fileExists($value) === false); } /** * Get the validation error message. + * + * @return string */ public function message(): string { diff --git a/app/Rules/Uniqueish.php b/app/Rules/Uniqueish.php index 5dd9470..14e4689 100644 --- a/app/Rules/Uniqueish.php +++ b/app/Rules/Uniqueish.php @@ -47,6 +47,7 @@ class Uniqueish implements Rule * Set the ID of the record to be ignored. * * @param mixed $id The ID to ignore. + * @return App\Rules\Uniqueish */ public function ignore(mixed $id): static { @@ -59,6 +60,7 @@ class Uniqueish implements Rule * * @param mixed $attribute Not used. * @param mixed $value The value to compare. + * @return boolean */ public function passes(mixed $attribute, mixed $value): bool { @@ -83,7 +85,7 @@ class Uniqueish implements Rule foreach ($results as $result) { $resultValue = preg_replace('/[^A-Za-z0-9]/', '', strtolower($result->{$columnName})); - if ($resultValue === $similarValue && $result->id != $this->ignoreId) { + if ($resultValue === $similarValue && $result->id !== $this->ignoreId) { return false; // Value already exists in the table } } @@ -95,6 +97,8 @@ class Uniqueish implements Rule /** * Get the validation error message. + * + * @return string */ public function message(): string { diff --git a/app/Traits/HasGallery.php b/app/Traits/HasGallery.php index 4d074ce..f2697b9 100644 --- a/app/Traits/HasGallery.php +++ b/app/Traits/HasGallery.php @@ -64,6 +64,11 @@ trait HasGallery return $this->morphMany(\App\Models\Gallery::class, 'addendum'); } + /** + * Get the article's gallery collection. + * + * @return Illuminate\Database\Eloquent\Collection The gallery collection + */ public function getGallery(): Collection { return Cache::remember($this->galleryCacheKey(), now()->addDays(28), function () { diff --git a/app/Traits/Uuids.php b/app/Traits/Uuids.php index 64524f0..a5053ee 100644 --- a/app/Traits/Uuids.php +++ b/app/Traits/Uuids.php @@ -8,6 +8,8 @@ trait Uuids { /** * Boot function from Laravel. + * + * @return void */ protected static function bootUuids(): void { @@ -20,6 +22,8 @@ trait Uuids /** * Get the value indicating whether the IDs are incrementing. + * + * @return boolean */ public function getIncrementing(): bool { @@ -28,6 +32,8 @@ trait Uuids /** * Get the auto-incrementing key type. + * + * @return string */ public function getKeyType(): string { diff --git a/config/broadcasting.php b/config/broadcasting.php index 4dbd22c..bc46200 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -36,7 +36,7 @@ return [ 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ - 'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com', + 'host' => env('PUSHER_HOST') === null ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com', 'port' => env('PUSHER_PORT', 443), 'scheme' => env('PUSHER_SCHEME', 'https'), 'encrypted' => true, diff --git a/config/clamav.php b/config/clamav.php index ca26ffa..c58c198 100644 --- a/config/clamav.php +++ b/config/clamav.php @@ -34,7 +34,8 @@ return [ |-------------------------------------------------------------------------- | Socket connect timeout |-------------------------------------------------------------------------- - | This option defines the maximum time to wait in seconds for socket connection attempts before failure or timeout, default null = no limit. + | This option defines the maximum time to wait in seconds for socket connection attempts before failure or timeout, + | default null = no limit. */ 'socket_connect_timeout' => env('CLAMAV_SOCKET_CONNECT_TIMEOUT', null), diff --git a/config/database.php b/config/database.php index 535cd52..690645a 100644 --- a/config/database.php +++ b/config/database.php @@ -58,7 +58,7 @@ return [ 'prefix_indexes' => true, 'strict' => true, 'engine' => null, - 'options' => extension_loaded('pdo_mysql') ? array_filter([ + 'options' => extension_loaded('pdo_mysql') === true ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], ], diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index e3ad27e..c6b6d48 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -9,6 +9,8 @@ trait CreatesApplication { /** * Creates the application. + * + * @return \Illuminate\Foundation\Application */ public function createApplication(): Application { diff --git a/tests/Feature/ArticlesApiTest.php b/tests/Feature/ArticlesApiTest.php index 2d2e79a..37d1332 100644 --- a/tests/Feature/ArticlesApiTest.php +++ b/tests/Feature/ArticlesApiTest.php @@ -1,5 +1,7 @@ faker = FakerFactory::create(); } + /** + * Tests that any user can view an article if it's published and not in the future. + * + * @return void + */ public function testAnyUserCanViewArticle(): void { // Create an event @@ -51,6 +67,11 @@ final class ArticlesApiTest extends TestCase ]); } + /** + * Tests that an admin can create, update, and delete articles. + * + * @return void + */ public function testAdminCanCreateUpdateDeleteArticle(): void { // Create a user with the admin/events permission @@ -102,6 +123,11 @@ final class ArticlesApiTest extends TestCase ]); } + /** + * Tests that a non-admin user cannot create, update, or delete articles. + * + * @return void + */ public function testNonAdminCannotCreateUpdateDeleteArticle(): void { // Create a user without admin/events permission diff --git a/tests/Feature/AuthApiTest.php b/tests/Feature/AuthApiTest.php index 5c7793f..012b95f 100644 --- a/tests/Feature/AuthApiTest.php +++ b/tests/Feature/AuthApiTest.php @@ -1,5 +1,7 @@ create([ diff --git a/tests/Feature/ContactFormTest.php b/tests/Feature/ContactFormTest.php index e0f7ba7..fc212e7 100644 --- a/tests/Feature/ContactFormTest.php +++ b/tests/Feature/ContactFormTest.php @@ -1,5 +1,7 @@ faker = FakerFactory::create(); } + /** + * Tests that any user can view an event if it's published and not in the future. + * + * @return void + */ public function testAnyUserCanViewEvent(): void { // Create an event @@ -52,6 +68,11 @@ final class EventsApiTest extends TestCase ]); } + /** + * Tests that any user cannot see draft events. + * + * @return void + */ public function testAnyUserCannotSeeDraftEvent(): void { // Create a draft event @@ -85,6 +106,11 @@ final class EventsApiTest extends TestCase ]); } + /** + * Tests that an admin can create, update, and delete events. + * + * @return void + */ public function testAdminCanCreateUpdateDeleteEvent(): void { // Create a user with the admin/events permission @@ -139,6 +165,11 @@ final class EventsApiTest extends TestCase ]); } + /** + * Tests that a non-admin user cannot create, update, or delete events. + * + * @return void + */ public function testNonAdminCannotCreateUpdateDeleteEvent(): void { // Create a user without admin/events permission diff --git a/tests/Feature/UsersApiTest.php b/tests/Feature/UsersApiTest.php index d15d2d3..2974143 100644 --- a/tests/Feature/UsersApiTest.php +++ b/tests/Feature/UsersApiTest.php @@ -1,5 +1,7 @@ assertJsonValidationErrors(['display_name', 'email']); } + /** + * Tests that a user can only update their own user info. + * + * @return void + */ public function testUserCanOnlyUpdateOwnUser(): void { $user = User::factory()->create(); @@ -149,6 +176,11 @@ final class UsersApiTest extends TestCase $response->assertStatus(403); } + /** + * Tests that a user cannot delete users via the API. + * + * @return void + */ public function testUserCannotDeleteUsers(): void { $user = User::factory()->create(); @@ -165,6 +197,11 @@ final class UsersApiTest extends TestCase $this->assertDatabaseHas('users', ['id' => $otherUser->id]); } + /** + * Tests that an admin can update any user's info. + * + * @return void + */ public function testAdminCanUpdateAnyUser(): void { $admin = User::factory()->create(); @@ -200,6 +237,11 @@ final class UsersApiTest extends TestCase ]); } + /** + * Tests that an admin can delete any user via the API. + * + * @return void + */ public function testAdminCanDeleteAnyUser(): void { $admin = User::factory()->create(); diff --git a/tests/TestCase.php b/tests/TestCase.php index dead5f1..c6f92c9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,6 +9,11 @@ abstract class TestCase extends BaseTestCase use CreatesApplication; + /** + * {@inheritDoc} + * + * @return void + */ protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index fff6e3c..500fbfe 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -8,6 +8,8 @@ final class ExampleTest extends TestCase { /** * A basic test example. + * + * @return void */ public function test_that_true_is_true(): void {