1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-04-17 13:12:15 +02:00

Large code cleanup and formatting of existing app code

This commit is contained in:
Kovah 2022-07-20 21:16:53 +02:00
parent 121cf4bd57
commit b38bb3b72f
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
31 changed files with 10 additions and 364 deletions

View File

@ -137,8 +137,10 @@ class LinkController extends Controller
return redirect()->route('links.show', ['link' => $link]);
}
public function markWorking(MarkLinkWorkingRequest $request, Link $link): RedirectResponse
public function markWorking(Link $link): RedirectResponse
{
$this->authorize('update', $link);
$link->status = Link::STATUS_OK;
$link->save();

View File

@ -7,16 +7,8 @@ use Illuminate\Http\Request;
class GuestAccess
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next): mixed
{
// Check for logged-in users
if (auth()->check()) {
return redirect()->route('dashboard');
}

View File

@ -8,14 +8,7 @@ use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null): mixed
{
if (Auth::guard($guard)->check()) {

View File

@ -11,7 +11,7 @@ class RegisterRequest extends FormRequest
{
use PasswordValidationRules;
public function rules(Request $request): array
public function rules(): array
{
return array_merge(['token' => ['required']], CreateNewUser::rules());
}

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class DoImportRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -8,21 +8,6 @@ use Illuminate\Validation\Rule;
class LinkStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -11,12 +11,6 @@ class LinkUpdateRequest extends FormRequest
{
private bool $requireUniqueUrl = false;
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request): bool
{
if ($request->input('url') !== null) {
@ -26,11 +20,6 @@ class LinkUpdateRequest extends FormRequest
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [

View File

@ -7,21 +7,6 @@ use Illuminate\Foundation\Http\FormRequest;
class ListStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -11,12 +11,6 @@ class ListUpdateRequest extends FormRequest
{
private bool $requireUniqueName = false;
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request): bool
{
if ($request->input('name') !== null) {
@ -26,11 +20,6 @@ class ListUpdateRequest extends FormRequest
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [

View File

@ -1,19 +0,0 @@
<?php
namespace App\Http\Requests\Models;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
class MarkLinkWorkingRequest extends FormRequest
{
public function authorize(Request $request): bool
{
return $request->user()->can('update', $request->link);
}
public function rules(): array
{
return [];
}
}

View File

@ -9,22 +9,11 @@ use Illuminate\Http\Request;
class NoteStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request): bool
{
return $request->user()->can('view', Link::find($request->input('link_id')));
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -8,22 +8,11 @@ use Illuminate\Http\Request;
class NoteUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request): bool
{
return $request->user()->can('view', $request->route('note')->link);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -8,21 +8,6 @@ use Illuminate\Validation\Rule;
class TagStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -11,12 +11,6 @@ class TagUpdateRequest extends FormRequest
{
private bool $requireUniqueName = false;
/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request): bool
{
if ($request->input('name') !== null) {
@ -26,11 +20,6 @@ class TagUpdateRequest extends FormRequest
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [

View File

@ -7,21 +7,11 @@ use Illuminate\Http\Request;
class ToggleLinkCheckRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(Request $request): bool
{
return $request->user()->can('update', $request->link);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -7,21 +7,6 @@ use Illuminate\Foundation\Http\FormRequest;
class SearchRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
@ -46,11 +31,6 @@ class SearchRequest extends FormRequest
];
}
/**
* Specifies custom error messages for the special validations.
*
* @return array
*/
public function messages(): array
{
return [

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class SetupDatabaseRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class SystemSettingsUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class TrashClearRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class TrashRestoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -6,21 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
class UserSettingsUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [

View File

@ -14,20 +14,10 @@ class SaveLinkToWaybackmachine implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @param Link $link
*/
public function __construct(protected Link $link)
{
}
/**
* Notify the Wayback Machine about the link
*
* @return void
*/
public function handle(): void
{
WaybackMachine::saveToArchive($this->link->url);

View File

@ -181,12 +181,6 @@ class Link extends Model implements Auditable
return preg_replace('/http(s)?:\/\//', '', Str::limit(trim($this->url, '/'), $maxLength));
}
/**
* Get the title shortened to max 50 characters
*
* @param int $maxLength
* @return string
*/
public function shortTitle(int $maxLength = 50): string
{
return Str::limit($this->title, $maxLength);
@ -231,11 +225,6 @@ class Link extends Model implements Auditable
]);
}
/**
* Output a relative time inside a span with real time information
*
* @return string
*/
public function addedAt(): string
{
$output = '<time-ago class="cursor-help"';

View File

@ -71,11 +71,6 @@ class Note extends Model
* METHODS
*/
/**
* Get the formatted note content of the note
*
* @return string
*/
public function getFormattedNoteAttribute(): string
{
if ($this->note === null) {
@ -89,11 +84,6 @@ class Note extends Model
return Str::markdown($this->note, ['html_input' => 'escape']);
}
/**
* Output a relative time inside a span with real time information
*
* @return string
*/
public function addedAt(): string
{
$output = '<time-ago class="cursor-help"';

View File

@ -181,7 +181,7 @@ class LinkRepository
/**
* Tags or lists are passed as comma-delimited strings or integers.
* If integers are passed we assume that the tags or lists are referenced
* by their ID. n that case we try to retrieve the tag or list by the
* by their ID. In that case we try to retrieve the tag or list by the
* provided ID.
* If tags or lists are passed as strings, we create them and pass the new
* entity to the taxonomy list.

View File

@ -8,10 +8,6 @@ use Illuminate\Support\Facades\Log;
class ListRepository
{
/**
* @param array $data
* @return LinkList
*/
public static function create(array $data): LinkList
{
$data['user_id'] = auth()->user()->id;
@ -20,11 +16,6 @@ class ListRepository
return LinkList::create($data);
}
/**
* @param LinkList $list
* @param array $data
* @return LinkList
*/
public static function update(LinkList $list, array $data): LinkList
{
$data['name'] = str_replace(',', '', $data['name']);
@ -34,10 +25,6 @@ class ListRepository
return $list;
}
/**
* @param LinkList $list
* @return bool
*/
public static function delete(LinkList $list): bool
{
try {

View File

@ -8,10 +8,6 @@ use Illuminate\Support\Facades\Log;
class NoteRepository
{
/**
* @param array $data
* @return Note
*/
public static function create(array $data): Note
{
$data['user_id'] = auth()->user()->id;
@ -19,11 +15,6 @@ class NoteRepository
return Note::create($data);
}
/**
* @param Note $note
* @param array $data
* @return Note
*/
public static function update(Note $note, array $data): Note
{
$note->update($data);
@ -31,10 +22,6 @@ class NoteRepository
return $note;
}
/**
* @param Note $note
* @return bool
*/
public static function delete(Note $note): bool
{
try {

View File

@ -8,10 +8,6 @@ use Illuminate\Support\Facades\Log;
class TagRepository
{
/**
* @param array $data
* @return Tag
*/
public static function create(array $data): Tag
{
$data['user_id'] = auth()->user()->id;
@ -20,11 +16,6 @@ class TagRepository
return Tag::create($data);
}
/**
* @param Tag $tag
* @param array $data
* @return Tag
*/
public static function update(Tag $tag, array $data): Tag
{
$data['name'] = str_replace(',', '', $data['name']);
@ -34,10 +25,6 @@ class TagRepository
return $tag;
}
/**
* @param Tag $tag
* @return bool
*/
public static function delete(Tag $tag): bool
{
try {

View File

@ -7,23 +7,6 @@ use Illuminate\Contracts\Validation\Rule;
class ModelVisibility implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
return in_array((int)$value, [
@ -33,12 +16,7 @@ class ModelVisibility implements Rule
], true);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return trans('validation.custom.visibility.visibility');
}

View File

@ -8,13 +8,6 @@ use Illuminate\Database\Eloquent\Scope;
class OrderNameScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param Builder $builder
* @param Model $model
* @return void
*/
public function apply(Builder $builder, Model $model): void
{
$builder->orderBy('name');

View File

@ -27,14 +27,11 @@ class VisibilityToggle extends Component
'internal' => $internal,
'private' => $private,
'publicSelected' => old('visibility', $this->existingValue) === $public
|| (old('visibility',
$this->existingValue) === null && usersettings($this->visibilitySetting) === $public),
|| (old('visibility', $this->existingValue) === null && usersettings($this->visibilitySetting) === $public),
'internalSelected' => old('visibility', $this->existingValue) === $internal
|| (old('visibility',
$this->existingValue) === null && usersettings($this->visibilitySetting) === $internal),
|| (old('visibility', $this->existingValue) === null && usersettings($this->visibilitySetting) === $internal),
'privateSelected' => old('visibility', $this->existingValue) === $private
|| (old('visibility',
$this->existingValue) === null && usersettings($this->visibilitySetting) === $private),
|| (old('visibility', $this->existingValue) === null && usersettings($this->visibilitySetting) === $private),
]);
}
}