Merge pull request #670 from jonnybarnes/develop

MTM: Laravel 10
This commit is contained in:
Jonny Barnes 2023-02-18 10:03:06 +00:00 committed by GitHub
commit fcf0b4a778
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
163 changed files with 2959 additions and 3146 deletions

View file

@ -5,17 +5,23 @@ root = true
# Unix-style newlines with a newline ending every file # Unix-style newlines with a newline ending every file
[*] [*]
end_of_line = lf
charset = utf-8 charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
indent_style = space
indent_size = 4
# Tab indentation # Tab indentation
[Makefile] [Makefile]
indent_style = tab indent_style = tab
tab_width = 4 tab_width = 4
[yml] [*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2 indent_size = 2
[docker-compose.yml]
indent_size = 4

View file

@ -25,22 +25,10 @@ class MigratePlaceDataFromPostgis extends Command
*/ */
protected $description = 'Copy Postgis data to normal latitude longitude fields'; protected $description = 'Copy Postgis data to normal latitude longitude fields';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/** /**
* Execute the console command. * Execute the console command.
*
* @return int
*/ */
public function handle() public function handle(): int
{ {
$locationColumn = DB::selectOne(DB::raw(" $locationColumn = DB::selectOne(DB::raw("
SELECT EXISTS ( SELECT EXISTS (

View file

@ -6,6 +6,7 @@ namespace App\Console\Commands;
use App\Models\WebMention; use App\Models\WebMention;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\FileSystem\FileSystem; use Illuminate\FileSystem\FileSystem;
class ParseCachedWebMentions extends Command class ParseCachedWebMentions extends Command
@ -27,9 +28,9 @@ class ParseCachedWebMentions extends Command
/** /**
* Execute the console command. * Execute the console command.
* *
* @return mixed * @throws FileNotFoundException
*/ */
public function handle(FileSystem $filesystem) public function handle(FileSystem $filesystem): void
{ {
$htmlFiles = $filesystem->allFiles(storage_path() . '/HTML'); $htmlFiles = $filesystem->allFiles(storage_path() . '/HTML');
foreach ($htmlFiles as $file) { foreach ($htmlFiles as $file) {
@ -49,9 +50,6 @@ class ParseCachedWebMentions extends Command
/** /**
* Determine the source URL from a filename. * Determine the source URL from a filename.
*
* @param string
* @return string
*/ */
private function urlFromFilename(string $filepath): string private function urlFromFilename(string $filepath): string
{ {

View file

@ -24,22 +24,10 @@ class ReDownloadWebMentions extends Command
*/ */
protected $description = 'Redownload the HTML content of webmentions'; protected $description = 'Redownload the HTML content of webmentions';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/** /**
* Execute the console command. * Execute the console command.
*
* @return mixed
*/ */
public function handle() public function handle(): void
{ {
$webmentions = WebMention::all(); $webmentions = WebMention::all();
foreach ($webmentions as $webmention) { foreach ($webmentions as $webmention) {

View file

@ -10,7 +10,7 @@ class Kernel extends ConsoleKernel
/** /**
* The Artisan commands provided by your application. * The Artisan commands provided by your application.
* *
* @var array * @var array<int, string>
*/ */
protected $commands = [ protected $commands = [
Commands\ParseCachedWebMentions::class, Commands\ParseCachedWebMentions::class,
@ -20,22 +20,18 @@ class Kernel extends ConsoleKernel
/** /**
* Define the application's command schedule. * Define the application's command schedule.
* *
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule): void
{ {
$schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('cache:prune-stale-tags')->hourly();
} }
/** /**
* Register the commands for the application. * Register the commands for the application.
*
* @return void
*/ */
protected function commands() protected function commands(): void
{ {
$this->load(__DIR__ . '/Commands'); $this->load(__DIR__ . '/Commands');

View file

@ -21,47 +21,34 @@ class Handler extends ExceptionHandler
/** /**
* A list of the exception types that are not reported. * A list of the exception types that are not reported.
* *
* @var array * @var array<int, class-string<\Throwable>>
*/ */
protected $dontReport = [ protected $dontReport = [
NotFoundHttpException::class, NotFoundHttpException::class,
ModelNotFoundException::class, ModelNotFoundException::class,
]; ];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/** /**
* Report or log an exception. * Report or log an exception.
* *
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
* *
* @param Throwable $throwable
* @return void
*
* @throws Exception * @throws Exception
* @throws Throwable * @throws Throwable
*/ */
public function report(Throwable $throwable) public function report(Throwable $e): void
{ {
parent::report($throwable); parent::report($e);
if (config('logging.slack') && $this->shouldReport($throwable)) { if (config('logging.slack') && $this->shouldReport($e)) {
$guzzle = new Client([ $guzzle = new Client([
'headers' => [ 'headers' => [
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
], ],
]); ]);
$exceptionName = get_class($throwable) ?? 'Unknown Exception'; $exceptionName = get_class($e) ?? 'Unknown Exception';
$title = $exceptionName . ': ' . $throwable->getMessage(); $title = $exceptionName . ': ' . $e->getMessage();
$guzzle->post( $guzzle->post(
config('logging.slack'), config('logging.slack'),
@ -89,7 +76,6 @@ class Handler extends ExceptionHandler
* Render an exception into an HTTP response. * Render an exception into an HTTP response.
* *
* @param Request $request * @param Request $request
* @param Throwable $throwable
* @return Response * @return Response
* *
* @throws Throwable * @throws Throwable

View file

@ -14,8 +14,6 @@ class ClientsController extends Controller
{ {
/** /**
* Show a list of known clients. * Show a list of known clients.
*
* @return \Illuminate\View\View
*/ */
public function index(): View public function index(): View
{ {
@ -26,8 +24,6 @@ class ClientsController extends Controller
/** /**
* Show form to add a client name. * Show form to add a client name.
*
* @return \Illuminate\View\View
*/ */
public function create(): View public function create(): View
{ {
@ -36,8 +32,6 @@ class ClientsController extends Controller
/** /**
* Process the request to adda new client name. * Process the request to adda new client name.
*
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(): RedirectResponse public function store(): RedirectResponse
{ {
@ -51,9 +45,6 @@ class ClientsController extends Controller
/** /**
* Show a form to edit a client name. * Show a form to edit a client name.
*
* @param int $clientId
* @return \Illuminate\View\View
*/ */
public function edit(int $clientId): View public function edit(int $clientId): View
{ {
@ -68,9 +59,6 @@ class ClientsController extends Controller
/** /**
* Process the request to edit a client name. * Process the request to edit a client name.
*
* @param int $clientId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function update(int $clientId): RedirectResponse public function update(int $clientId): RedirectResponse
{ {
@ -84,9 +72,6 @@ class ClientsController extends Controller
/** /**
* Process a request to delete a client. * Process a request to delete a client.
*
* @param int $clientId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy(int $clientId): RedirectResponse public function destroy(int $clientId): RedirectResponse
{ {

View file

@ -17,8 +17,6 @@ class ContactsController extends Controller
{ {
/** /**
* List the currect contacts that can be edited. * List the currect contacts that can be edited.
*
* @return \Illuminate\View\View
*/ */
public function index(): View public function index(): View
{ {
@ -29,8 +27,6 @@ class ContactsController extends Controller
/** /**
* Display the form to add a new contact. * Display the form to add a new contact.
*
* @return \Illuminate\View\View
*/ */
public function create(): View public function create(): View
{ {
@ -39,8 +35,6 @@ class ContactsController extends Controller
/** /**
* Process the request to add a new contact. * Process the request to add a new contact.
*
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(): RedirectResponse public function store(): RedirectResponse
{ {
@ -57,9 +51,6 @@ class ContactsController extends Controller
/** /**
* Show the form to edit an existing contact. * Show the form to edit an existing contact.
*
* @param int $contactId
* @return \Illuminate\View\View
*/ */
public function edit(int $contactId): View public function edit(int $contactId): View
{ {
@ -72,9 +63,6 @@ class ContactsController extends Controller
* Process the request to edit a contact. * Process the request to edit a contact.
* *
* @todo Allow saving profile pictures for people without homepages * @todo Allow saving profile pictures for people without homepages
*
* @param int $contactId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function update(int $contactId): RedirectResponse public function update(int $contactId): RedirectResponse
{ {
@ -101,9 +89,6 @@ class ContactsController extends Controller
/** /**
* Process the request to delete a contact. * Process the request to delete a contact.
*
* @param int $contactId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy(int $contactId): RedirectResponse public function destroy(int $contactId): RedirectResponse
{ {
@ -119,7 +104,6 @@ class ContactsController extends Controller
* This method attempts to find the microformat marked-up profile image * This method attempts to find the microformat marked-up profile image
* from a given homepage and save it accordingly * from a given homepage and save it accordingly
* *
* @param int $contactId
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/ */
public function getAvatar(int $contactId) public function getAvatar(int $contactId)

View file

@ -11,8 +11,6 @@ class HomeController extends Controller
{ {
/** /**
* Show the homepage of the admin CP. * Show the homepage of the admin CP.
*
* @return \Illuminate\View\View
*/ */
public function welcome(): View public function welcome(): View
{ {

View file

@ -14,8 +14,6 @@ class LikesController extends Controller
{ {
/** /**
* List the likes that can be edited. * List the likes that can be edited.
*
* @return \Illuminate\View\View
*/ */
public function index(): View public function index(): View
{ {
@ -26,8 +24,6 @@ class LikesController extends Controller
/** /**
* Show the form to make a new like. * Show the form to make a new like.
*
* @return \Illuminate\View\View
*/ */
public function create(): View public function create(): View
{ {
@ -36,8 +32,6 @@ class LikesController extends Controller
/** /**
* Process a request to make a new like. * Process a request to make a new like.
*
* @return \Illuminate\Http\RedirectResponse
*/ */
public function store(): RedirectResponse public function store(): RedirectResponse
{ {
@ -51,9 +45,6 @@ class LikesController extends Controller
/** /**
* Display the form to edit a specific like. * Display the form to edit a specific like.
*
* @param int $likeId
* @return \Illuminate\View\View
*/ */
public function edit(int $likeId): View public function edit(int $likeId): View
{ {
@ -67,9 +58,6 @@ class LikesController extends Controller
/** /**
* Process a request to edit a like. * Process a request to edit a like.
*
* @param int $likeId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function update(int $likeId): RedirectResponse public function update(int $likeId): RedirectResponse
{ {
@ -83,9 +71,6 @@ class LikesController extends Controller
/** /**
* Process the request to delete a like. * Process the request to delete a like.
*
* @param int $likeId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy(int $likeId): RedirectResponse public function destroy(int $likeId): RedirectResponse
{ {

View file

@ -15,8 +15,6 @@ class NotesController extends Controller
{ {
/** /**
* List the notes that can be edited. * List the notes that can be edited.
*
* @return \Illuminate\View\View
*/ */
public function index(): View public function index(): View
{ {
@ -30,8 +28,6 @@ class NotesController extends Controller
/** /**
* Show the form to make a new note. * Show the form to make a new note.
*
* @return \Illuminate\View\View
*/ */
public function create(): View public function create(): View
{ {
@ -40,9 +36,6 @@ class NotesController extends Controller
/** /**
* Process a request to make a new note. * Process a request to make a new note.
*
* @param Request $request
* @return RedirectResponse
*/ */
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
{ {
@ -56,9 +49,6 @@ class NotesController extends Controller
/** /**
* Display the form to edit a specific note. * Display the form to edit a specific note.
*
* @param int $noteId
* @return \Illuminate\View\View
*/ */
public function edit(int $noteId): View public function edit(int $noteId): View
{ {
@ -71,9 +61,6 @@ class NotesController extends Controller
/** /**
* Process a request to edit a note. Easy since this can only be done * Process a request to edit a note. Easy since this can only be done
* from the admin CP. * from the admin CP.
*
* @param int $noteId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function update(int $noteId): RedirectResponse public function update(int $noteId): RedirectResponse
{ {
@ -92,9 +79,6 @@ class NotesController extends Controller
/** /**
* Delete the note. * Delete the note.
*
* @param int $noteId
* @return \Illuminate\Http\RedirectResponse
*/ */
public function destroy(int $noteId): RedirectResponse public function destroy(int $noteId): RedirectResponse
{ {

View file

@ -21,8 +21,6 @@ class PlacesController extends Controller
/** /**
* List the places that can be edited. * List the places that can be edited.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -33,8 +31,6 @@ class PlacesController extends Controller
/** /**
* Show the form to make a new place. * Show the form to make a new place.
*
* @return View
*/ */
public function create(): View public function create(): View
{ {
@ -43,8 +39,6 @@ class PlacesController extends Controller
/** /**
* Process a request to make a new place. * Process a request to make a new place.
*
* @return RedirectResponse
*/ */
public function store(): RedirectResponse public function store(): RedirectResponse
{ {
@ -62,9 +56,6 @@ class PlacesController extends Controller
/** /**
* Display the form to edit a specific place. * Display the form to edit a specific place.
*
* @param int $placeId
* @return View
*/ */
public function edit(int $placeId): View public function edit(int $placeId): View
{ {
@ -75,9 +66,6 @@ class PlacesController extends Controller
/** /**
* Process a request to edit a place. * Process a request to edit a place.
*
* @param int $placeId
* @return RedirectResponse
*/ */
public function update(int $placeId): RedirectResponse public function update(int $placeId): RedirectResponse
{ {
@ -94,9 +82,6 @@ class PlacesController extends Controller
/** /**
* List the places we can merge with the current place. * List the places we can merge with the current place.
*
* @param int $placeId
* @return View
*/ */
public function mergeIndex(int $placeId): View public function mergeIndex(int $placeId): View
{ {
@ -114,10 +99,6 @@ class PlacesController extends Controller
/** /**
* Show a form for merging two specific places. * Show a form for merging two specific places.
*
* @param int $placeId1
* @param int $placeId2
* @return View
*/ */
public function mergeEdit(int $placeId1, int $placeId2): View public function mergeEdit(int $placeId1, int $placeId2): View
{ {
@ -129,8 +110,6 @@ class PlacesController extends Controller
/** /**
* Process the request to merge two places. * Process the request to merge two places.
*
* @return RedirectResponse
*/ */
public function mergeStore(): RedirectResponse public function mergeStore(): RedirectResponse
{ {

View file

@ -14,8 +14,6 @@ class SyndicationTargetsController extends Controller
{ {
/** /**
* Show a list of known syndication targets. * Show a list of known syndication targets.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -26,8 +24,6 @@ class SyndicationTargetsController extends Controller
/** /**
* Show form to add a syndication target. * Show form to add a syndication target.
*
* @return View
*/ */
public function create(): View public function create(): View
{ {
@ -36,9 +32,6 @@ class SyndicationTargetsController extends Controller
/** /**
* Process the request to adda new syndication target. * Process the request to adda new syndication target.
*
* @param Request $request
* @return RedirectResponse
*/ */
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
{ {
@ -60,9 +53,6 @@ class SyndicationTargetsController extends Controller
/** /**
* Show a form to edit a syndication target. * Show a form to edit a syndication target.
*
* @param SyndicationTarget $syndicationTarget
* @return View
*/ */
public function edit(SyndicationTarget $syndicationTarget): View public function edit(SyndicationTarget $syndicationTarget): View
{ {
@ -73,10 +63,6 @@ class SyndicationTargetsController extends Controller
/** /**
* Process the request to edit a client name. * Process the request to edit a client name.
*
* @param Request $request
* @param SyndicationTarget $syndicationTarget
* @return RedirectResponse
*/ */
public function update(Request $request, SyndicationTarget $syndicationTarget): RedirectResponse public function update(Request $request, SyndicationTarget $syndicationTarget): RedirectResponse
{ {
@ -98,9 +84,6 @@ class SyndicationTargetsController extends Controller
/** /**
* Process a request to delete a client. * Process a request to delete a client.
*
* @param SyndicationTarget $syndicationTarget
* @return RedirectResponse
*/ */
public function destroy(SyndicationTarget $syndicationTarget): RedirectResponse public function destroy(SyndicationTarget $syndicationTarget): RedirectResponse
{ {

View file

@ -14,10 +14,6 @@ class ArticlesController extends Controller
{ {
/** /**
* Show all articles (with pagination). * Show all articles (with pagination).
*
* @param int|null $year
* @param int|null $month
* @return View
*/ */
public function index(int $year = null, int $month = null): View public function index(int $year = null, int $month = null): View
{ {
@ -31,13 +27,8 @@ class ArticlesController extends Controller
/** /**
* Show a single article. * Show a single article.
*
* @param int $year
* @param int $month
* @param string $slug
* @return RedirectResponse|View
*/ */
public function show(int $year, int $month, string $slug) public function show(int $year, int $month, string $slug): RedirectResponse|View
{ {
try { try {
$article = Article::where('titleurl', $slug)->firstOrFail(); $article = Article::where('titleurl', $slug)->firstOrFail();
@ -56,11 +47,7 @@ class ArticlesController extends Controller
} }
/** /**
* We only have the ID, work out post title, year and month * We only have the ID, work out post title, year and month and redirect to it.
* and redirect to it.
*
* @param string $idFromUrl
* @return RedirectResponse
*/ */
public function onlyIdInUrl(string $idFromUrl): RedirectResponse public function onlyIdInUrl(string $idFromUrl): RedirectResponse
{ {

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\View\View; use Illuminate\View\View;
@ -12,10 +13,8 @@ class AuthController extends Controller
{ {
/** /**
* Show the login form. * Show the login form.
*
* @return View|RedirectResponse
*/ */
public function showLogin() public function showLogin(): View|RedirectResponse
{ {
if (Auth::check()) { if (Auth::check()) {
return redirect('/'); return redirect('/');
@ -25,14 +24,11 @@ class AuthController extends Controller
} }
/** /**
* Log in a user, set a session variable, check credentials against * Log in a user, set a session variable, check credentials against the `.env` file.
* the .env file.
*
* @return RedirectResponse
*/ */
public function login(): RedirectResponse public function login(Request $request): RedirectResponse
{ {
$credentials = request()->only('name', 'password'); $credentials = $request->only('name', 'password');
if (Auth::attempt($credentials, true)) { if (Auth::attempt($credentials, true)) {
return redirect()->intended('/'); return redirect()->intended('/');
@ -42,11 +38,9 @@ class AuthController extends Controller
} }
/** /**
* Show the form to logout a user. * Show the form to allow a user to log-out.
*
* @return View|RedirectResponse
*/ */
public function showLogout() public function showLogout(): View|RedirectResponse
{ {
if (Auth::check() === false) { if (Auth::check() === false) {
// The user is not logged in, just redirect them home // The user is not logged in, just redirect them home
@ -58,8 +52,6 @@ class AuthController extends Controller
/** /**
* Log the user out from their current session. * Log the user out from their current session.
*
* @return RedirectResponse;
*/ */
public function logout(): RedirectResponse public function logout(): RedirectResponse
{ {

View file

@ -11,8 +11,6 @@ class BookmarksController extends Controller
{ {
/** /**
* Show the most recent bookmarks. * Show the most recent bookmarks.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -23,9 +21,6 @@ class BookmarksController extends Controller
/** /**
* Show a single bookmark. * Show a single bookmark.
*
* @param Bookmark $bookmark
* @return View
*/ */
public function show(Bookmark $bookmark): View public function show(Bookmark $bookmark): View
{ {
@ -36,9 +31,6 @@ class BookmarksController extends Controller
/** /**
* Show bookmarks tagged with a specific tag. * Show bookmarks tagged with a specific tag.
*
* @param string $tag
* @return View
*/ */
public function tagged(string $tag): View public function tagged(string $tag): View
{ {

View file

@ -12,8 +12,6 @@ class ContactsController extends Controller
{ {
/** /**
* Show all the contacts. * Show all the contacts.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -33,9 +31,6 @@ class ContactsController extends Controller
/** /**
* Show a single contact. * Show a single contact.
*
* @param Contact $contact
* @return View
*/ */
public function show(Contact $contact): View public function show(Contact $contact): View
{ {

View file

@ -13,8 +13,6 @@ class FeedsController extends Controller
{ {
/** /**
* Returns the blog RSS feed. * Returns the blog RSS feed.
*
* @return Response
*/ */
public function blogRss(): Response public function blogRss(): Response
{ {
@ -28,8 +26,6 @@ class FeedsController extends Controller
/** /**
* Returns the blog Atom feed. * Returns the blog Atom feed.
*
* @return Response
*/ */
public function blogAtom(): Response public function blogAtom(): Response
{ {
@ -42,8 +38,6 @@ class FeedsController extends Controller
/** /**
* Returns the notes RSS feed. * Returns the notes RSS feed.
*
* @return Response
*/ */
public function notesRss(): Response public function notesRss(): Response
{ {
@ -57,8 +51,6 @@ class FeedsController extends Controller
/** /**
* Returns the notes Atom feed. * Returns the notes Atom feed.
*
* @return Response
*/ */
public function notesAtom(): Response public function notesAtom(): Response
{ {
@ -73,8 +65,6 @@ class FeedsController extends Controller
/** /**
* Returns the blog JSON feed. * Returns the blog JSON feed.
*
* @return array
*/ */
public function blogJson(): array public function blogJson(): array
{ {
@ -106,10 +96,8 @@ class FeedsController extends Controller
/** /**
* Returns the notes JSON feed. * Returns the notes JSON feed.
*
* @return array
*/ */
public function notesJson() public function notesJson(): array
{ {
$notes = Note::latest()->with('media')->take(20)->get(); $notes = Note::latest()->with('media')->take(20)->get();
$data = [ $data = [
@ -138,8 +126,6 @@ class FeedsController extends Controller
/** /**
* Returns the blog JF2 feed. * Returns the blog JF2 feed.
*
* @return JsonResponse
*/ */
public function blogJf2(): JsonResponse public function blogJf2(): JsonResponse
{ {
@ -176,8 +162,6 @@ class FeedsController extends Controller
/** /**
* Returns the notes JF2 feed. * Returns the notes JF2 feed.
*
* @return JsonResponse
*/ */
public function notesJf2(): JsonResponse public function notesJf2(): JsonResponse
{ {

View file

@ -7,6 +7,7 @@ use App\Models\Bookmark;
use App\Models\Like; use App\Models\Like;
use App\Models\Note; use App\Models\Note;
use App\Services\ActivityStreamsService; use App\Services\ActivityStreamsService;
use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\View\View; use Illuminate\View\View;
@ -14,12 +15,10 @@ class FrontPageController extends Controller
{ {
/** /**
* Show all the recent activity. * Show all the recent activity.
*
* @return Response|View
*/ */
public function index() public function index(Request $request): Response|View
{ {
if (request()->wantsActivityStream()) { if ($request->wantsActivityStream()) {
return (new ActivityStreamsService())->siteOwnerResponse(); return (new ActivityStreamsService())->siteOwnerResponse();
} }

View file

@ -11,8 +11,6 @@ class LikesController extends Controller
{ {
/** /**
* Show the latest likes. * Show the latest likes.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -23,9 +21,6 @@ class LikesController extends Controller
/** /**
* Show a single like. * Show a single like.
*
* @param Like $like
* @return View
*/ */
public function show(Like $like): View public function show(Like $like): View
{ {

View file

@ -44,9 +44,6 @@ class MicropubController extends Controller
/** /**
* This function receives an API request, verifies the authenticity * This function receives an API request, verifies the authenticity
* then passes over the info to the relevant Service class. * then passes over the info to the relevant Service class.
*
* @param Request $request
* @return JsonResponse
*/ */
public function post(Request $request): JsonResponse public function post(Request $request): JsonResponse
{ {
@ -117,37 +114,35 @@ class MicropubController extends Controller
* token, here we check whether the token is valid and respond * token, here we check whether the token is valid and respond
* appropriately. Further if the request has the query parameter * appropriately. Further if the request has the query parameter
* syndicate-to we respond with the known syndication endpoints. * syndicate-to we respond with the known syndication endpoints.
*
* @return JsonResponse
*/ */
public function get(): JsonResponse public function get(Request $request): JsonResponse
{ {
try { try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token')); $tokenData = $this->tokenService->validateToken($request->input('access_token'));
} catch (RequiredConstraintsViolated|InvalidTokenStructure) { } catch (RequiredConstraintsViolated|InvalidTokenStructure) {
return (new MicropubResponses())->invalidTokenResponse(); return (new MicropubResponses())->invalidTokenResponse();
} }
if (request()->input('q') === 'syndicate-to') { if ($request->input('q') === 'syndicate-to') {
return response()->json([ return response()->json([
'syndicate-to' => SyndicationTarget::all(), 'syndicate-to' => SyndicationTarget::all(),
]); ]);
} }
if (request()->input('q') === 'config') { if ($request->input('q') === 'config') {
return response()->json([ return response()->json([
'syndicate-to' => SyndicationTarget::all(), 'syndicate-to' => SyndicationTarget::all(),
'media-endpoint' => route('media-endpoint'), 'media-endpoint' => route('media-endpoint'),
]); ]);
} }
if (request()->has('q') && substr(request()->input('q'), 0, 4) === 'geo:') { if ($request->has('q') && str_starts_with($request->input('q'), 'geo:')) {
preg_match_all( preg_match_all(
'/([0-9.\-]+)/', '/([0-9.\-]+)/',
request()->input('q'), $request->input('q'),
$matches $matches
); );
$distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000; $distance = (count($matches[0]) === 3) ? 100 * $matches[0][2] : 1000;
$places = Place::near( $places = Place::near(
(object) ['latitude' => $matches[0][0], 'longitude' => $matches[0][1]], (object) ['latitude' => $matches[0][0], 'longitude' => $matches[0][1]],
$distance $distance
@ -173,23 +168,19 @@ class MicropubController extends Controller
/** /**
* Determine the client id from the access token sent with the request. * Determine the client id from the access token sent with the request.
* *
* @return string
*
* @throws RequiredConstraintsViolated * @throws RequiredConstraintsViolated
*/ */
private function getClientId(): string private function getClientId(): string
{ {
return resolve(TokenService::class) return resolve(TokenService::class)
->validateToken(request()->input('access_token')) ->validateToken(app('request')->input('access_token'))
->claims()->get('client_id'); ->claims()->get('client_id');
} }
/** /**
* Save the details of the micropub request to a log file. * Save the details of the micropub request to a log file.
*
* @param array $request This is the info from request()->all()
*/ */
private function logMicropubRequest(array $request) private function logMicropubRequest(array $request): void
{ {
$logger = new Logger('micropub'); $logger = new Logger('micropub');
$logger->pushHandler(new StreamHandler(storage_path('logs/micropub.log'))); $logger->pushHandler(new StreamHandler(storage_path('logs/micropub.log')));

View file

@ -98,15 +98,13 @@ class MicropubMediaController extends Controller
/** /**
* Process a media item posted to the media endpoint. * Process a media item posted to the media endpoint.
* *
* @return JsonResponse
*
* @throws BindingResolutionException * @throws BindingResolutionException
* @throws Exception * @throws Exception
*/ */
public function media(): JsonResponse public function media(Request $request): JsonResponse
{ {
try { try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token')); $tokenData = $this->tokenService->validateToken($request->input('access_token'));
} catch (RequiredConstraintsViolated|InvalidTokenStructure $exception) { } catch (RequiredConstraintsViolated|InvalidTokenStructure $exception) {
$micropubResponses = new MicropubResponses(); $micropubResponses = new MicropubResponses();
@ -125,7 +123,7 @@ class MicropubMediaController extends Controller
return $micropubResponses->insufficientScopeResponse(); return $micropubResponses->insufficientScopeResponse();
} }
if (request()->hasFile('file') === false) { if ($request->hasFile('file') === false) {
return response()->json([ return response()->json([
'response' => 'error', 'response' => 'error',
'error' => 'invalid_request', 'error' => 'invalid_request',
@ -133,7 +131,7 @@ class MicropubMediaController extends Controller
], 400); ], 400);
} }
if (request()->file('file')->isValid() === false) { if ($request->file('file')->isValid() === false) {
return response()->json([ return response()->json([
'response' => 'error', 'response' => 'error',
'error' => 'invalid_request', 'error' => 'invalid_request',
@ -141,11 +139,11 @@ class MicropubMediaController extends Controller
], 400); ], 400);
} }
$filename = $this->saveFile(request()->file('file')); $filename = $this->saveFile($request->file('file'));
$manager = resolve(ImageManager::class); $manager = resolve(ImageManager::class);
try { try {
$image = $manager->make(request()->file('file')); $image = $manager->make($request->file('file'));
$width = $image->width(); $width = $image->width();
} catch (NotReadableException $exception) { } catch (NotReadableException $exception) {
// not an image // not an image
@ -153,9 +151,9 @@ class MicropubMediaController extends Controller
} }
$media = Media::create([ $media = Media::create([
'token' => request()->bearerToken(), 'token' => $request->bearerToken(),
'path' => 'media/' . $filename, 'path' => 'media/' . $filename,
'type' => $this->getFileTypeFromMimeType(request()->file('file')->getMimeType()), 'type' => $this->getFileTypeFromMimeType($request->file('file')->getMimeType()),
'image_widths' => $width, 'image_widths' => $width,
]); ]);
@ -176,8 +174,6 @@ class MicropubMediaController extends Controller
/** /**
* Return the relevant CORS headers to a pre-flight OPTIONS request. * Return the relevant CORS headers to a pre-flight OPTIONS request.
*
* @return Response
*/ */
public function mediaOptionsResponse(): Response public function mediaOptionsResponse(): Response
{ {
@ -186,9 +182,6 @@ class MicropubMediaController extends Controller
/** /**
* Get the file type from the mime-type of the uploaded file. * Get the file type from the mime-type of the uploaded file.
*
* @param string $mimeType
* @return string
*/ */
private function getFileTypeFromMimeType(string $mimeType): string private function getFileTypeFromMimeType(string $mimeType): string
{ {
@ -232,9 +225,6 @@ class MicropubMediaController extends Controller
/** /**
* Save an uploaded file to the local disk. * Save an uploaded file to the local disk.
* *
* @param UploadedFile $file
* @return string
*
* @throws Exception * @throws Exception
*/ */
private function saveFile(UploadedFile $file): string private function saveFile(UploadedFile $file): string

View file

@ -9,6 +9,7 @@ use App\Services\ActivityStreamsService;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\View\View; use Illuminate\View\View;
use Jonnybarnes\IndieWeb\Numbers; use Jonnybarnes\IndieWeb\Numbers;
@ -19,12 +20,10 @@ class NotesController extends Controller
{ {
/** /**
* Show all the notes. This is also the homepage. * Show all the notes. This is also the homepage.
*
* @return View|Response
*/ */
public function index() public function index(Request $request): View|Response
{ {
if (request()->wantsActivityStream()) { if ($request->wantsActivityStream()) {
return (new ActivityStreamsService())->siteOwnerResponse(); return (new ActivityStreamsService())->siteOwnerResponse();
} }
@ -39,11 +38,8 @@ class NotesController extends Controller
/** /**
* Show a single note. * Show a single note.
*
* @param string $urlId The id of the note
* @return View|JsonResponse|Response
*/ */
public function show(string $urlId) public function show(string $urlId): View|JsonResponse|Response
{ {
try { try {
$note = Note::nb60($urlId)->with('webmentions')->firstOrFail(); $note = Note::nb60($urlId)->with('webmentions')->firstOrFail();
@ -60,9 +56,6 @@ class NotesController extends Controller
/** /**
* Redirect /note/{decID} to /notes/{nb60id}. * Redirect /note/{decID} to /notes/{nb60id}.
*
* @param int $decId The decimal id of the note
* @return RedirectResponse
*/ */
public function redirect(int $decId): RedirectResponse public function redirect(int $decId): RedirectResponse
{ {
@ -71,9 +64,6 @@ class NotesController extends Controller
/** /**
* Show all notes tagged with {tag}. * Show all notes tagged with {tag}.
*
* @param string $tag
* @return View
*/ */
public function tagged(string $tag): View public function tagged(string $tag): View
{ {
@ -88,8 +78,6 @@ class NotesController extends Controller
* Page to create a new note. * Page to create a new note.
* *
* Dummy page for now. * Dummy page for now.
*
* @return View
*/ */
public function create(): View public function create(): View
{ {

View file

@ -11,8 +11,6 @@ class PlacesController extends Controller
{ {
/** /**
* Show all the places. * Show all the places.
*
* @return View
*/ */
public function index(): View public function index(): View
{ {
@ -23,9 +21,6 @@ class PlacesController extends Controller
/** /**
* Show a specific place. * Show a specific place.
*
* @param Place $place
* @return View
*/ */
public function show(Place $place): View public function show(Place $place): View
{ {

View file

@ -19,8 +19,6 @@ class ShortURLsController extends Controller
/** /**
* Redirect from '/' to the long url. * Redirect from '/' to the long url.
*
* @return RedirectResponse
*/ */
public function baseURL(): RedirectResponse public function baseURL(): RedirectResponse
{ {
@ -29,8 +27,6 @@ class ShortURLsController extends Controller
/** /**
* Redirect from '/@' to a twitter profile. * Redirect from '/@' to a twitter profile.
*
* @return RedirectResponse
*/ */
public function twitter(): RedirectResponse public function twitter(): RedirectResponse
{ {
@ -39,18 +35,15 @@ class ShortURLsController extends Controller
/** /**
* Redirect a short url of this site out to a long one based on post type. * Redirect a short url of this site out to a long one based on post type.
* Further redirects may happen.
* *
* @param string Post type * Further redirects may happen.
* @param string Post ID
* @return RedirectResponse
*/ */
public function expandType(string $type, string $postId): RedirectResponse public function expandType(string $type, string $postId): RedirectResponse
{ {
if ($type == 't') { if ($type === 't') {
$type = 'notes'; $type = 'notes';
} }
if ($type == 'b') { if ($type === 'b') {
$type = 'blog/s'; $type = 'blog/s';
} }

View file

@ -24,17 +24,10 @@ class TokenEndpointController extends Controller
*/ */
protected GuzzleClient $guzzle; protected GuzzleClient $guzzle;
/**
* @var TokenService The Token handling service.
*/
protected TokenService $tokenService; protected TokenService $tokenService;
/** /**
* Inject the dependencies. * Inject the dependencies.
*
* @param Client $client
* @param GuzzleClient $guzzle
* @param TokenService $tokenService
*/ */
public function __construct( public function __construct(
Client $client, Client $client,
@ -48,9 +41,6 @@ class TokenEndpointController extends Controller
/** /**
* If the user has authd via the IndieAuth protocol, issue a valid token. * If the user has authd via the IndieAuth protocol, issue a valid token.
*
* @param Request $request
* @return JsonResponse
*/ */
public function create(Request $request): JsonResponse public function create(Request $request): JsonResponse
{ {

View file

@ -7,6 +7,7 @@ namespace App\Http\Controllers;
use App\Jobs\ProcessWebMention; use App\Jobs\ProcessWebMention;
use App\Models\Note; use App\Models\Note;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\View\View; use Illuminate\View\View;
use Jonnybarnes\IndieWeb\Numbers; use Jonnybarnes\IndieWeb\Numbers;
@ -18,8 +19,6 @@ class WebMentionsController extends Controller
* *
* This is probably someone looking for information about what * This is probably someone looking for information about what
* webmentions are, or about my particular implementation. * webmentions are, or about my particular implementation.
*
* @return View
*/ */
public function get(): View public function get(): View
{ {
@ -28,13 +27,11 @@ class WebMentionsController extends Controller
/** /**
* Receive and process a webmention. * Receive and process a webmention.
*
* @return Response
*/ */
public function receive(): Response public function receive(Request $request): Response
{ {
//first we trivially reject requests that lack all required inputs //first we trivially reject requests that lack all required inputs
if ((request()->has('target') !== true) || (request()->has('source') !== true)) { if (($request->has('target') !== true) || ($request->has('source') !== true)) {
return response( return response(
'You need both the target and source parameters', 'You need both the target and source parameters',
400 400
@ -42,15 +39,15 @@ class WebMentionsController extends Controller
} }
//next check the $target is valid //next check the $target is valid
$path = parse_url(request()->input('target'), PHP_URL_PATH); $path = parse_url($request->input('target'), PHP_URL_PATH);
$pathParts = explode('/', $path); $pathParts = explode('/', $path);
if ($pathParts[1] == 'notes') { if ($pathParts[1] === 'notes') {
//we have a note //we have a note
$noteId = $pathParts[2]; $noteId = $pathParts[2];
try { try {
$note = Note::findOrFail(resolve(Numbers::class)->b60tonum($noteId)); $note = Note::findOrFail(resolve(Numbers::class)->b60tonum($noteId));
dispatch(new ProcessWebMention($note, request()->input('source'))); dispatch(new ProcessWebMention($note, $request->input('source')));
} catch (ModelNotFoundException $e) { } catch (ModelNotFoundException $e) {
return response('This note doesnt exist.', 400); return response('This note doesnt exist.', 400);
} }
@ -60,7 +57,7 @@ class WebMentionsController extends Controller
202 202
); );
} }
if ($pathParts[1] == 'blog') { if ($pathParts[1] === 'blog') {
return response( return response(
'I dont accept webmentions for blog posts yet.', 'I dont accept webmentions for blog posts yet.',
501 501

View file

@ -11,7 +11,7 @@ class Kernel extends HttpKernel
* *
* These middleware are run during every request to your application. * These middleware are run during every request to your application.
* *
* @var array * @var array<int, class-string|string>
*/ */
protected $middleware = [ protected $middleware = [
// \App\Http\Middleware\TrustHosts::class, // \App\Http\Middleware\TrustHosts::class,
@ -26,7 +26,7 @@ class Kernel extends HttpKernel
/** /**
* The application's route middleware groups. * The application's route middleware groups.
* *
* @var array * @var array<string, array<int, class-string|string>>
*/ */
protected $middlewareGroups = [ protected $middlewareGroups = [
'web' => [ 'web' => [
@ -44,21 +44,23 @@ class Kernel extends HttpKernel
], ],
'api' => [ 'api' => [
'throttle:api', // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
], ],
]; ];
/** /**
* The application's route middleware. * The application's middleware aliases.
* *
* These middleware may be assigned to groups or used individually. * Aliases may be used to conveniently assign middleware to routes and groups.
* *
* @var array * @var array<string, class-string|string>
*/ */
protected $routeMiddleware = [ protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class, 'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,

View file

@ -6,17 +6,14 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class ActivityStreamLinks class ActivityStreamLinks
{ {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
$response = $next($request); $response = $next($request);
if ($request->path() === '/') { if ($request->path() === '/') {

View file

@ -3,6 +3,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware; use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
@ -11,14 +12,9 @@ class Authenticate extends Middleware
{ {
/** /**
* Get the path the user should be redirected to when they are not authenticated. * Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/ */
protected function redirectTo($request) protected function redirectTo(Request $request): ?string
{ {
if (! $request->expectsJson()) { return $request->expectsJson() ? null : route('login');
return route('login');
}
} }
} }

View file

@ -5,17 +5,14 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Response;
class CSPHeader class CSPHeader
{ {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
if (App::environment('local', 'development')) { if (App::environment('local', 'development')) {
return $next($request); return $next($request);

View file

@ -1,17 +0,0 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
class CheckForMaintenanceMode extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}

View file

@ -3,17 +3,15 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CorsHeaders class CorsHeaders
{ {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
$response = $next($request); $response = $next($request);
if ($request->path() === 'api/media') { if ($request->path() === 'api/media') {

View file

@ -9,7 +9,7 @@ class EncryptCookies extends Middleware
/** /**
* The names of the cookies that should not be encrypted. * The names of the cookies that should not be encrypted.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
// //

View file

@ -3,17 +3,15 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class LinkHeadersMiddleware class LinkHeadersMiddleware
{ {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle($request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
$response = $next($request); $response = $next($request);
$response->header('Link', '<https://indieauth.com/auth>; rel="authorization_endpoint"', false); $response->header('Link', '<https://indieauth.com/auth>; rel="authorization_endpoint"', false);

View file

@ -6,6 +6,7 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class LocalhostSessionMiddleware class LocalhostSessionMiddleware
{ {
@ -13,12 +14,8 @@ class LocalhostSessionMiddleware
* Whilst we are developing locally, automatically log in as * Whilst we are developing locally, automatically log in as
* `['me' => config('app.url')]` as I cant manually log in as * `['me' => config('app.url')]` as I cant manually log in as
* a .localhost domain. * a .localhost domain.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
if (config('app.env') !== 'production') { if (config('app.env') !== 'production') {
session(['me' => config('app.url')]); session(['me' => config('app.url')]);

View file

@ -7,19 +7,16 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class MyAuthMiddleware class MyAuthMiddleware
{ {
/** /**
* Check the user is logged in. * Check the user is logged in.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
if (Auth::check($request->user()) == false) { if (Auth::check() === false) {
// theyre not logged in, so send them to login form // theyre not logged in, so send them to login form
return redirect()->route('login'); return redirect()->route('login');
} }

View file

@ -9,7 +9,7 @@ class PreventRequestsDuringMaintenance extends Middleware
/** /**
* The URIs that should be reachable while maintenance mode is enabled. * The URIs that should be reachable while maintenance mode is enabled.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
// //

View file

@ -6,6 +6,7 @@ use App\Providers\RouteServiceProvider;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
@ -15,12 +16,9 @@ class RedirectIfAuthenticated
/** /**
* Handle an incoming request. * Handle an incoming request.
* *
* @param \Illuminate\Http\Request $request * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
* @param \Closure $next
* @param string|null ...$guards
* @return mixed
*/ */
public function handle(Request $request, Closure $next, ...$guards) public function handle(Request $request, Closure $next, string ...$guards): Response
{ {
$guards = empty($guards) ? [null] : $guards; $guards = empty($guards) ? [null] : $guards;

View file

@ -9,9 +9,10 @@ class TrimStrings extends Middleware
/** /**
* The names of the attributes that should not be trimmed. * The names of the attributes that should not be trimmed.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
'current_password',
'password', 'password',
'password_confirmation', 'password_confirmation',
]; ];

View file

@ -12,9 +12,9 @@ class TrustHosts extends Middleware
/** /**
* Get the host patterns that should be trusted. * Get the host patterns that should be trusted.
* *
* @return array * @return array<int, string|null>
*/ */
public function hosts() public function hosts(): array
{ {
return [ return [
$this->allSubdomainsOfApplicationUrl(), $this->allSubdomainsOfApplicationUrl(),

View file

@ -10,7 +10,7 @@ class TrustProxies extends Middleware
/** /**
* The trusted proxies for this application. * The trusted proxies for this application.
* *
* @var array|string * @var array<int, string>|string|null
*/ */
protected $proxies; protected $proxies;

View file

@ -9,7 +9,7 @@ class VerifyCsrfToken extends Middleware
/** /**
* The URIs that should be excluded from CSRF verification. * The URIs that should be excluded from CSRF verification.
* *
* @var array * @var array<int, string>
*/ */
protected $except = [ protected $except = [
'api/media', 'api/media',

View file

@ -6,17 +6,14 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class VerifyMicropubToken class VerifyMicropubToken
{ {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/ */
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next): Response
{ {
if ($request->input('access_token')) { if ($request->input('access_token')) {
return $next($request); return $next($request);

View file

@ -10,8 +10,6 @@ class MicropubResponses
{ {
/** /**
* Generate a response to be returned when the token has insufficient scope. * Generate a response to be returned when the token has insufficient scope.
*
* @return JsonResponse
*/ */
public function insufficientScopeResponse(): JsonResponse public function insufficientScopeResponse(): JsonResponse
{ {
@ -24,8 +22,6 @@ class MicropubResponses
/** /**
* Generate a response to be returned when the token is invalid. * Generate a response to be returned when the token is invalid.
*
* @return JsonResponse
*/ */
public function invalidTokenResponse(): JsonResponse public function invalidTokenResponse(): JsonResponse
{ {
@ -38,8 +34,6 @@ class MicropubResponses
/** /**
* Generate a response to be returned when the token has no scope. * Generate a response to be returned when the token has no scope.
*
* @return JsonResponse
*/ */
public function tokenHasNoScopeResponse(): JsonResponse public function tokenHasNoScopeResponse(): JsonResponse
{ {

View file

@ -18,26 +18,22 @@ class AddClientToDatabase implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
protected $client_id; protected string $client_id;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param string $client_id
*/ */
public function __construct(string $client_id) public function __construct(string $clientId)
{ {
$this->client_id = $client_id; $this->client_id = $clientId;
} }
/** /**
* Execute the job. * Execute the job.
*
* @return void
*/ */
public function handle() public function handle(): void
{ {
if (MicropubClient::where('client_url', $this->client_id)->count() == 0) { if (MicropubClient::where('client_url', $this->client_id)->count() === 0) {
MicropubClient::create([ MicropubClient::create([
'client_url' => $this->client_id, 'client_url' => $this->client_id,
'client_name' => $this->client_id, // default client name is the URL 'client_name' => $this->client_id, // default client name is the URL

View file

@ -19,37 +19,26 @@ class DownloadWebMention implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/**
* The webmention source URL.
*
* @var string
*/
protected $source;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param string $source
*/ */
public function __construct(string $source) public function __construct(
{ protected string $source
$this->source = $source; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @param Client $guzzle
*
* @throws GuzzleException * @throws GuzzleException
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public function handle(Client $guzzle) public function handle(Client $guzzle): void
{ {
$response = $guzzle->request('GET', $this->source); $response = $guzzle->request('GET', $this->source);
//4XX and 5XX responses should get Guzzle to throw an exception, //4XX and 5XX responses should get Guzzle to throw an exception,
//Laravel should catch and retry these automatically. //Laravel should catch and retry these automatically.
if ($response->getStatusCode() == '200') { if ($response->getStatusCode() === 200) {
$filesystem = new FileSystem(); $filesystem = new FileSystem();
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source); $filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
//backup file first //backup file first
@ -72,7 +61,7 @@ class DownloadWebMention implements ShouldQueue
); );
//remove backup if the same //remove backup if the same
if ($filesystem->exists($filenameBackup)) { if ($filesystem->exists($filenameBackup)) {
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) { if ($filesystem->get($filename) === $filesystem->get($filenameBackup)) {
$filesystem->delete($filenameBackup); $filesystem->delete($filenameBackup);
} }
} }
@ -81,14 +70,11 @@ class DownloadWebMention implements ShouldQueue
/** /**
* Create a file path from a URL. This is used when caching the HTML response. * Create a file path from a URL. This is used when caching the HTML response.
*
* @param string $url
* @return string The path name
*/ */
private function createFilenameFromURL(string $url) private function createFilenameFromURL(string $url): string
{ {
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url); $filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
if (substr($filepath, -1) == '/') { if (str_ends_with($filepath, '/')) {
$filepath .= 'index.html'; $filepath .= 'index.html';
} }

View file

@ -20,22 +20,16 @@ class ProcessBookmark implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
protected Bookmark $bookmark;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Bookmark $bookmark
*/ */
public function __construct(Bookmark $bookmark) public function __construct(
{ protected Bookmark $bookmark
$this->bookmark = $bookmark; ) {
} }
/** /**
* Execute the job. * Execute the job.
*
* @return void
*/ */
public function handle(): void public function handle(): void
{ {

View file

@ -25,26 +25,17 @@ class ProcessLike implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/** @var Like */
protected $like;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Like $like
*/ */
public function __construct(Like $like) public function __construct(
{ protected Like $like
$this->like = $like; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @param Client $client
* @param Authorship $authorship
* @return int
*
* @throws GuzzleException * @throws GuzzleException
*/ */
public function handle(Client $client, Authorship $authorship): int public function handle(Client $client, Authorship $authorship): int
@ -104,9 +95,6 @@ class ProcessLike implements ShouldQueue
/** /**
* Determine if a given URL is that of a Tweet. * Determine if a given URL is that of a Tweet.
*
* @param string $url
* @return bool
*/ */
private function isTweet(string $url): bool private function isTweet(string $url): bool
{ {

View file

@ -20,25 +20,18 @@ class ProcessMedia implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/** @var string */
protected $filename;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param string $filename
*/ */
public function __construct(string $filename) public function __construct(
{ protected string $filename
$this->filename = $filename; ) {
} }
/** /**
* Execute the job. * Execute the job.
*
* @param ImageManager $manager
*/ */
public function handle(ImageManager $manager) public function handle(ImageManager $manager): void
{ {
//open file //open file
try { try {

View file

@ -24,35 +24,23 @@ class ProcessWebMention implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/** @var Note */
protected $note;
/** @var string */
protected $source;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Note $note
* @param string $source
*/ */
public function __construct(Note $note, string $source) public function __construct(
{ protected Note $note,
$this->note = $note; protected string $source
$this->source = $source; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @param Parser $parser
* @param Client $guzzle
*
* @throws RemoteContentNotFoundException * @throws RemoteContentNotFoundException
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidMentionException * @throws InvalidMentionException
*/ */
public function handle(Parser $parser, Client $guzzle) public function handle(Parser $parser, Client $guzzle): void
{ {
try { try {
$response = $guzzle->request('GET', $this->source); $response = $guzzle->request('GET', $this->source);
@ -65,8 +53,8 @@ class ProcessWebMention implements ShouldQueue
foreach ($webmentions as $webmention) { foreach ($webmentions as $webmention) {
// check webmention still references target // check webmention still references target
// we try each type of mention (reply/like/repost) // we try each type of mention (reply/like/repost)
if ($webmention->type == 'in-reply-to') { if ($webmention->type === 'in-reply-to') {
if ($parser->checkInReplyTo($microformats, $this->note->longurl) == false) { if ($parser->checkInReplyTo($microformats, $this->note->longurl) === false) {
// it doesnt so delete // it doesnt so delete
$webmention->delete(); $webmention->delete();
@ -79,16 +67,16 @@ class ProcessWebMention implements ShouldQueue
return; return;
} }
if ($webmention->type == 'like-of') { if ($webmention->type === 'like-of') {
if ($parser->checkLikeOf($microformats, $this->note->longurl) == false) { if ($parser->checkLikeOf($microformats, $this->note->longurl) === false) {
// it doesnt so delete // it doesnt so delete
$webmention->delete(); $webmention->delete();
return; return;
} // note we dont need to do anything if it still is a like } // note we dont need to do anything if it still is a like
} }
if ($webmention->type == 'repost-of') { if ($webmention->type === 'repost-of') {
if ($parser->checkRepostOf($microformats, $this->note->longurl) == false) { if ($parser->checkRepostOf($microformats, $this->note->longurl) === false) {
// it doesnt so delete // it doesnt so delete
$webmention->delete(); $webmention->delete();
@ -112,26 +100,23 @@ class ProcessWebMention implements ShouldQueue
/** /**
* Save the HTML of a webmention for future use. * Save the HTML of a webmention for future use.
*
* @param string $html
* @param string $url
*/ */
private function saveRemoteContent($html, $url) private function saveRemoteContent(string $html, string $url): void
{ {
$filenameFromURL = str_replace( $filenameFromURL = str_replace(
['https://', 'http://'], ['https://', 'http://'],
['https/', 'http/'], ['https/', 'http/'],
$url $url
); );
if (substr($url, -1) == '/') { if (str_ends_with($url, '/')) {
$filenameFromURL .= 'index.html'; $filenameFromURL .= 'index.html';
} }
$path = storage_path() . '/HTML/' . $filenameFromURL; $path = storage_path() . '/HTML/' . $filenameFromURL;
$parts = explode('/', $path); $parts = explode('/', $path);
$name = array_pop($parts); $name = array_pop($parts);
$dir = implode('/', $parts); $dir = implode('/', $parts);
if (! is_dir($dir)) { if (! is_dir($dir) && ! mkdir($dir, 0755, true) && ! is_dir($dir)) {
mkdir($dir, 0755, true); throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
} }
file_put_contents("$dir/$name", $html); file_put_contents("$dir/$name", $html);
} }

View file

@ -20,29 +20,23 @@ class SaveProfileImage implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
protected array $microformats;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param array $microformats
*/ */
public function __construct(array $microformats) public function __construct(
{ protected array $microformats
$this->microformats = $microformats; ) {
} }
/** /**
* Execute the job. * Execute the job.
*
* @param Authorship $authorship
*/ */
public function handle(Authorship $authorship) public function handle(Authorship $authorship): void
{ {
try { try {
$author = $authorship->findAuthor($this->microformats); $author = $authorship->findAuthor($this->microformats);
} catch (AuthorshipParserException) { } catch (AuthorshipParserException) {
return null; return;
} }
$photo = Arr::get($author, 'properties.photo.0'); $photo = Arr::get($author, 'properties.photo.0');
@ -51,8 +45,8 @@ class SaveProfileImage implements ShouldQueue
//dont save pbs.twimg.com links //dont save pbs.twimg.com links
if ( if (
$photo $photo
&& parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com' && parse_url($photo, PHP_URL_HOST) !== 'pbs.twimg.com'
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com' && parse_url($photo, PHP_URL_HOST) !== 'twitter.com'
) { ) {
$client = resolve(Client::class); $client = resolve(Client::class);
@ -71,8 +65,8 @@ class SaveProfileImage implements ShouldQueue
$parts = explode('/', $path); $parts = explode('/', $path);
$name = array_pop($parts); $name = array_pop($parts);
$dir = implode('/', $parts); $dir = implode('/', $parts);
if (! is_dir($dir)) { if (! is_dir($dir) && ! mkdir($dir, 0755, true) && ! is_dir($dir)) {
mkdir($dir, 0755, true); throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
} }
file_put_contents("$dir/$name", $image); file_put_contents("$dir/$name", $image);
} }

View file

@ -18,22 +18,17 @@ class SaveScreenshot implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private Bookmark $bookmark;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @return void
*/ */
public function __construct(Bookmark $bookmark) public function __construct(
{ protected Bookmark $bookmark
$this->bookmark = $bookmark; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @return void
* *
* @throws JsonException * @throws JsonException
*/ */

View file

@ -22,23 +22,17 @@ class SendWebMentions implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
protected Note $note;
/** /**
* Create the job instance, inject dependencies. * Create a new job instance.
*
* @param Note $note
*/ */
public function __construct(Note $note) public function __construct(
{ protected Note $note
$this->note = $note; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @return void
*
* @throws GuzzleException * @throws GuzzleException
*/ */
public function handle(): void public function handle(): void
@ -63,9 +57,6 @@ class SendWebMentions implements ShouldQueue
/** /**
* Discover if a URL has a webmention endpoint. * Discover if a URL has a webmention endpoint.
* *
* @param string $url
* @return string|null
*
* @throws GuzzleException * @throws GuzzleException
*/ */
public function discoverWebmentionEndpoint(string $url): ?string public function discoverWebmentionEndpoint(string $url): ?string
@ -111,9 +102,6 @@ class SendWebMentions implements ShouldQueue
/** /**
* Get the URLs from a note. * Get the URLs from a note.
*
* @param string|null $html
* @return array
*/ */
public function getLinks(?string $html): array public function getLinks(?string $html): array
{ {
@ -134,10 +122,6 @@ class SendWebMentions implements ShouldQueue
/** /**
* Resolve a URI if necessary. * Resolve a URI if necessary.
*
* @param string $url
* @param string $base The base of the URL
* @return string
*/ */
public function resolveUri(string $url, string $base): string public function resolveUri(string $url, string $base): string
{ {

View file

@ -20,27 +20,20 @@ class SyndicateBookmarkToTwitter implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/** @var Bookmark */
protected $bookmark;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Bookmark $bookmark
*/ */
public function __construct(Bookmark $bookmark) public function __construct(
{ protected Bookmark $bookmark
$this->bookmark = $bookmark; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @param Client $guzzle
*
* @throws GuzzleException * @throws GuzzleException
*/ */
public function handle(Client $guzzle) public function handle(Client $guzzle): void
{ {
//send webmention //send webmention
$response = $guzzle->request( $response = $guzzle->request(
@ -55,7 +48,7 @@ class SyndicateBookmarkToTwitter implements ShouldQueue
] ]
); );
//parse for syndication URL //parse for syndication URL
if ($response->getStatusCode() == 201) { if ($response->getStatusCode() === 201) {
$json = json_decode((string) $response->getBody()); $json = json_decode((string) $response->getBody());
$syndicates = $this->bookmark->syndicates; $syndicates = $this->bookmark->syndicates;
$syndicates['twitter'] = $json->url; $syndicates['twitter'] = $json->url;

View file

@ -19,9 +19,6 @@ class SyndicateNoteToMastodon implements ShouldQueue
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Note $note
* @return void
*/ */
public function __construct( public function __construct(
protected Note $note protected Note $note
@ -31,9 +28,6 @@ class SyndicateNoteToMastodon implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
* *
* @param Client $guzzle
* @return void
*
* @throws GuzzleException * @throws GuzzleException
*/ */
public function handle(Client $guzzle): void public function handle(Client $guzzle): void

View file

@ -18,23 +18,17 @@ class SyndicateNoteToTwitter implements ShouldQueue
use Queueable; use Queueable;
use SerializesModels; use SerializesModels;
/** @var Note */
protected $note;
/** /**
* Create a new job instance. * Create a new job instance.
*
* @param Note $note
*/ */
public function __construct(Note $note) public function __construct(
{ protected Note $note
$this->note = $note; ) {
} }
/** /**
* Execute the job. * Execute the job.
* *
* @param Client $guzzle
* *
* @throws GuzzleException * @throws GuzzleException
*/ */

View file

@ -24,24 +24,26 @@ class Article extends Model
use Sluggable; use Sluggable;
use SoftDeletes; use SoftDeletes;
/** /** @var string */
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'articles'; protected $table = 'articles';
/** @var array<int, string> */
protected $fillable = [
'url',
'title',
'main',
'published',
];
/** @var array<string, string> */
protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
/** /**
* Return the sluggable configuration array for this model. * Return the sluggable configuration array for this model.
*
* @return array
*/ */
public function sluggable(): array public function sluggable(): array
{ {
@ -52,18 +54,6 @@ class Article extends Model
]; ];
} }
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'url',
'title',
'main',
'published',
];
protected function html(): Attribute protected function html(): Attribute
{ {
return Attribute::get( return Attribute::get(
@ -116,11 +106,6 @@ class Article extends Model
/** /**
* Scope a query to only include articles from a particular year/month. * Scope a query to only include articles from a particular year/month.
*
* @param Builder $query
* @param int|null $year
* @param int|null $month
* @return Builder
*/ */
public function scopeDate(Builder $query, int $year = null, int $month = null): Builder public function scopeDate(Builder $query, int $year = null, int $month = null): Builder
{ {

View file

@ -13,28 +13,15 @@ class Bookmark extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['url', 'name', 'content']; protected $fillable = ['url', 'name', 'content'];
/** /** @var array<string, string> */
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [ protected $casts = [
'syndicates' => 'array', 'syndicates' => 'array',
]; ];
/** public function tags(): BelongsToMany
* The tags that belong to the bookmark.
*
* @return BelongsToMany
*/
public function tags()
{ {
return $this->belongsToMany('App\Models\Tag'); return $this->belongsToMany('App\Models\Tag');
} }

View file

@ -12,18 +12,10 @@ class Contact extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var string */
* The database table used by the model.
*
* @var string
*/
protected $table = 'contacts'; protected $table = 'contacts';
/** /** @var array<int, string> */
* We shall guard against mass-migration.
*
* @var array
*/
protected $fillable = ['nick', 'name', 'homepage', 'twitter', 'facebook']; protected $fillable = ['nick', 'name', 'homepage', 'twitter', 'facebook'];
protected function photo(): Attribute protected function photo(): Attribute

View file

@ -16,6 +16,7 @@ class Like extends Model
use FilterHtml; use FilterHtml;
use HasFactory; use HasFactory;
/** @var array<int, string> */
protected $fillable = ['url']; protected $fillable = ['url'];
protected function url(): Attribute protected function url(): Attribute

View file

@ -14,25 +14,12 @@ class Media extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var string */
* The table associated with the model.
*
* @var string
*/
protected $table = 'media_endpoint'; protected $table = 'media_endpoint';
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['token', 'path', 'type', 'image_widths']; protected $fillable = ['token', 'path', 'type', 'image_widths'];
/**
* Get the note that owns this media.
*
* @return BelongsTo
*/
public function note(): BelongsTo public function note(): BelongsTo
{ {
return $this->belongsTo(Note::class); return $this->belongsTo(Note::class);

View file

@ -12,25 +12,12 @@ class MicropubClient extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var string */
* The table associated with the model.
*
* @var string
*/
protected $table = 'clients'; protected $table = 'clients';
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['client_url', 'client_name']; protected $fillable = ['client_url', 'client_name'];
/**
* Define the relationship with notes.
*
* @return HasMany
*/
public function notes(): HasMany public function notes(): HasMany
{ {
return $this->hasMany('App\Models\Note', 'client_id', 'client_url'); return $this->hasMany('App\Models\Note', 'client_id', 'client_url');

View file

@ -6,7 +6,6 @@ namespace App\Models;
use App\CommonMark\Generators\ContactMentionGenerator; use App\CommonMark\Generators\ContactMentionGenerator;
use App\CommonMark\Renderers\ContactMentionRenderer; use App\CommonMark\Renderers\ContactMentionRenderer;
use App\Exceptions\TwitterContentException;
use Codebird\Codebird; use Codebird\Codebird;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
@ -51,8 +50,6 @@ class Note extends Model
/** /**
* Set our contacts variable to null. * Set our contacts variable to null.
*
* @param array $attributes
*/ */
public function __construct(array $attributes = []) public function __construct(array $attributes = [])
{ {
@ -60,85 +57,46 @@ class Note extends Model
$this->contacts = null; $this->contacts = null;
} }
/** /** @var string */
* The database table used by the model.
*
* @var string
*/
protected $table = 'notes'; protected $table = 'notes';
/** /** @var array<int, string> */
* Mass-assignment.
*
* @var array
*/
protected $fillable = [ protected $fillable = [
'note', 'note',
'in_reply_to', 'in_reply_to',
'client_id', 'client_id',
]; ];
/** /** @var array<int, string> */
* Hide the column used with Laravel Scout.
*
* @var array
*/
protected $hidden = ['searchable']; protected $hidden = ['searchable'];
/**
* Define the relationship with tags.
*
* @return BelongsToMany
*/
public function tags(): BelongsToMany public function tags(): BelongsToMany
{ {
return $this->belongsToMany(Tag::class); return $this->belongsToMany(Tag::class);
} }
/**
* Define the relationship with clients.
*
* @return BelongsTo
*/
public function client(): BelongsTo public function client(): BelongsTo
{ {
return $this->belongsTo(MicropubClient::class, 'client_id', 'client_url'); return $this->belongsTo(MicropubClient::class, 'client_id', 'client_url');
} }
/**
* Define the relationship with webmentions.
*
* @return MorphMany
*/
public function webmentions(): MorphMany public function webmentions(): MorphMany
{ {
return $this->morphMany(WebMention::class, 'commentable'); return $this->morphMany(WebMention::class, 'commentable');
} }
/**
* Define the relationship with places.
*
* @return BelongsTo
*/
public function place(): BelongsTo public function place(): BelongsTo
{ {
return $this->belongsTo(Place::class); return $this->belongsTo(Place::class);
} }
/**
* Define the relationship with media.
*
* @return HasMany
*/
public function media(): HasMany public function media(): HasMany
{ {
return $this->hasMany(Media::class); return $this->hasMany(Media::class);
} }
/** /**
* Set the attributes to be indexed for searching with Scout. * @return array<int, string>
*
* @return array
*/ */
public function toSearchableArray(): array public function toSearchableArray(): array
{ {
@ -147,11 +105,6 @@ class Note extends Model
]; ];
} }
/**
* Normalize the note to Unicode FORM C.
*
* @param string|null $value
*/
public function setNoteAttribute(?string $value): void public function setNoteAttribute(?string $value): void
{ {
if ($value !== null) { if ($value !== null) {
@ -165,9 +118,6 @@ class Note extends Model
/** /**
* Pre-process notes for web-view. * Pre-process notes for web-view.
*
* @param string|null $value
* @return string|null
*/ */
public function getNoteAttribute(?string $value): ?string public function getNoteAttribute(?string $value): ?string
{ {
@ -189,8 +139,6 @@ class Note extends Model
* Provide the content_html for JSON feed. * Provide the content_html for JSON feed.
* *
* In particular, we want to include media links such as images. * In particular, we want to include media links such as images.
*
* @return string
*/ */
public function getContentAttribute(): string public function getContentAttribute(): string
{ {
@ -216,72 +164,37 @@ class Note extends Model
return $note; return $note;
} }
/**
* Generate the NewBase60 ID from primary ID.
*
* @return string
*/
public function getNb60idAttribute(): string public function getNb60idAttribute(): string
{ {
// we cast to string because sometimes the nb60id is an “int” // we cast to string because sometimes the nb60id is an “int”
return (string) resolve(Numbers::class)->numto60($this->id); return (string) resolve(Numbers::class)->numto60($this->id);
} }
/**
* The Long URL for a note.
*
* @return string
*/
public function getLongurlAttribute(): string public function getLongurlAttribute(): string
{ {
return config('app.url') . '/notes/' . $this->nb60id; return config('app.url') . '/notes/' . $this->nb60id;
} }
/**
* The Short URL for a note.
*
* @return string
*/
public function getShorturlAttribute(): string public function getShorturlAttribute(): string
{ {
return config('app.shorturl') . '/notes/' . $this->nb60id; return config('app.shorturl') . '/notes/' . $this->nb60id;
} }
/**
* Get the ISO8601 value for mf2.
*
* @return string
*/
public function getIso8601Attribute(): string public function getIso8601Attribute(): string
{ {
return $this->updated_at->toISO8601String(); return $this->updated_at->toISO8601String();
} }
/**
* Get the ISO8601 value for mf2.
*
* @return string
*/
public function getHumandiffAttribute(): string public function getHumandiffAttribute(): string
{ {
return $this->updated_at->diffForHumans(); return $this->updated_at->diffForHumans();
} }
/**
* Get the publish date value for RSS feeds.
*
* @return string
*/
public function getPubdateAttribute(): string public function getPubdateAttribute(): string
{ {
return $this->updated_at->toRSSString(); return $this->updated_at->toRSSString();
} }
/**
* Get the latitude value.
*
* @return float|null
*/
public function getLatitudeAttribute(): ?float public function getLatitudeAttribute(): ?float
{ {
if ($this->place !== null) { if ($this->place !== null) {
@ -297,11 +210,6 @@ class Note extends Model
return null; return null;
} }
/**
* Get the longitude value.
*
* @return float|null
*/
public function getLongitudeAttribute(): ?float public function getLongitudeAttribute(): ?float
{ {
if ($this->place !== null) { if ($this->place !== null) {
@ -318,10 +226,9 @@ class Note extends Model
} }
/** /**
* Get the address for a note. This is either a reverse geo-code from the * Get the address for a note.
* location, or is derived from the associated place.
* *
* @return string|null * This is either a reverse geo-code from the location, or is derived from the associated place.
*/ */
public function getAddressAttribute(): ?string public function getAddressAttribute(): ?string
{ {
@ -337,8 +244,6 @@ class Note extends Model
/** /**
* Get the OEmbed html for a tweet the note is a reply to. * Get the OEmbed html for a tweet the note is a reply to.
*
* @return object|null
*/ */
public function getTwitterAttribute(): ?object public function getTwitterAttribute(): ?object
{ {
@ -378,10 +283,6 @@ class Note extends Model
* Show a specific form of the note for twitter. * Show a specific form of the note for twitter.
* *
* That is we swap the contacts names for their known Twitter handles. * That is we swap the contacts names for their known Twitter handles.
*
* @return string
*
* @throws TwitterContentException
*/ */
public function getTwitterContentAttribute(): string public function getTwitterContentAttribute(): string
{ {
@ -424,10 +325,6 @@ class Note extends Model
/** /**
* Scope a query to select a note via a NewBase60 id. * Scope a query to select a note via a NewBase60 id.
*
* @param Builder $query
* @param string $nb60id
* @return Builder
*/ */
public function scopeNb60(Builder $query, string $nb60id): Builder public function scopeNb60(Builder $query, string $nb60id): Builder
{ {
@ -441,9 +338,6 @@ class Note extends Model
* we try to create a fancy hcard from our contact info. If this is not possible * we try to create a fancy hcard from our contact info. If this is not possible
* due to lack of contact info, we assume @username is a twitter handle and link it * due to lack of contact info, we assume @username is a twitter handle and link it
* as such. * as such.
*
* @param string $text
* @return string
*/ */
private function makeHCards(string $text): string private function makeHCards(string $text): string
{ {
@ -475,8 +369,6 @@ class Note extends Model
/** /**
* Get the value of the `contacts` property. * Get the value of the `contacts` property.
*
* @return array
*/ */
public function getContacts(): array public function getContacts(): array
{ {
@ -489,8 +381,6 @@ class Note extends Model
/** /**
* Process the note and save the contacts to the `contacts` property. * Process the note and save the contacts to the `contacts` property.
*
* @return void
*/ */
public function setContacts(): void public function setContacts(): void
{ {
@ -512,9 +402,6 @@ class Note extends Model
* Given a string and section, finds all hashtags matching * Given a string and section, finds all hashtags matching
* `#[\-_a-zA-Z0-9]+` and wraps them in an `a` element with * `#[\-_a-zA-Z0-9]+` and wraps them in an `a` element with
* `rel=tag` set and a `href` of 'section/tagged/' + tagname without the #. * `rel=tag` set and a `href` of 'section/tagged/' + tagname without the #.
*
* @param string $note
* @return string
*/ */
public function autoLinkHashtag(string $note): string public function autoLinkHashtag(string $note): string
{ {
@ -529,12 +416,6 @@ class Note extends Model
); );
} }
/**
* Pass a note through the commonmark library.
*
* @param string $note
* @return string
*/
private function convertMarkdown(string $note): string private function convertMarkdown(string $note): string
{ {
$config = [ $config = [
@ -559,13 +440,6 @@ class Note extends Model
return $markdownConverter->convert($note)->getContent(); return $markdownConverter->convert($note)->getContent();
} }
/**
* Do a reverse geocode lookup of a `lat,lng` value.
*
* @param float $latitude
* @param float $longitude
* @return string
*/
public function reverseGeoCode(float $latitude, float $longitude): string public function reverseGeoCode(float $latitude, float $longitude): string
{ {
$latLng = $latitude . ',' . $longitude; $latLng = $latitude . ',' . $longitude;

View file

@ -17,38 +17,20 @@ class Place extends Model
use HasFactory; use HasFactory;
use Sluggable; use Sluggable;
/** public function getRouteKeyName(): string
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{ {
return 'slug'; return 'slug';
} }
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'slug']; protected $fillable = ['name', 'slug'];
/** /** @var array<string, string> */
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [ protected $casts = [
'latitude' => 'float', 'latitude' => 'float',
'longitude' => 'float', 'longitude' => 'float',
]; ];
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
public function sluggable(): array public function sluggable(): array
{ {
return [ return [
@ -59,23 +41,13 @@ class Place extends Model
]; ];
} }
/** public function notes(): HasMany
* Define the relationship with Notes.
*
* @return HasMany
*/
public function notes()
{ {
return $this->hasMany('App\Models\Note'); return $this->hasMany('App\Models\Note');
} }
/** /**
* Select places near a given location. * Select places near a given location.
*
* @param Builder $query
* @param object $location
* @param int $distance
* @return Builder
*/ */
public function scopeNear(Builder $query, object $location, int $distance = 1000): Builder public function scopeNear(Builder $query, object $location, int $distance = 1000): Builder
{ {
@ -94,10 +66,6 @@ class Place extends Model
/** /**
* Select places based on a URL. * Select places based on a URL.
*
* @param Builder $query
* @param string $url
* @return Builder
*/ */
public function scopeWhereExternalURL(Builder $query, string $url): Builder public function scopeWhereExternalURL(Builder $query, string $url): Builder
{ {
@ -150,9 +118,6 @@ class Place extends Model
/** /**
* Given a URL, see if it is one of our known types. * Given a URL, see if it is one of our known types.
*
* @param string $url
* @return string
*/ */
private function getType(string $url): string private function getType(string $url): string
{ {

View file

@ -12,11 +12,7 @@ class SyndicationTarget extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [ protected $fillable = [
'uid', 'uid',
'name', 'name',
@ -28,11 +24,7 @@ class SyndicationTarget extends Model
'user_photo', 'user_photo',
]; ];
/** /** @var array<int, string> */
* The attributes that are visible when serializing the model.
*
* @var array<string>
*/
protected $visible = [ protected $visible = [
'uid', 'uid',
'name', 'name',
@ -40,21 +32,12 @@ class SyndicationTarget extends Model
'user', 'user',
]; ];
/** /** @var array<int, string> */
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [ protected $appends = [
'service', 'service',
'user', 'user',
]; ];
/**
* Get the service data as a single attribute.
*
* @vreturn Attribute
*/
protected function service(): Attribute protected function service(): Attribute
{ {
return Attribute::get( return Attribute::get(
@ -66,11 +49,6 @@ class SyndicationTarget extends Model
); );
} }
/**
* Get the user data as a single attribute.
*
* @vreturn Attribute
*/
protected function user(): Attribute protected function user(): Attribute
{ {
return Attribute::get( return Attribute::get(

View file

@ -14,29 +14,15 @@ class Tag extends Model
{ {
use HasFactory; use HasFactory;
/** /** @var array<int, string> */
* We shall set a blacklist of non-modifiable model attributes.
*
* @var array
*/
protected $guarded = ['id']; protected $guarded = ['id'];
/** public function notes(): BelongsToMany
* Define the relationship with notes.
*
* @return BelongsToMany
*/
public function notes()
{ {
return $this->belongsToMany(Note::class); return $this->belongsToMany(Note::class);
} }
/** public function bookmarks(): BelongsToMany
* The bookmarks that belong to the tag.
*
* @return BelongsToMany
*/
public function bookmarks()
{ {
return $this->belongsToMany('App\Models\Bookmark'); return $this->belongsToMany('App\Models\Bookmark');
} }
@ -49,11 +35,9 @@ class Tag extends Model
} }
/** /**
* This method actually normalizes a tag. That means lowercase-ing and * Normalizes a tag.
* removing fancy diatric characters.
* *
* @param string $tag * That means convert to lowercase and removing fancy diatric characters.
* @return string
*/ */
public static function normalize(string $tag): string public static function normalize(string $tag): string
{ {

View file

@ -13,21 +13,15 @@ class User extends Authenticatable
use HasFactory; use HasFactory;
use Notifiable; use Notifiable;
/** /** @var array<int, string> */
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [ protected $fillable = [
'name', 'password', 'name', 'password',
]; ];
/** /** @var array<int, string> */
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [ protected $hidden = [
'password', 'remember_token', 'current_password',
'password',
'remember_token',
]; ];
} }

View file

@ -20,26 +20,13 @@ class WebMention extends Model
use FilterHtml; use FilterHtml;
use HasFactory; use HasFactory;
/** /** @var string */
* The database table used by the model.
*
* @var string
*/
protected $table = 'webmentions'; protected $table = 'webmentions';
/** /** @var array<int, string> */
* We shall set a blacklist of non-modifiable model attributes.
*
* @var array
*/
protected $guarded = ['id']; protected $guarded = ['id'];
/** public function commentable(): MorphTo
* Define the relationship.
*
* @return MorphTo
*/
public function commentable()
{ {
return $this->morphTo(); return $this->morphTo();
} }
@ -121,9 +108,6 @@ class WebMention extends Model
/** /**
* Create the photo link. * Create the photo link.
*
* @param string $url
* @return string
*/ */
public function createPhotoLink(string $url): string public function createPhotoLink(string $url): string
{ {

View file

@ -13,10 +13,8 @@ class NoteObserver
{ {
/** /**
* Listen to the Note created event. * Listen to the Note created event.
*
* @param Note $note
*/ */
public function created(Note $note) public function created(Note $note): void
{ {
$text = Arr::get($note->getAttributes(), 'note'); $text = Arr::get($note->getAttributes(), 'note');
if ($text === null) { if ($text === null) {
@ -37,10 +35,8 @@ class NoteObserver
/** /**
* Listen to the Note updated event. * Listen to the Note updated event.
*
* @param Note $note
*/ */
public function updated(Note $note) public function updated(Note $note): void
{ {
$text = Arr::get($note->getAttributes(), 'note'); $text = Arr::get($note->getAttributes(), 'note');
if ($text === null) { if ($text === null) {
@ -63,19 +59,14 @@ class NoteObserver
/** /**
* Listen to the Note deleting event. * Listen to the Note deleting event.
*
* @param Note $note
*/ */
public function deleting(Note $note) public function deleting(Note $note): void
{ {
$note->tags()->detach(); $note->tags()->detach();
} }
/** /**
* Retrieve the tags from a notes text, tag for form #tag. * Retrieve the tags from a notes text, tag for form #tag.
*
* @param string $note
* @return Collection
*/ */
private function getTagsFromNote(string $note): Collection private function getTagsFromNote(string $note): Collection
{ {

View file

@ -25,10 +25,8 @@ class AppServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
Note::observe(NoteObserver::class); Note::observe(NoteObserver::class);
@ -144,10 +142,8 @@ class AppServiceProvider extends ServiceProvider
/** /**
* Register any application services. * Register any application services.
*
* @return void
*/ */
public function register() public function register(): void
{ {
if ($this->app->environment('local', 'testing')) { if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class); $this->app->register(DuskServiceProvider::class);

View file

@ -7,23 +7,19 @@ use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvid
class AuthServiceProvider extends ServiceProvider class AuthServiceProvider extends ServiceProvider
{ {
/** /**
* The policy mappings for the application. * The model to policy mappings for the application.
* *
* @var array * @var array<class-string, class-string>
*/ */
protected $policies = [ protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy', // 'App\Models\Model' => 'App\Policies\ModelPolicy',
]; ];
/** /**
* Register any application authentication / authorization services. * Register any authentication / authorization services.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
$this->registerPolicies();
// //
} }
} }

View file

@ -12,10 +12,8 @@ class BroadcastServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
Broadcast::routes(); Broadcast::routes();

View file

@ -10,9 +10,9 @@ use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider class EventServiceProvider extends ServiceProvider
{ {
/** /**
* The event listener mappings for the application. * The event to listener mappings for the application.
* *
* @var array * @var array<class-string, array<int, class-string>>
*/ */
protected $listen = [ protected $listen = [
Registered::class => [ Registered::class => [
@ -22,13 +22,9 @@ class EventServiceProvider extends ServiceProvider
/** /**
* Register any events for your application. * Register any events for your application.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
parent::boot();
// //
} }
} }

View file

@ -10,10 +10,8 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
{ {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
parent::boot(); parent::boot();
@ -28,10 +26,8 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
* Register the Horizon gate. * Register the Horizon gate.
* *
* This gate determines who can access Horizon in non-local environments. * This gate determines who can access Horizon in non-local environments.
*
* @return void
*/ */
protected function gate() protected function gate(): void
{ {
Gate::define('viewHorizon', function ($user) { Gate::define('viewHorizon', function ($user) {
return $user->name === 'jonny'; return $user->name === 'jonny';

View file

@ -11,46 +11,38 @@ use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
/** /**
* This namespace is applied to your controller routes. * The path to the "home" route for your application.
* *
* In addition, it is set as the URL generator's root namespace. * Typically, users are redirected here after authentication.
* *
* @var string|null * @var string
*/ */
// protected $namespace = 'App\Http\Controllers'; public const HOME = '/admin';
/** /**
* Define your route model bindings, pattern filters, etc. * Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
$this->configureRateLimiting(); $this->configureRateLimiting();
$this->routes(function () { $this->routes(function () {
Route::prefix('api') Route::middleware('api')
->middleware('api') ->prefix('api')
->namespace($this->namespace)
->group(base_path('routes/api.php')); ->group(base_path('routes/api.php'));
Route::middleware('web') Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php')); ->group(base_path('routes/web.php'));
}); });
} }
/** /**
* Configure the rate limiters for the application. * Configure the rate limiters for the application.
*
* @return void
*
* @codeCoverageIgnore
*/ */
protected function configureRateLimiting() protected function configureRateLimiting(): void
{ {
RateLimiter::for('api', function (Request $request) { RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60); return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
}); });
} }
} }

View file

@ -5,15 +5,14 @@ declare(strict_types=1);
namespace App\Services; namespace App\Services;
use App\Models\Note; use App\Models\Note;
use Illuminate\Http\Response;
class ActivityStreamsService class ActivityStreamsService
{ {
/** /**
* Return the relevant data to an AS2.0 request to the root path. * Return the relevant data to an AS2.0 request to the root path.
*
* @return \Illuminate\Http\Response
*/ */
public function siteOwnerResponse() public function siteOwnerResponse(): Response
{ {
$data = json_encode([ $data = json_encode([
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',
@ -28,11 +27,8 @@ class ActivityStreamsService
/** /**
* Return the relevant data to an AS2.0 request for a particular note. * Return the relevant data to an AS2.0 request for a particular note.
*
* @param \App\Models\Note $note
* @return \Illuminate\Http\Response
*/ */
public function singleNoteResponse(Note $note) public function singleNoteResponse(Note $note): Response
{ {
$data = json_encode([ $data = json_encode([
'@context' => 'https://www.w3.org/ns/activitystreams', '@context' => 'https://www.w3.org/ns/activitystreams',

View file

@ -19,10 +19,6 @@ class BookmarkService extends Service
{ {
/** /**
* Create a new Bookmark. * Create a new Bookmark.
*
* @param array $request Data from request()->all()
* @param string|null $client
* @return Bookmark
*/ */
public function create(array $request, ?string $client = null): Bookmark public function create(array $request, ?string $client = null): Bookmark
{ {
@ -76,9 +72,6 @@ class BookmarkService extends Service
/** /**
* Given a URL, attempt to save it to the Internet Archive. * Given a URL, attempt to save it to the Internet Archive.
* *
* @param string $url
* @return string
*
* @throws InternetArchiveException * @throws InternetArchiveException
*/ */
public function getArchiveLink(string $url): string public function getArchiveLink(string $url): string

View file

@ -12,9 +12,6 @@ class LikeService extends Service
{ {
/** /**
* Create a new Like. * Create a new Like.
*
* @param array $request
* @return Like $like
*/ */
public function create(array $request, ?string $client = null): Like public function create(array $request, ?string $client = null): Like
{ {

View file

@ -11,9 +11,6 @@ class HCardService
{ {
/** /**
* Create a Place from h-card data, return the URL. * Create a Place from h-card data, return the URL.
*
* @param array $request Data from request()->all()
* @return string
*/ */
public function process(array $request): string public function process(array $request): string
{ {
@ -29,8 +26,7 @@ class HCardService
$data['latitude'] = Arr::get($request, 'latitude'); $data['latitude'] = Arr::get($request, 'latitude');
$data['longitude'] = Arr::get($request, 'longitude'); $data['longitude'] = Arr::get($request, 'longitude');
} }
$place = resolve(PlaceService::class)->createPlace($data);
return $place->longurl; return resolve(PlaceService::class)->createPlace($data)->longurl;
} }
} }

View file

@ -13,11 +13,7 @@ use Illuminate\Support\Arr;
class HEntryService class HEntryService
{ {
/** /**
* Create the relavent model from some h-entry data. * Create the relevant model from some h-entry data.
*
* @param array $request Data from request()->all()
* @param string|null $client The micropub client that made the request
* @return string|null
*/ */
public function process(array $request, ?string $client = null): ?string public function process(array $request, ?string $client = null): ?string
{ {

View file

@ -7,6 +7,7 @@ namespace App\Services\Micropub;
use App\Models\Media; use App\Models\Media;
use App\Models\Note; use App\Models\Note;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -14,11 +15,8 @@ class UpdateService
{ {
/** /**
* Process a micropub request to update an entry. * Process a micropub request to update an entry.
*
* @param array $request Data from request()->all()
* @return \Illuminate\Http\JsonResponse
*/ */
public function process(array $request) public function process(array $request): JsonResponse
{ {
$urlPath = parse_url(Arr::get($request, 'url'), PHP_URL_PATH); $urlPath = parse_url(Arr::get($request, 'url'), PHP_URL_PATH);
@ -42,10 +40,10 @@ class UpdateService
//got the note, are we dealing with a “replace” request? //got the note, are we dealing with a “replace” request?
if (Arr::get($request, 'replace')) { if (Arr::get($request, 'replace')) {
foreach (Arr::get($request, 'replace') as $property => $value) { foreach (Arr::get($request, 'replace') as $property => $value) {
if ($property == 'content') { if ($property === 'content') {
$note->note = $value[0]; $note->note = $value[0];
} }
if ($property == 'syndication') { if ($property === 'syndication') {
foreach ($value as $syndicationURL) { foreach ($value as $syndicationURL) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) { if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL; $note->facebook_url = $syndicationURL;
@ -69,7 +67,7 @@ class UpdateService
//how about “add” //how about “add”
if (Arr::get($request, 'add')) { if (Arr::get($request, 'add')) {
foreach (Arr::get($request, 'add') as $property => $value) { foreach (Arr::get($request, 'add') as $property => $value) {
if ($property == 'syndication') { if ($property === 'syndication') {
foreach ($value as $syndicationURL) { foreach ($value as $syndicationURL) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) { if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL; $note->facebook_url = $syndicationURL;
@ -82,7 +80,7 @@ class UpdateService
} }
} }
} }
if ($property == 'photo') { if ($property === 'photo') {
foreach ($value as $photoURL) { foreach ($value as $photoURL) {
if (Str::startsWith($photoURL, 'https://')) { if (Str::startsWith($photoURL, 'https://')) {
$media = new Media(); $media = new Media();

View file

@ -18,10 +18,6 @@ class NoteService extends Service
{ {
/** /**
* Create a new note. * Create a new note.
*
* @param array $request Data from request()->all()
* @param string|null $client
* @return Note
*/ */
public function create(array $request, ?string $client = null): Note public function create(array $request, ?string $client = null): Note
{ {
@ -68,9 +64,6 @@ class NoteService extends Service
/** /**
* Get the published time from the request to create a new note. * Get the published time from the request to create a new note.
*
* @param array $request Data from request()->all()
* @return string|null
*/ */
private function getPublished(array $request): ?string private function getPublished(array $request): ?string
{ {
@ -87,14 +80,11 @@ class NoteService extends Service
/** /**
* Get the location data from the request to create a new note. * Get the location data from the request to create a new note.
*
* @param array $request Data from request()->all()
* @return string|null
*/ */
private function getLocation(array $request): ?string private function getLocation(array $request): ?string
{ {
$location = Arr::get($request, 'properties.location.0') ?? Arr::get($request, 'location'); $location = Arr::get($request, 'properties.location.0') ?? Arr::get($request, 'location');
if (is_string($location) && substr($location, 0, 4) == 'geo:') { if (is_string($location) && str_starts_with($location, 'geo:')) {
preg_match_all( preg_match_all(
'/([0-9\.\-]+)/', '/([0-9\.\-]+)/',
$location, $location,
@ -109,9 +99,6 @@ class NoteService extends Service
/** /**
* Get the checkin data from the request to create a new note. This will be a Place. * Get the checkin data from the request to create a new note. This will be a Place.
*
* @param array $request Data from request()->all()
* @return Place|null
*/ */
private function getCheckin(array $request): ?Place private function getCheckin(array $request): ?Place
{ {
@ -155,13 +142,10 @@ class NoteService extends Service
/** /**
* Get the Swarm URL from the syndication data in the request to create a new note. * Get the Swarm URL from the syndication data in the request to create a new note.
*
* @param array $request Data from request()->all()
* @return string|null
*/ */
private function getSwarmUrl(array $request): ?string private function getSwarmUrl(array $request): ?string
{ {
if (stristr(Arr::get($request, 'properties.syndication.0', ''), 'swarmapp')) { if (str_contains(Arr::get($request, 'properties.syndication.0', ''), 'swarmapp')) {
return Arr::get($request, 'properties.syndication.0'); return Arr::get($request, 'properties.syndication.0');
} }
@ -170,9 +154,6 @@ class NoteService extends Service
/** /**
* Get the syndication targets from the request to create a new note. * Get the syndication targets from the request to create a new note.
*
* @param array $request Data from request()->all()
* @return array
*/ */
private function getSyndicationTargets(array $request): array private function getSyndicationTargets(array $request): array
{ {
@ -194,9 +175,6 @@ class NoteService extends Service
/** /**
* Get the media URLs from the request to create a new note. * Get the media URLs from the request to create a new note.
*
* @param array $request Data from request()->all()
* @return array
*/ */
private function getMedia(array $request): array private function getMedia(array $request): array
{ {
@ -224,9 +202,6 @@ class NoteService extends Service
/** /**
* Get the Instagram photo URL from the request to create a new note. * Get the Instagram photo URL from the request to create a new note.
*
* @param array $request Data from request()->all()
* @return string|null
*/ */
private function getInstagramUrl(array $request): ?string private function getInstagramUrl(array $request): ?string
{ {

View file

@ -11,9 +11,6 @@ class PlaceService
{ {
/** /**
* Create a place. * Create a place.
*
* @param array $data
* @return Place
*/ */
public function createPlace(array $data): Place public function createPlace(array $data): Place
{ {
@ -40,9 +37,6 @@ class PlaceService
/** /**
* Create a place from a h-card checkin, for example from OwnYourSwarm. * Create a place from a h-card checkin, for example from OwnYourSwarm.
*
* @param array
* @return Place
*/ */
public function createPlaceFromCheckin(array $checkin): Place public function createPlaceFromCheckin(array $checkin): Place
{ {

View file

@ -13,9 +13,6 @@ class TokenService
{ {
/** /**
* Generate a JWT token. * Generate a JWT token.
*
* @param array The data to be encoded
* @return string The signed token
*/ */
public function getNewToken(array $data): string public function getNewToken(array $data): string
{ {
@ -36,9 +33,6 @@ class TokenService
/** /**
* Check the token signature is valid. * Check the token signature is valid.
*
* @param string The token
* @return mixed
*/ */
public function validateToken(string $bearerToken): Token public function validateToken(string $bearerToken): Token
{ {

View file

@ -11,7 +11,7 @@ define('LARAVEL_START', microtime(true));
| Composer provides a convenient, automatically generated class loader | Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it | for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the | into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax. | loading of any of our classes manually. It's great to relax.
| |
*/ */

View file

@ -13,14 +13,14 @@
"ext-dom": "*", "ext-dom": "*",
"ext-intl": "*", "ext-intl": "*",
"ext-json": "*", "ext-json": "*",
"cviebrock/eloquent-sluggable": "^9.0", "cviebrock/eloquent-sluggable": "^10.0",
"guzzlehttp/guzzle": "^7.0.1", "guzzlehttp/guzzle": "^7.0.1",
"indieauth/client": "^1.1", "indieauth/client": "^1.1",
"intervention/image": "^2.4", "intervention/image": "^2.4",
"jonnybarnes/indieweb": "~0.2", "jonnybarnes/indieweb": "~0.2",
"jonnybarnes/webmentions-parser": "~0.5", "jonnybarnes/webmentions-parser": "~0.5",
"jublonet/codebird-php": "4.0.0-beta.1", "jublonet/codebird-php": "4.0.0-beta.1",
"laravel/framework": "^9.0", "laravel/framework": "^10.0",
"laravel/horizon": "^5.0", "laravel/horizon": "^5.0",
"laravel/sanctum": "^3.0", "laravel/sanctum": "^3.0",
"laravel/tinker": "^2.0", "laravel/tinker": "^2.0",
@ -40,10 +40,10 @@
"laravel/pint": "^1.0.0", "laravel/pint": "^1.0.0",
"laravel/sail": "^1.15", "laravel/sail": "^1.15",
"mockery/mockery": "^1.0", "mockery/mockery": "^1.0",
"nunomaduro/collision": "^6.1", "nunomaduro/collision": "^7.0",
"phpunit/php-code-coverage": "^9.2", "phpunit/php-code-coverage": "^10.0",
"phpunit/phpunit": "^9.0", "phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^1.0", "spatie/laravel-ignition": "^2.0",
"spatie/laravel-ray": "^1.12", "spatie/laravel-ray": "^1.12",
"vimeo/psalm": "^5.0" "vimeo/psalm": "^5.0"
}, },
@ -76,7 +76,7 @@
"Tests\\": "tests" "Tests\\": "tests"
} }
}, },
"minimum-stability": "dev", "minimum-stability": "stable",
"prefer-stable": true, "prefer-stable": true,
"scripts": { "scripts": {
"post-autoload-dump": [ "post-autoload-dump": [

1339
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -63,7 +63,7 @@ return [
| Application Long URL | Application Long URL
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| The short URL for the application | The long URL for the application
| |
*/ */
@ -191,7 +191,9 @@ return [
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Font Link | Font Link
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
|
| Which URL should the app load custom fonts from | Which URL should the app load custom fonts from
|
*/ */
'font_link' => env('FONT_LINK'), 'font_link' => env('FONT_LINK'),

View file

@ -84,12 +84,16 @@ return [
| considered valid. This security feature keeps tokens short-lived so | considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed. | they have less time to be guessed. You may change this as needed.
| |
| The throttle setting is the number of seconds a user must wait before
| generating more password reset tokens. This prevents the user from
| quickly generating a very large amount of password reset tokens.
|
*/ */
'passwords' => [ 'passwords' => [
'users' => [ 'users' => [
'provider' => 'users', 'provider' => 'users',
'table' => 'password_resets', 'table' => 'password_reset_tokens',
'expire' => 60, 'expire' => 60,
'throttle' => 60, 'throttle' => 60,
], ],

View file

@ -28,7 +28,7 @@ return [
| sending an e-mail. You will specify which one you are using for your | sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required. | mailers below. You are free to add additional mailers as required.
| |
| Supported: "smtp", "sendmail", "mailgun", "ses", | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
| "postmark", "log", "array", "failover" | "postmark", "log", "array", "failover"
| |
*/ */
@ -51,10 +51,16 @@ return [
'mailgun' => [ 'mailgun' => [
'transport' => 'mailgun', 'transport' => 'mailgun',
// 'client' => [
// 'timeout' => 5,
// ],
], ],
'postmark' => [ 'postmark' => [
'transport' => 'postmark', 'transport' => 'postmark',
// 'client' => [
// 'timeout' => 5,
// ],
], ],
'sendmail' => [ 'sendmail' => [

View file

@ -6,6 +6,9 @@ use App\Models\Article;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Article>
*/
class ArticleFactory extends Factory class ArticleFactory extends Factory
{ {
/** /**
@ -18,9 +21,9 @@ class ArticleFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'titleurl' => $this->faker->slug(3), 'titleurl' => $this->faker->slug(3),

View file

@ -6,6 +6,9 @@ use App\Models\Bookmark;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Bookmark>
*/
class BookmarkFactory extends Factory class BookmarkFactory extends Factory
{ {
/** /**
@ -18,9 +21,9 @@ class BookmarkFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
$now = Carbon::now()->subDays(rand(5, 15)); $now = Carbon::now()->subDays(rand(5, 15));

View file

@ -6,6 +6,9 @@ use App\Models\Contact;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Contact>
*/
class ContactFactory extends Factory class ContactFactory extends Factory
{ {
/** /**
@ -18,9 +21,9 @@ class ContactFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'nick' => mb_strtolower($this->faker->firstName), 'nick' => mb_strtolower($this->faker->firstName),

View file

@ -6,6 +6,9 @@ use App\Models\Like;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Like>
*/
class LikeFactory extends Factory class LikeFactory extends Factory
{ {
/** /**
@ -18,9 +21,9 @@ class LikeFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
$now = Carbon::now()->subDays(rand(5, 15)); $now = Carbon::now()->subDays(rand(5, 15));

View file

@ -6,6 +6,9 @@ use App\Models\Media;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Media>
*/
class MediaFactory extends Factory class MediaFactory extends Factory
{ {
/** /**
@ -18,9 +21,9 @@ class MediaFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'path' => 'media/' . $this->faker->uuid . '.jpg', 'path' => 'media/' . $this->faker->uuid . '.jpg',

View file

@ -5,6 +5,9 @@ namespace Database\Factories;
use App\Models\MicropubClient; use App\Models\MicropubClient;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\MicropubClient>
*/
class MicropubClientFactory extends Factory class MicropubClientFactory extends Factory
{ {
/** /**
@ -17,9 +20,9 @@ class MicropubClientFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'client_url' => $this->faker->url, 'client_url' => $this->faker->url,

View file

@ -7,6 +7,9 @@ use Exception;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Note>
*/
class NoteFactory extends Factory class NoteFactory extends Factory
{ {
/** /**
@ -19,11 +22,11 @@ class NoteFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
* *
* @throws Exception * @throws Exception
*/ */
public function definition() public function definition(): array
{ {
$now = Carbon::now()->subDays(random_int(5, 15)); $now = Carbon::now()->subDays(random_int(5, 15));

View file

@ -5,6 +5,9 @@ namespace Database\Factories;
use App\Models\Place; use App\Models\Place;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Place>
*/
class PlaceFactory extends Factory class PlaceFactory extends Factory
{ {
/** /**
@ -17,9 +20,9 @@ class PlaceFactory extends Factory
/** /**
* Define the model's default state. * Define the model's default state.
* *
* @return array * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'name' => $this->faker->company, 'name' => $this->faker->company,

View file

@ -14,7 +14,7 @@ class SyndicationTargetFactory extends Factory
* *
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function definition() public function definition(): array
{ {
return [ return [
'uid' => $this->faker->url, 'uid' => $this->faker->url,

Some files were not shown because too many files have changed in this diff Show more