Laravel 10.x Shift #49
@@ -41,7 +41,7 @@ class AnalyticsConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow model to be visible.
|
||||
*/
|
||||
public static function viewable(Model $model)
|
||||
public static function viewable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
||||
@@ -52,7 +52,7 @@ class AnalyticsConductor extends Conductor
|
||||
*
|
||||
* @return boolean Allow creating model.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class AnalyticsConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
||||
@@ -75,7 +75,7 @@ class AnalyticsConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/analytics') === true);
|
||||
|
||||
@@ -41,7 +41,7 @@ class ArticleConductor extends Conductor
|
||||
* @param Builder $builder The builder in use.
|
||||
* @return void
|
||||
*/
|
||||
public function scope(Builder $builder)
|
||||
public function scope(Builder $builder): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user === null || $user->hasPermission('admin/articles') === false) {
|
||||
@@ -56,7 +56,7 @@ class ArticleConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow model to be visible.
|
||||
*/
|
||||
public static function viewable(Model $model)
|
||||
public static function viewable(Model $model): bool
|
||||
{
|
||||
if (Carbon::parse($model->publish_at)->isFuture() === true) {
|
||||
$user = auth()->user();
|
||||
@@ -73,7 +73,7 @@ class ArticleConductor extends Conductor
|
||||
*
|
||||
* @return boolean Allow creating model.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
||||
@@ -85,7 +85,7 @@ class ArticleConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
||||
@@ -97,7 +97,7 @@ class ArticleConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/articles') === true);
|
||||
@@ -109,7 +109,7 @@ class ArticleConductor extends Conductor
|
||||
* @param array $data The model data to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
public function transformFinal(array $data)
|
||||
public function transformFinal(array $data): array
|
||||
{
|
||||
unset($data['user_id']);
|
||||
return $data;
|
||||
@@ -145,7 +145,7 @@ class ArticleConductor extends Conductor
|
||||
* @param mixed $value The current value.
|
||||
* @return array The new value.
|
||||
*/
|
||||
public function transformHero(mixed $value)
|
||||
public function transformHero(mixed $value): array
|
||||
{
|
||||
return MediaConductor::includeModel(request(), 'hero', Media::find($value));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class Conductor
|
||||
* @param string $string The string to split.
|
||||
* @return array The split string.
|
||||
*/
|
||||
private function splitString(string $string)
|
||||
private function splitString(string $string): array
|
||||
{
|
||||
$parts = [];
|
||||
$start = 0;
|
||||
@@ -145,7 +145,7 @@ class Conductor
|
||||
* @param array|null $limitFields A list of fields to limit the filter request to.
|
||||
* @return void
|
||||
*/
|
||||
private function filter(Request $request, array|null $limitFields = null)
|
||||
private function filter(Request $request, array|null $limitFields = null): void
|
||||
{
|
||||
if (is_array($limitFields) === true && count($limitFields) === 0) {
|
||||
$limitFields = null;
|
||||
@@ -213,7 +213,7 @@ class Conductor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function applyFilters()
|
||||
final public function applyFilters(): void
|
||||
{
|
||||
$parseFunc = function ($filterArray, $query) use (&$parseFunc) {
|
||||
$item = null;
|
||||
@@ -365,7 +365,7 @@ class Conductor
|
||||
* @param Request $request The request data.
|
||||
* @return array The processed and transformed collection | the total rows found.
|
||||
*/
|
||||
final public static function request(Request $request)
|
||||
final public static function request(Request $request): array
|
||||
{
|
||||
$conductor_class = get_called_class();
|
||||
$conductor = new $conductor_class();
|
||||
@@ -457,7 +457,7 @@ class Conductor
|
||||
* @param Collection $collection The collection.
|
||||
* @return array The processed and transformed model data.
|
||||
*/
|
||||
final public static function collection(Request $request, Collection $collection)
|
||||
final public static function collection(Request $request, Collection $collection): array
|
||||
{
|
||||
$conductor_class = get_called_class();
|
||||
$conductor = new $conductor_class();
|
||||
@@ -505,7 +505,7 @@ class Conductor
|
||||
* @param array|null $limitFields Limit the request to these fields.
|
||||
* @return Builder
|
||||
*/
|
||||
public static function filterQuery(Builder $query, Request $request, array|null $limitFields = null)
|
||||
public static function filterQuery(Builder $query, Request $request, array|null $limitFields = null): Builder
|
||||
{
|
||||
$conductor_class = get_called_class();
|
||||
$conductor = new $conductor_class();
|
||||
@@ -525,7 +525,7 @@ class Conductor
|
||||
* @param Model|null $model The model.
|
||||
* @return array The processed and transformed model data.
|
||||
*/
|
||||
final public static function includeModel(Request $request, string $key, mixed $model)
|
||||
final public static function includeModel(Request $request, string $key, mixed $model): array
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
@@ -553,7 +553,7 @@ class Conductor
|
||||
* @param Model|null $model The model.
|
||||
* @return array The processed and transformed model data.
|
||||
*/
|
||||
final public static function model(mixed $fields, mixed $model)
|
||||
final public static function model(mixed $fields, mixed $model): array
|
||||
{
|
||||
if ($model === null) {
|
||||
return null;
|
||||
@@ -606,7 +606,7 @@ class Conductor
|
||||
*
|
||||
* @return integer The current collection count.
|
||||
*/
|
||||
final public function count()
|
||||
final public function count(): int
|
||||
{
|
||||
if ($this->query !== null) {
|
||||
return $this->query->count();
|
||||
@@ -621,7 +621,7 @@ class Conductor
|
||||
* @param mixed $fields A field name or array of field names to sort. Supports prefix of +/- to change direction.
|
||||
* @return void
|
||||
*/
|
||||
final public function sort(mixed $fields = null)
|
||||
final public function sort(mixed $fields = null): void
|
||||
{
|
||||
$collectionSort = [];
|
||||
|
||||
@@ -700,7 +700,7 @@ class Conductor
|
||||
* @param array $includes The list of includes to include.
|
||||
* @return void
|
||||
*/
|
||||
final public function applyIncludes(Model $model, array $includes)
|
||||
final public function applyIncludes(Model $model, array $includes): void
|
||||
{
|
||||
foreach ($includes as $include) {
|
||||
$includeMethodName = 'include' . Str::studly($include);
|
||||
@@ -720,7 +720,7 @@ class Conductor
|
||||
* @param array $fields An array of field names.
|
||||
* @return void
|
||||
*/
|
||||
final public function limitFields(array $fields)
|
||||
final public function limitFields(array $fields): void
|
||||
{
|
||||
if (empty($fields) !== true) {
|
||||
$this->query->select(array_diff($fields, $this->includes));
|
||||
@@ -735,7 +735,7 @@ 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 = 'OR')
|
||||
final public function appendFilterString(string $rawFilter, array|null $limitFields = null, string $outerJoin = 'OR'): void
|
||||
{
|
||||
if ($rawFilter === '') {
|
||||
return;
|
||||
@@ -849,7 +849,7 @@ class Conductor
|
||||
* @param string $join The join to append.
|
||||
* @return void
|
||||
*/
|
||||
final public function appendFilter(string $field, string $operator, string $value, string $join = 'OR')
|
||||
final public function appendFilter(string $field, string $operator, string $value, string $join = 'OR'): void
|
||||
{
|
||||
if (count($this->filterArray) !== 0) {
|
||||
$this->filterArray[] = $join;
|
||||
@@ -863,7 +863,7 @@ class Conductor
|
||||
* @param Builder $builder The builder in use.
|
||||
* @return void
|
||||
*/
|
||||
public function scope(Builder $builder)
|
||||
public function scope(Builder $builder): void
|
||||
{
|
||||
}
|
||||
|
||||
@@ -873,7 +873,7 @@ class Conductor
|
||||
* @param Model $model The model in question.
|
||||
* @return array The array of field names.
|
||||
*/
|
||||
public function fields(Model $model)
|
||||
public function fields(Model $model): array
|
||||
{
|
||||
$visibleFields = $model->getVisible();
|
||||
if (empty($visibleFields) === true) {
|
||||
@@ -900,7 +900,7 @@ class Conductor
|
||||
* @param Model $model The model to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
protected function transformModel(Model $model)
|
||||
protected function transformModel(Model $model): array
|
||||
{
|
||||
$result = $this->transform($model);
|
||||
foreach ($result as $key => $value) {
|
||||
@@ -920,7 +920,7 @@ class Conductor
|
||||
* @param Model $model The model to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
public function transform(Model $model): array
|
||||
{
|
||||
$result = $model->toArray();
|
||||
|
||||
@@ -939,7 +939,7 @@ class Conductor
|
||||
* @param array $data The model array to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
public function transformFinal(array $data)
|
||||
public function transformFinal(array $data): array
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
@@ -950,7 +950,7 @@ class Conductor
|
||||
* @param Model $model The model in question.
|
||||
* @return boolean Is the model viewable.
|
||||
*/
|
||||
public static function viewable(Model $model)
|
||||
public static function viewable(Model $model): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -960,7 +960,7 @@ class Conductor
|
||||
*
|
||||
* @return boolean Is the model creatable.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -971,7 +971,7 @@ class Conductor
|
||||
* @param Model $model The model in question.
|
||||
* @return boolean Is the model updatable.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -982,7 +982,7 @@ class Conductor
|
||||
* @param Model $model The model in question.
|
||||
* @return boolean Is the model destroyable.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class EventConductor extends Conductor
|
||||
* @param Builder $builder The builder in use.
|
||||
* @return void
|
||||
*/
|
||||
public function scope(Builder $builder)
|
||||
public function scope(Builder $builder): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user === null || $user->hasPermission('admin/events') === false) {
|
||||
@@ -51,7 +51,7 @@ class EventConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow model to be visible.
|
||||
*/
|
||||
public static function viewable(Model $model)
|
||||
public static function viewable(Model $model): bool
|
||||
{
|
||||
if (strtolower($model->status) === 'draft' || Carbon::parse($model->publish_at)->isFuture() === true) {
|
||||
$user = auth()->user();
|
||||
@@ -68,7 +68,7 @@ class EventConductor extends Conductor
|
||||
*
|
||||
* @return boolean Allow creating model.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
||||
@@ -80,7 +80,7 @@ class EventConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
||||
@@ -92,7 +92,7 @@ class EventConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/events') === true);
|
||||
@@ -121,7 +121,7 @@ class EventConductor extends Conductor
|
||||
* @param mixed $value The current value.
|
||||
* @return array The new value.
|
||||
*/
|
||||
public function transformHero(mixed $value)
|
||||
public function transformHero(mixed $value): array
|
||||
{
|
||||
return MediaConductor::includeModel(request(), 'hero', Media::find($value));
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class MediaConductor extends Conductor
|
||||
* @param Model $model The model in question.
|
||||
* @return array The array of field names.
|
||||
*/
|
||||
public function fields(Model $model)
|
||||
public function fields(Model $model): array
|
||||
{
|
||||
$fields = parent::fields($model);
|
||||
|
||||
@@ -61,7 +61,7 @@ class MediaConductor extends Conductor
|
||||
* @param Builder $builder The builder in use.
|
||||
* @return void
|
||||
*/
|
||||
public function scope(Builder $builder)
|
||||
public function scope(Builder $builder): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user === null) {
|
||||
@@ -77,7 +77,7 @@ class MediaConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow model to be visible.
|
||||
*/
|
||||
public static function viewable(Model $model)
|
||||
public static function viewable(Model $model): bool
|
||||
{
|
||||
if ($model->permission !== '') {
|
||||
$user = auth()->user();
|
||||
@@ -94,7 +94,7 @@ class MediaConductor extends Conductor
|
||||
*
|
||||
* @return boolean Allow creating model.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null);
|
||||
@@ -106,7 +106,7 @@ class MediaConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && (strcasecmp($model->user_id, $user->id) === 0 || $user->hasPermission('admin/media') === true));
|
||||
@@ -118,7 +118,7 @@ class MediaConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && ($model->user_id === $user->id || $user->hasPermission('admin/media') === true));
|
||||
@@ -130,7 +130,7 @@ class MediaConductor extends Conductor
|
||||
* @param array $data The model data to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
public function transformFinal(array $data)
|
||||
public function transformFinal(array $data): array
|
||||
{
|
||||
unset($data['user_id']);
|
||||
return $data;
|
||||
|
||||
@@ -26,7 +26,7 @@ class ShortlinkConductor extends Conductor
|
||||
*
|
||||
* @return boolean Allow creating model.
|
||||
*/
|
||||
public static function creatable()
|
||||
public static function creatable(): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
||||
@@ -38,7 +38,7 @@ class ShortlinkConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
||||
@@ -50,7 +50,7 @@ class ShortlinkConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/shortlinks') === true);
|
||||
|
||||
@@ -19,7 +19,7 @@ class SubscriptionConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
||||
@@ -31,7 +31,7 @@ class SubscriptionConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && ((strcasecmp($model->email, $user->email) === 0 && $user->email_verified_at !== null) || $user->hasPermission('admin/subscriptions') === true));
|
||||
|
||||
@@ -19,7 +19,7 @@ class UserConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return string[] The fields visible.
|
||||
*/
|
||||
public function fields(Model $model)
|
||||
public function fields(Model $model): array
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user === null || $user->hasPermission('admin/users') === false) {
|
||||
@@ -35,7 +35,7 @@ class UserConductor extends Conductor
|
||||
* @param Model $model The model to transform.
|
||||
* @return array The transformed model.
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
public function transform(Model $model): array
|
||||
{
|
||||
$user = auth()->user();
|
||||
$data = $model->toArray();
|
||||
@@ -56,7 +56,7 @@ class UserConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow updating model.
|
||||
*/
|
||||
public static function updatable(Model $model)
|
||||
public static function updatable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user !== null) {
|
||||
@@ -72,7 +72,7 @@ class UserConductor extends Conductor
|
||||
* @param Model $model The model.
|
||||
* @return boolean Allow deleting model.
|
||||
*/
|
||||
public static function destroyable(Model $model)
|
||||
public static function destroyable(Model $model): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
return ($user !== null && $user->hasPermission('admin/users') === true);
|
||||
|
||||
@@ -30,7 +30,7 @@ class MediaMigrate extends Command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption(
|
||||
'replace',
|
||||
|
||||
@@ -29,7 +29,7 @@ class MediaRebuild extends Command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption(
|
||||
'replace',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Enum\HttpResponseCodes;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -25,7 +26,7 @@ class ApiController extends Controller
|
||||
* @param array $headers Response headers.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondJson(array $data, int $respondCode = HttpResponseCodes::HTTP_OK, array $headers = [])
|
||||
public function respondJson(array $data, int $respondCode = HttpResponseCodes::HTTP_OK, array $headers = []): JsonResponse
|
||||
{
|
||||
return response()->json($data, $respondCode, $headers);
|
||||
}
|
||||
@@ -36,7 +37,7 @@ class ApiController extends Controller
|
||||
* @param string $message Response message.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondForbidden(string $message = 'You do not have permission to access the resource.')
|
||||
public function respondForbidden(string $message = 'You do not have permission to access the resource.'): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_FORBIDDEN);
|
||||
}
|
||||
@@ -47,7 +48,7 @@ class ApiController extends Controller
|
||||
* @param string $message Response message.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondNotFound(string $message = 'The resource was not found.')
|
||||
public function respondNotFound(string $message = 'The resource was not found.'): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_NOT_FOUND);
|
||||
}
|
||||
@@ -58,7 +59,7 @@ class ApiController extends Controller
|
||||
* @param string $message Response message.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondTooLarge(string $message = 'The request entity is too large.')
|
||||
public function respondTooLarge(string $message = 'The request entity is too large.'): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => $message], HttpResponseCodes::HTTP_REQUEST_ENTITY_TOO_LARGE);
|
||||
}
|
||||
@@ -67,7 +68,7 @@ class ApiController extends Controller
|
||||
* Return no content
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondNoContent()
|
||||
public function respondNoContent(): JsonResponse
|
||||
{
|
||||
return response()->json([], HttpResponseCodes::HTTP_NO_CONTENT);
|
||||
}
|
||||
@@ -76,7 +77,7 @@ class ApiController extends Controller
|
||||
* Return created
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondCreated()
|
||||
public function respondCreated(): JsonResponse
|
||||
{
|
||||
return response()->json([], HttpResponseCodes::HTTP_CREATED);
|
||||
}
|
||||
@@ -85,7 +86,7 @@ class ApiController extends Controller
|
||||
* Return accepted
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondAccepted()
|
||||
public function respondAccepted(): JsonResponse
|
||||
{
|
||||
return response()->json([], HttpResponseCodes::HTTP_ACCEPTED);
|
||||
}
|
||||
@@ -97,7 +98,7 @@ class ApiController extends Controller
|
||||
* @param integer $responseCode Resource code.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondError(string $message, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY)
|
||||
public function respondError(string $message, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'message' => $message
|
||||
@@ -111,7 +112,7 @@ class ApiController extends Controller
|
||||
* @param integer $responseCode Resource code.
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function respondWithErrors(array $errors, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY)
|
||||
public function respondWithErrors(array $errors, int $responseCode = HttpResponseCodes::HTTP_UNPROCESSABLE_ENTITY): JsonResponse
|
||||
{
|
||||
$keys = array_keys($errors);
|
||||
$error = $errors[$keys[0]];
|
||||
@@ -138,7 +139,7 @@ class ApiController extends Controller
|
||||
mixed $data,
|
||||
array $options = [],
|
||||
$validationFn = null
|
||||
) {
|
||||
): JsonResponse {
|
||||
$isCollection = $options['isCollection'] ?? false;
|
||||
$appendData = $options['appendData'] ?? null;
|
||||
$resourceName = $options['resourceName'] ?? null;
|
||||
|
||||
@@ -126,7 +126,7 @@ class ArticleController extends ApiController
|
||||
* @throws BindingResolutionException
|
||||
* @throws InvalidCastException
|
||||
*/
|
||||
public function getAttachments(Request $request, Article $article)
|
||||
public function getAttachments(Request $request, Article $article): JsonResponse
|
||||
{
|
||||
if (ArticleConductor::viewable($article) === true) {
|
||||
$medium = $article->attachments->map(function ($attachment) {
|
||||
@@ -148,7 +148,7 @@ class ArticleController extends ApiController
|
||||
* @throws BindingResolutionException
|
||||
* @throws MassAssignmentException
|
||||
*/
|
||||
public function storeAttachment(Request $request, Article $article)
|
||||
public function storeAttachment(Request $request, Article $article): JsonResponse
|
||||
{
|
||||
if (ArticleConductor::updatable($article) === true) {
|
||||
if ($request->has("medium") && Media::find($request->medium)) {
|
||||
@@ -171,7 +171,7 @@ class ArticleController extends ApiController
|
||||
* @throws BindingResolutionException
|
||||
* @throws MassAssignmentException
|
||||
*/
|
||||
public function updateAttachments(Request $request, Article $article)
|
||||
public function updateAttachments(Request $request, Article $article): JsonResponse
|
||||
{
|
||||
if (ArticleConductor::updatable($article) === true) {
|
||||
$mediaIds = $request->attachments;
|
||||
@@ -219,7 +219,7 @@ class ArticleController extends ApiController
|
||||
* @return JsonResponse
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function deleteAttachment(Request $request, Article $article, Media $medium)
|
||||
public function deleteAttachment(Request $request, Article $article, Media $medium): JsonResponse
|
||||
{
|
||||
if (ArticleConductor::updatable($article) === true) {
|
||||
$attachments = $article->attachments;
|
||||
|
||||
@@ -33,7 +33,7 @@ class AuthController extends ApiController
|
||||
* @param Request $request Current request data.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function me(Request $request)
|
||||
public function me(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user()->makeVisible(['permissions']);
|
||||
return $this->respondAsResource($user);
|
||||
@@ -89,7 +89,7 @@ class AuthController extends ApiController
|
||||
* @param Request $request Current request data.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
public function logout(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class EventController extends ApiController
|
||||
* @param Event $event The event model.
|
||||
* @return JsonResponse Returns the event attachments.
|
||||
*/
|
||||
public function getAttachments(Request $request, Event $event)
|
||||
public function getAttachments(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
if (EventConductor::viewable($event) === true) {
|
||||
$medium = $event->attachments->map(function ($attachment) {
|
||||
@@ -136,7 +136,7 @@ class EventController extends ApiController
|
||||
* @param Event $event The event model.
|
||||
* @return JsonResponse The response.
|
||||
*/
|
||||
public function storeAttachment(Request $request, Event $event)
|
||||
public function storeAttachment(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
if (EventConductor::updatable($event) === true) {
|
||||
if ($request->has("medium") === true && Media::find($request->medium) !== null) {
|
||||
@@ -157,7 +157,7 @@ class EventController extends ApiController
|
||||
* @param Event $event The related model.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function updateAttachments(Request $request, Event $event)
|
||||
public function updateAttachments(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
if (EventConductor::updatable($event) === true) {
|
||||
$mediaIds = $request->attachments;
|
||||
@@ -205,7 +205,7 @@ class EventController extends ApiController
|
||||
* @param Media $medium The attachment medium.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deleteAttachment(Request $request, Event $event, Media $medium)
|
||||
public function deleteAttachment(Request $request, Event $event, Media $medium): JsonResponse
|
||||
{
|
||||
if (EventConductor::updatable($event) === true) {
|
||||
$attachments = $event->attachments;
|
||||
|
||||
@@ -147,7 +147,7 @@ class UserController extends ApiController
|
||||
* @param \App\Http\Requests\UserRegisterRequest $request The register user request.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function register(UserRegisterRequest $request)
|
||||
public function register(UserRegisterRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$userData = $request->only([
|
||||
@@ -288,7 +288,7 @@ class UserController extends ApiController
|
||||
* @param \App\Http\Requests\UserResendVerifyEmailRequest $request The resend verify email request.
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function resendVerifyEmail(UserResendVerifyEmailRequest $request)
|
||||
public function resendVerifyEmail(UserResendVerifyEmailRequest $request): JsonResponse
|
||||
{
|
||||
UserCode::clearExpired();
|
||||
|
||||
@@ -342,7 +342,7 @@ class UserController extends ApiController
|
||||
* @param User $user The specified user.
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function eventList(Request $request, User $user)
|
||||
public function eventList(Request $request, User $user): JsonResponse
|
||||
{
|
||||
if ($request->user() !== null && ($request->user() === $user || $request->user()->hasPermission('admin/events') === true)) {
|
||||
$collection = $user->events;
|
||||
|
||||
@@ -11,7 +11,7 @@ class AnalyticsRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function postRules()
|
||||
public function postRules(): array
|
||||
{
|
||||
return [
|
||||
'type' => 'required|string',
|
||||
@@ -23,7 +23,7 @@ class AnalyticsRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function putRules()
|
||||
public function putRules(): array
|
||||
{
|
||||
return [
|
||||
'type' => 'string',
|
||||
|
||||
@@ -11,7 +11,7 @@ class ArticleRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function postRules()
|
||||
public function postRules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => 'required|string|min:6|unique:articles',
|
||||
@@ -28,7 +28,7 @@ class ArticleRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function putRules()
|
||||
public function putRules(): array
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
|
||||
@@ -56,7 +56,7 @@ class BaseRequest extends FormRequest
|
||||
* @param array $collection2 The second collection of rules to merge.
|
||||
* @return array
|
||||
*/
|
||||
private function mergeRules(array $collection1, array $collection2)
|
||||
private function mergeRules(array $collection1, array $collection2): array
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class EventRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function baseRules()
|
||||
public function baseRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'min:6',
|
||||
@@ -42,7 +42,7 @@ class EventRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function postRules()
|
||||
protected function postRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required',
|
||||
|
||||
@@ -11,7 +11,7 @@ class ShortlinkRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function postRules()
|
||||
public function postRules(): array
|
||||
{
|
||||
return [
|
||||
'code' => 'required|string|max:255|min:2|unique:shortlinks',
|
||||
@@ -24,7 +24,7 @@ class ShortlinkRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function putRules()
|
||||
public function putRules(): array
|
||||
{
|
||||
$shortlink = $this->route('shortlink');
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class SubscriptionRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function postRules()
|
||||
public function postRules(): array
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email|unique:subscriptions',
|
||||
@@ -24,7 +24,7 @@ class SubscriptionRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function destroyRules()
|
||||
public function destroyRules(): array
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
|
||||
@@ -15,7 +15,7 @@ class UserRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function postRules()
|
||||
public function postRules(): array
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdminUser = $user->hasPermission('admin/users');
|
||||
@@ -40,7 +40,7 @@ class UserRequest extends BaseRequest
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function putRules()
|
||||
public function putRules(): array
|
||||
{
|
||||
$user = auth()->user();
|
||||
$ruleUser = $this->route('user');
|
||||
|
||||
@@ -57,7 +57,7 @@ class ChangeEmailVerify extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '👋🏻 Lets change your email!',
|
||||
@@ -69,7 +69,7 @@ class ChangeEmailVerify extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.change_email_verify',
|
||||
|
||||
@@ -57,7 +57,7 @@ class ChangedEmail extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '👍 Your email has been changed!',
|
||||
@@ -69,7 +69,7 @@ class ChangedEmail extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.changed_email',
|
||||
|
||||
@@ -39,7 +39,7 @@ class ChangedPassword extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '👍 Your password has been changed!',
|
||||
@@ -51,7 +51,7 @@ class ChangedPassword extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.changed_password',
|
||||
|
||||
@@ -56,7 +56,7 @@ class Contact extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: config('contact.contact_subject'),
|
||||
@@ -68,7 +68,7 @@ class Contact extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.contact',
|
||||
|
||||
@@ -48,7 +48,7 @@ class EmailVerify extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '👋🏻 Welcome to STEMMechanics!',
|
||||
@@ -60,7 +60,7 @@ class EmailVerify extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.email_verify',
|
||||
|
||||
@@ -48,7 +48,7 @@ class ForgotPassword extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '🤦 Forgot your password?',
|
||||
@@ -60,7 +60,7 @@ class ForgotPassword extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.forgot_password',
|
||||
|
||||
@@ -39,7 +39,7 @@ class SubscriptionConfirm extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '🗞️ You\'re on the mailing list!',
|
||||
@@ -51,7 +51,7 @@ class SubscriptionConfirm extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.subscription_confirm',
|
||||
|
||||
@@ -39,7 +39,7 @@ class SubscriptionUnsubscribed extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'You have been unsubscribed',
|
||||
@@ -51,7 +51,7 @@ class SubscriptionUnsubscribed extends Mailable
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Content
|
||||
*/
|
||||
public function content()
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.subscription_unsubscribed',
|
||||
|
||||
@@ -24,7 +24,7 @@ class Analytics extends Model
|
||||
* @param array $attributes Model attributes.
|
||||
* @return static
|
||||
*/
|
||||
public static function createWithSession(array $attributes)
|
||||
public static function createWithSession(array $attributes): static
|
||||
{
|
||||
$previousRow = self::where('useragent', $attributes['useragent'])
|
||||
->where('ip', $attributes['ip'])
|
||||
|
||||
@@ -32,7 +32,7 @@ class Article extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class Article extends Model
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments()
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(\App\Models\Attachment::class, 'attachable');
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class Attachment extends Model
|
||||
*
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function attachable()
|
||||
public function attachable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class Attachment extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function media()
|
||||
public function media(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Media::class);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Event extends Model
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments()
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(\App\Models\Attachment::class, 'attachable');
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class Event extends Model
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function users()
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'event_user', 'event_id', 'user_id');
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class EventUser extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function event()
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class EventUser extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class Media extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
@@ -136,7 +136,7 @@ class Media extends Model
|
||||
* @param string $type The variant type to get.
|
||||
* @return array The variant data.
|
||||
*/
|
||||
public static function getTypeVariants(string $type)
|
||||
public static function getTypeVariants(string $type): array
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === true) {
|
||||
return self::$variantTypes[$type];
|
||||
@@ -151,7 +151,7 @@ class Media extends Model
|
||||
* @param mixed $value The value to mutate.
|
||||
* @return array The mutated value.
|
||||
*/
|
||||
public function getVariantsAttribute(mixed $value)
|
||||
public function getVariantsAttribute(mixed $value): array
|
||||
{
|
||||
if (is_string($value) === true) {
|
||||
return json_decode($value, true);
|
||||
@@ -166,7 +166,7 @@ class Media extends Model
|
||||
* @param mixed $value The value to mutate.
|
||||
* @return void
|
||||
*/
|
||||
public function setVariantsAttribute(mixed $value)
|
||||
public function setVariantsAttribute(mixed $value): void
|
||||
{
|
||||
if (is_array($value) !== true) {
|
||||
$value = [];
|
||||
@@ -182,7 +182,7 @@ class Media extends Model
|
||||
* @param string $variant The initial variant.
|
||||
* @return string The previous variant name (or '').
|
||||
*/
|
||||
public function getPreviousVariant(string $type, string $variant)
|
||||
public function getPreviousVariant(string $type, string $variant): string
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === false) {
|
||||
return '';
|
||||
@@ -206,7 +206,7 @@ class Media extends Model
|
||||
* @param string $variant The initial variant.
|
||||
* @return string The next variant name (or '').
|
||||
*/
|
||||
public function getNextVariant(string $type, string $variant)
|
||||
public function getNextVariant(string $type, string $variant): string
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === false) {
|
||||
return '';
|
||||
@@ -230,7 +230,7 @@ class Media extends Model
|
||||
* @param boolean $returnNearest Return the nearest variant if request is not found.
|
||||
* @return string The URL.
|
||||
*/
|
||||
public function getVariantURL(string $variant, bool $returnNearest = true)
|
||||
public function getVariantURL(string $variant, bool $returnNearest = true): string
|
||||
{
|
||||
$variants = $this->variants;
|
||||
if (isset($variants[$variant]) === true) {
|
||||
@@ -259,7 +259,7 @@ class Media extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteFile()
|
||||
public function deleteFile(): void
|
||||
{
|
||||
$fileName = $this->name;
|
||||
$baseName = pathinfo($fileName, PATHINFO_FILENAME);
|
||||
@@ -282,7 +282,7 @@ class Media extends Model
|
||||
* @return void
|
||||
* @throws InvalidArgumentException Exception.
|
||||
*/
|
||||
private function invalidateCFCache()
|
||||
private function invalidateCFCache(): void
|
||||
{
|
||||
$zone_id = env("CLOUDFLARE_ZONE_ID");
|
||||
$api_key = env("CLOUDFLARE_API_KEY");
|
||||
@@ -314,7 +314,7 @@ class Media extends Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlPath()
|
||||
public function getUrlPath(): string
|
||||
{
|
||||
$url = config("filesystems.disks.$this->storage.url");
|
||||
return "$url/";
|
||||
@@ -325,7 +325,7 @@ class Media extends Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlAttribute()
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
if (isset($this->attributes['name']) === true) {
|
||||
return self::getUrlPath() . $this->name;
|
||||
@@ -339,7 +339,7 @@ class Media extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
@@ -350,7 +350,7 @@ class Media extends Model
|
||||
* @param string $storage The storage ID to move to.
|
||||
* @return void
|
||||
*/
|
||||
public function moveToStorage(string $storage)
|
||||
public function moveToStorage(string $storage): void
|
||||
{
|
||||
if ($storage !== $this->storage && Config::has("filesystems.disks.$storage") === true) {
|
||||
$this->status = "Processing media";
|
||||
@@ -366,7 +366,7 @@ class Media extends Model
|
||||
* @param Illuminate\Http\UploadedFile $file The file.
|
||||
* @return null|Media The result or null if not successful.
|
||||
*/
|
||||
public static function createFromUploadedFile(Request $request, UploadedFile $file)
|
||||
public static function createFromUploadedFile(Request $request, UploadedFile $file): ?Media
|
||||
{
|
||||
$request->merge([
|
||||
'title' => $request->get('title', ''),
|
||||
@@ -401,7 +401,7 @@ class Media extends Model
|
||||
* @param Illuminate\Http\UploadedFile $file The file.
|
||||
* @return null|Media The media item.
|
||||
*/
|
||||
public function updateWithUploadedFile(UploadedFile $file)
|
||||
public function updateWithUploadedFile(UploadedFile $file): ?Media
|
||||
{
|
||||
if ($file === null || $file->isValid() !== true) {
|
||||
throw new \Exception('The file is invalid.', self::INVALID_FILE_ERROR);
|
||||
@@ -497,7 +497,7 @@ class Media extends Model
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getMaxUploadSize()
|
||||
public static function getMaxUploadSize(): int
|
||||
{
|
||||
$sizes = [
|
||||
ini_get('upload_max_filesize'),
|
||||
@@ -561,7 +561,7 @@ class Media extends Model
|
||||
* @param boolean $ignoreCache Ignore the file list cache.
|
||||
* @return boolean If the file exists on any storage disks.
|
||||
*/
|
||||
public static function fileExistsInStorage(string $fileName, bool $ignoreCache = false)
|
||||
public static function fileExistsInStorage(string $fileName, bool $ignoreCache = false): bool
|
||||
{
|
||||
$disks = array_keys(Config::get('filesystems.disks'));
|
||||
|
||||
@@ -608,7 +608,7 @@ class Media extends Model
|
||||
* @param string $fileName The file name to test.
|
||||
* @return boolean If the file name contains the special suffix.
|
||||
*/
|
||||
public static function fileNameHasSuffix(string $fileName)
|
||||
public static function fileNameHasSuffix(string $fileName): bool
|
||||
{
|
||||
$suffix = '/(-\d+x\d+|-scaled)$/i';
|
||||
$fileNameWithoutExtension = pathinfo($fileName, PATHINFO_FILENAME);
|
||||
@@ -622,7 +622,7 @@ class Media extends Model
|
||||
* @param string $fileName Filename to sanitize.
|
||||
* @return string
|
||||
*/
|
||||
private static function sanitizeFilename(string $fileName)
|
||||
private static function sanitizeFilename(string $fileName): string
|
||||
{
|
||||
/*
|
||||
# file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
|
||||
@@ -27,7 +27,7 @@ class Permission extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function permissions()
|
||||
public function permissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Permission::class);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissionsAttribute()
|
||||
public function getPermissionsAttribute(): array
|
||||
{
|
||||
return $this->permissions()->pluck('permission')->toArray();
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string $permission Permission to test.
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPermission(string $permission)
|
||||
public function hasPermission(string $permission): bool
|
||||
{
|
||||
return ($this->permissions()->where('permission', $permission)->first() !== null);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string|array $permissions The permission(s) to give.
|
||||
* @return Collection
|
||||
*/
|
||||
public function givePermission($permissions)
|
||||
public function givePermission($permissions): Collection
|
||||
{
|
||||
if (is_array($permissions) === false) {
|
||||
$permissions = [$permissions];
|
||||
@@ -139,7 +139,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string|array $permissions The permission(s) to revoke.
|
||||
* @return integer
|
||||
*/
|
||||
public function revokePermission($permissions)
|
||||
public function revokePermission($permissions): int
|
||||
{
|
||||
if (is_array($permissions) === false) {
|
||||
$permissions = [$permissions];
|
||||
@@ -155,7 +155,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function media()
|
||||
public function media(): HasMany
|
||||
{
|
||||
return $this->hasMany(Media::class);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function articles()
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function codes()
|
||||
public function codes(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserCode::class);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function logins()
|
||||
public function logins(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserLogins::class);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function events()
|
||||
public function events(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Event::class, 'event_user', 'user_id', 'event_id');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
@@ -49,7 +49,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function regenerate()
|
||||
public function regenerate(): void
|
||||
{
|
||||
while (true) {
|
||||
$code = random_int(100000, 999999);
|
||||
@@ -65,7 +65,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearExpired()
|
||||
public static function clearExpired(): void
|
||||
{
|
||||
UserCode::where('updated_at', '<=', now()->subDays(5))->delete();
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class UserLogins extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class Recaptcha implements Rule
|
||||
* @param mixed $value Attribute value.
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes(mixed $attribute, mixed $value)
|
||||
public function passes(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
$endpoint = config('services.google_recaptcha');
|
||||
|
||||
@@ -45,7 +45,7 @@ class Recaptcha implements Rule
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
public function message(): string
|
||||
{
|
||||
return 'Captcha failed. Refresh the page and try again';
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class UniqueFileName implements Rule
|
||||
* @param mixed $value
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
public function passes(string $attribute, $value): bool
|
||||
{
|
||||
return (Media::fileExists($value) === false);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class UniqueFileName implements Rule
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
public function message(): string
|
||||
{
|
||||
return 'The file name already exists.';
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class Uniqueish implements Rule
|
||||
* @param mixed $id The ID to ignore.
|
||||
* @return $this
|
||||
*/
|
||||
public function ignore(mixed $id)
|
||||
public function ignore(mixed $id): static
|
||||
{
|
||||
$this->ignoreId = $id;
|
||||
return $this;
|
||||
@@ -62,7 +62,7 @@ class Uniqueish implements Rule
|
||||
* @param mixed $value The value to compare.
|
||||
* @return boolean
|
||||
*/
|
||||
public function passes(mixed $attribute, mixed $value)
|
||||
public function passes(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
$columnName = ($this->column ?? $attribute);
|
||||
$similarValue = preg_replace('/[^A-Za-z]/', '', strtolower($value));
|
||||
@@ -100,7 +100,7 @@ class Uniqueish implements Rule
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
public function message(): string
|
||||
{
|
||||
return 'The :attribute is similar to one that already exists. Please choose another.';
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class AnimatedGifService
|
||||
* @param integer $dataSize GIF blob size.
|
||||
* @return boolean GIF file/blob is animated.
|
||||
*/
|
||||
public static function isAnimatedGif(string $filenameOrBlob, int $dataSize = 0)
|
||||
public static function isAnimatedGif(string $filenameOrBlob, int $dataSize = 0): bool
|
||||
{
|
||||
$regex = '#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s';
|
||||
$count = 0;
|
||||
@@ -44,7 +44,7 @@ class AnimatedGifService
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function extract(string $filenameOrBlob, int $dataSize = 0, $originalFrames = false)
|
||||
public function extract(string $filenameOrBlob, int $dataSize = 0, bool $originalFrames = false): array
|
||||
{
|
||||
if (self::isAnimatedGif($filenameOrBlob) === false) {
|
||||
return [];
|
||||
@@ -198,7 +198,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param string $filename GIF filename path
|
||||
*/
|
||||
private function parseFramesInfo($filename)
|
||||
private function parseFramesInfo(string $filename)
|
||||
{
|
||||
$this->openFile($filename);
|
||||
$this->parseGifHeader();
|
||||
@@ -278,7 +278,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param integer $type
|
||||
*/
|
||||
private function parseGraphicsExtension($type)
|
||||
private function parseGraphicsExtension(int $type)
|
||||
{
|
||||
$startdata = $this->readByte(2);
|
||||
|
||||
@@ -306,7 +306,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param integer $type
|
||||
*/
|
||||
private function getFrameString($type)
|
||||
private function getFrameString(int $type)
|
||||
{
|
||||
if ($this->checkByte(0x2c)) {
|
||||
$start = $this->pointer;
|
||||
@@ -407,7 +407,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getImageDataByte($type, $start, $length)
|
||||
private function getImageDataByte(string $type, int $start, int $length): string
|
||||
{
|
||||
if ($type == "ext") {
|
||||
return substr($this->frameSources[$this->frameNumber]["graphicsextension"], $start, $length);
|
||||
@@ -427,7 +427,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
private function getImageDataBit($type, $byteIndex, $bitStart, $bitLength)
|
||||
private function getImageDataBit(string $type, int $byteIndex, int $bitStart, int $bitLength): number
|
||||
{
|
||||
if ($type == "ext") {
|
||||
return $this->readBits(ord(substr($this->frameSources[$this->frameNumber]["graphicsextension"], $byteIndex, 1)), $bitStart, $bitLength);
|
||||
@@ -444,7 +444,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function dualByteVal($s)
|
||||
private function dualByteVal(string $s): int
|
||||
{
|
||||
$i = (ord($s[1]) * 256 + ord($s[0]));
|
||||
|
||||
@@ -456,7 +456,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param integer $firstLength
|
||||
*/
|
||||
private function readDataStream($firstLength)
|
||||
private function readDataStream(int $firstLength)
|
||||
{
|
||||
$this->pointerForward($firstLength);
|
||||
$length = $this->readByteInt();
|
||||
@@ -474,7 +474,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
private function openFile($filename)
|
||||
private function openFile(string $filename)
|
||||
{
|
||||
$this->handle = fopen($filename, "rb");
|
||||
$this->pointer = 0;
|
||||
@@ -500,7 +500,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function readByte($byteCount)
|
||||
private function readByte(int $byteCount): string
|
||||
{
|
||||
$data = fread($this->handle, $byteCount);
|
||||
$this->pointer += $byteCount;
|
||||
@@ -513,7 +513,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function readByteInt()
|
||||
private function readByteInt(): int
|
||||
{
|
||||
$data = fread($this->handle, 1);
|
||||
$this->pointer++;
|
||||
@@ -530,7 +530,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
private function readBits($byte, $start, $length)
|
||||
private function readBits(string $byte, int $start, int $length): number
|
||||
{
|
||||
$bin = str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
|
||||
$data = substr($bin, $start, $length);
|
||||
@@ -543,7 +543,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param integer $length
|
||||
*/
|
||||
private function pointerRewind($length)
|
||||
private function pointerRewind(int $length)
|
||||
{
|
||||
$this->pointer -= $length;
|
||||
fseek($this->handle, $this->pointer);
|
||||
@@ -554,7 +554,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @param integer $length
|
||||
*/
|
||||
private function pointerForward($length)
|
||||
private function pointerForward(int $length)
|
||||
{
|
||||
$this->pointer += $length;
|
||||
fseek($this->handle, $this->pointer);
|
||||
@@ -568,7 +568,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function dataPart($start, $length)
|
||||
private function dataPart(int $start, int $length): string
|
||||
{
|
||||
fseek($this->handle, $start);
|
||||
$data = fread($this->handle, $length);
|
||||
@@ -584,7 +584,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkByte($byte)
|
||||
private function checkByte(int $byte): bool
|
||||
{
|
||||
if (fgetc($this->handle) == chr($byte)) {
|
||||
fseek($this->handle, $this->pointer);
|
||||
@@ -601,7 +601,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkEOF()
|
||||
private function checkEOF(): bool
|
||||
{
|
||||
if (fgetc($this->handle) === false) {
|
||||
return true;
|
||||
@@ -631,7 +631,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getTotalDuration()
|
||||
public function getTotalDuration(): int
|
||||
{
|
||||
return $this->totalDuration;
|
||||
}
|
||||
@@ -641,7 +641,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getFrameNumber()
|
||||
public function getFrameNumber(): int
|
||||
{
|
||||
return $this->frameNumber;
|
||||
}
|
||||
@@ -651,7 +651,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFrames()
|
||||
public function getFrames(): array
|
||||
{
|
||||
return $this->frames;
|
||||
}
|
||||
@@ -661,7 +661,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFramePositions()
|
||||
public function getFramePositions(): array
|
||||
{
|
||||
return $this->framePositions;
|
||||
}
|
||||
@@ -671,7 +671,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFrameDimensions()
|
||||
public function getFrameDimensions(): array
|
||||
{
|
||||
return $this->frameDimensions;
|
||||
}
|
||||
@@ -681,7 +681,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFrameImages()
|
||||
public function getFrameImages(): array
|
||||
{
|
||||
return $this->frameImages;
|
||||
}
|
||||
@@ -691,7 +691,7 @@ class GifFrameExtractor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFrameDurations()
|
||||
public function getFrameDurations(): array
|
||||
{
|
||||
return $this->frameDurations;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ trait Uuids
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function bootUuids()
|
||||
protected static function bootUuids(): void
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (empty($model->{$model->getKeyName()}) === true) {
|
||||
@@ -25,7 +25,7 @@ trait Uuids
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIncrementing()
|
||||
public function getIncrementing(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ trait Uuids
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyType()
|
||||
public function getKeyType(): string
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class UserFactory extends Factory
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function unverified()
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
|
||||
Reference in New Issue
Block a user