Upgrade to Laravel 10

This commit is contained in:
Jonny Barnes 2023-02-18 09:34:57 +00:00
parent c4d7dc31d5
commit 16b120bc73
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
142 changed files with 1676 additions and 2019 deletions

View file

@ -5,17 +5,23 @@ root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
# Tab indentation
[Makefile]
indent_style = tab
tab_width = 4
[yml]
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
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';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function handle(): int
{
$locationColumn = DB::selectOne(DB::raw("
SELECT EXISTS (

View file

@ -6,6 +6,7 @@ namespace App\Console\Commands;
use App\Models\WebMention;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\FileSystem\FileSystem;
class ParseCachedWebMentions extends Command
@ -27,9 +28,9 @@ class ParseCachedWebMentions extends 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');
foreach ($htmlFiles as $file) {
@ -49,8 +50,6 @@ class ParseCachedWebMentions extends Command
/**
* Determine the source URL from a filename.
*
* @param 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';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(): void
{
$webmentions = WebMention::all();
foreach ($webmentions as $webmention) {

View file

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

View file

@ -21,46 +21,34 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
NotFoundHttpException::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.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @return void
*
* @throws Exception
* @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([
'headers' => [
'Content-Type' => 'application/json',
],
]);
$exceptionName = get_class($throwable) ?? 'Unknown Exception';
$title = $exceptionName . ': ' . $throwable->getMessage();
$exceptionName = get_class($e) ?? 'Unknown Exception';
$title = $exceptionName . ': ' . $e->getMessage();
$guzzle->post(
config('logging.slack'),

View file

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

View file

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

View file

@ -96,10 +96,8 @@ class FeedsController extends Controller
/**
* Returns the notes JSON feed.
*
* @return array
*/
public function notesJson()
public function notesJson(): array
{
$notes = Note::latest()->with('media')->take(20)->get();
$data = [

View file

@ -7,6 +7,7 @@ use App\Models\Bookmark;
use App\Models\Like;
use App\Models\Note;
use App\Services\ActivityStreamsService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
@ -14,12 +15,10 @@ class FrontPageController extends Controller
{
/**
* 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();
}

View file

@ -115,34 +115,34 @@ class MicropubController extends Controller
* appropriately. Further if the request has the query parameter
* syndicate-to we respond with the known syndication endpoints.
*/
public function get(): JsonResponse
public function get(Request $request): JsonResponse
{
try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token'));
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
} catch (RequiredConstraintsViolated|InvalidTokenStructure) {
return (new MicropubResponses())->invalidTokenResponse();
}
if (request()->input('q') === 'syndicate-to') {
if ($request->input('q') === 'syndicate-to') {
return response()->json([
'syndicate-to' => SyndicationTarget::all(),
]);
}
if (request()->input('q') === 'config') {
if ($request->input('q') === 'config') {
return response()->json([
'syndicate-to' => SyndicationTarget::all(),
'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(
'/([0-9.\-]+)/',
request()->input('q'),
$request->input('q'),
$matches
);
$distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000;
$distance = (count($matches[0]) === 3) ? 100 * $matches[0][2] : 1000;
$places = Place::near(
(object) ['latitude' => $matches[0][0], 'longitude' => $matches[0][1]],
$distance
@ -168,22 +168,19 @@ class MicropubController extends Controller
/**
* Determine the client id from the access token sent with the request.
*
*
* @throws RequiredConstraintsViolated
*/
private function getClientId(): string
{
return resolve(TokenService::class)
->validateToken(request()->input('access_token'))
->validateToken(app('request')->input('access_token'))
->claims()->get('client_id');
}
/**
* 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->pushHandler(new StreamHandler(storage_path('logs/micropub.log')));

View file

@ -98,14 +98,13 @@ class MicropubMediaController extends Controller
/**
* Process a media item posted to the media endpoint.
*
*
* @throws BindingResolutionException
* @throws Exception
*/
public function media(): JsonResponse
public function media(Request $request): JsonResponse
{
try {
$tokenData = $this->tokenService->validateToken(request()->input('access_token'));
$tokenData = $this->tokenService->validateToken($request->input('access_token'));
} catch (RequiredConstraintsViolated|InvalidTokenStructure $exception) {
$micropubResponses = new MicropubResponses();
@ -124,7 +123,7 @@ class MicropubMediaController extends Controller
return $micropubResponses->insufficientScopeResponse();
}
if (request()->hasFile('file') === false) {
if ($request->hasFile('file') === false) {
return response()->json([
'response' => 'error',
'error' => 'invalid_request',
@ -132,7 +131,7 @@ class MicropubMediaController extends Controller
], 400);
}
if (request()->file('file')->isValid() === false) {
if ($request->file('file')->isValid() === false) {
return response()->json([
'response' => 'error',
'error' => 'invalid_request',
@ -140,11 +139,11 @@ class MicropubMediaController extends Controller
], 400);
}
$filename = $this->saveFile(request()->file('file'));
$filename = $this->saveFile($request->file('file'));
$manager = resolve(ImageManager::class);
try {
$image = $manager->make(request()->file('file'));
$image = $manager->make($request->file('file'));
$width = $image->width();
} catch (NotReadableException $exception) {
// not an image
@ -152,9 +151,9 @@ class MicropubMediaController extends Controller
}
$media = Media::create([
'token' => request()->bearerToken(),
'token' => $request->bearerToken(),
'path' => 'media/' . $filename,
'type' => $this->getFileTypeFromMimeType(request()->file('file')->getMimeType()),
'type' => $this->getFileTypeFromMimeType($request->file('file')->getMimeType()),
'image_widths' => $width,
]);
@ -226,7 +225,6 @@ class MicropubMediaController extends Controller
/**
* Save an uploaded file to the local disk.
*
*
* @throws Exception
*/
private function saveFile(UploadedFile $file): string

View file

@ -9,6 +9,7 @@ use App\Services\ActivityStreamsService;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
use Jonnybarnes\IndieWeb\Numbers;
@ -19,12 +20,10 @@ class NotesController extends Controller
{
/**
* 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();
}
@ -39,11 +38,8 @@ class NotesController extends Controller
/**
* 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 {
$note = Note::nb60($urlId)->with('webmentions')->firstOrFail();
@ -60,8 +56,6 @@ class NotesController extends Controller
/**
* Redirect /note/{decID} to /notes/{nb60id}.
*
* @param int $decId The decimal id of the note
*/
public function redirect(int $decId): RedirectResponse
{

View file

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

View file

@ -24,9 +24,6 @@ class TokenEndpointController extends Controller
*/
protected GuzzleClient $guzzle;
/**
* @var TokenService The Token handling service.
*/
protected TokenService $tokenService;
/**

View file

@ -7,6 +7,7 @@ namespace App\Http\Controllers;
use App\Jobs\ProcessWebMention;
use App\Models\Note;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
use Jonnybarnes\IndieWeb\Numbers;
@ -27,10 +28,10 @@ class WebMentionsController extends Controller
/**
* Receive and process a webmention.
*/
public function receive(): Response
public function receive(Request $request): Response
{
//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(
'You need both the target and source parameters',
400
@ -38,15 +39,15 @@ class WebMentionsController extends Controller
}
//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);
if ($pathParts[1] == 'notes') {
if ($pathParts[1] === 'notes') {
//we have a note
$noteId = $pathParts[2];
try {
$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) {
return response('This note doesnt exist.', 400);
}
@ -56,7 +57,7 @@ class WebMentionsController extends Controller
202
);
}
if ($pathParts[1] == 'blog') {
if ($pathParts[1] === 'blog') {
return response(
'I dont accept webmentions for blog posts yet.',
501

View file

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

View file

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

View file

@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
/**
* @codeCoverageIgnore
@ -11,14 +12,9 @@ class Authenticate extends Middleware
{
/**
* 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 route('login');
}
return $request->expectsJson() ? null : route('login');
}
}

View file

@ -5,16 +5,14 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Response;
class CSPHeader
{
/**
* Handle an incoming request.
*
* @param Request $request
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next): Response
{
if (App::environment('local', 'development')) {
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,16 +3,15 @@
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CorsHeaders
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request$request, Closure $next): Response
{
$response = $next($request);
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.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//

View file

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

View file

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

View file

@ -7,18 +7,17 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class MyAuthMiddleware
{
/**
* Check the user is logged in.
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): Response
{
if (Auth::check($request->user()) == false) {
//theyre not logged in, so send them to login form
if (Auth::check() === false) {
// theyre not logged in, so send them to login form
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.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//

View file

@ -6,6 +6,7 @@ use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
/**
* @codeCoverageIgnore
@ -15,10 +16,9 @@ class RedirectIfAuthenticated
/**
* Handle an incoming request.
*
* @param string|null ...$guards
* @return mixed
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next, ...$guards)
public function handle(Request $request, Closure $next, string ...$guards): Response
{
$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.
*
* @var array
* @var array<int, string>
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];

View file

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

View file

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

View file

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

View file

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

View file

@ -18,24 +18,22 @@ class AddClientToDatabase implements ShouldQueue
use Queueable;
use SerializesModels;
protected $client_id;
protected string $client_id;
/**
* Create a new job instance.
*/
public function __construct(string $client_id)
public function __construct(string $clientId)
{
$this->client_id = $client_id;
$this->client_id = $clientId;
}
/**
* 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([
'client_url' => $this->client_id,
'client_name' => $this->client_id, // default client name is the URL

View file

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

View file

@ -20,14 +20,12 @@ class ProcessBookmark implements ShouldQueue
use Queueable;
use SerializesModels;
protected Bookmark $bookmark;
/**
* Create a new job instance.
*/
public function __construct(Bookmark $bookmark)
{
$this->bookmark = $bookmark;
public function __construct(
protected Bookmark $bookmark
) {
}
/**

View file

@ -25,21 +25,17 @@ class ProcessLike implements ShouldQueue
use Queueable;
use SerializesModels;
/** @var Like */
protected $like;
/**
* Create a new job instance.
*/
public function __construct(Like $like)
{
$this->like = $like;
public function __construct(
protected Like $like
) {
}
/**
* Execute the job.
*
*
* @throws GuzzleException
*/
public function handle(Client $client, Authorship $authorship): int

View file

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

View file

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

View file

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

View file

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

View file

@ -22,20 +22,17 @@ class SendWebMentions implements ShouldQueue
use Queueable;
use SerializesModels;
protected Note $note;
/**
* Create the job instance, inject dependencies.
* Create a new job instance.
*/
public function __construct(Note $note)
{
$this->note = $note;
public function __construct(
protected Note $note
) {
}
/**
* Execute the job.
*
*
* @throws GuzzleException
*/
public function handle(): void
@ -60,7 +57,6 @@ class SendWebMentions implements ShouldQueue
/**
* Discover if a URL has a webmention endpoint.
*
*
* @throws GuzzleException
*/
public function discoverWebmentionEndpoint(string $url): ?string
@ -126,8 +122,6 @@ class SendWebMentions implements ShouldQueue
/**
* Resolve a URI if necessary.
*
* @param string $base The base of the URL
*/
public function resolveUri(string $url, string $base): string
{

View file

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

View file

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

View file

@ -18,15 +18,12 @@ class SyndicateNoteToTwitter implements ShouldQueue
use Queueable;
use SerializesModels;
/** @var Note */
protected $note;
/**
* Create a new job instance.
*/
public function __construct(Note $note)
{
$this->note = $note;
public function __construct(
protected Note $note
) {
}
/**

View file

@ -24,20 +24,24 @@ class Article extends Model
use Sluggable;
use SoftDeletes;
/**
* 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
*/
/** @var string */
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.
*/
@ -50,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
{
return Attribute::get(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -58,73 +58,46 @@ class Note extends Model
$this->contacts = null;
}
/**
* The database table used by the model.
*
* @var string
*/
/** @var string */
protected $table = 'notes';
/**
* Mass-assignment.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = [
'note',
'in_reply_to',
'client_id',
];
/**
* Hide the column used with Laravel Scout.
*
* @var array
*/
/** @var array<int, string> */
protected $hidden = ['searchable'];
/**
* Define the relationship with tags.
*/
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class);
}
/**
* Define the relationship with clients.
*/
public function client(): BelongsTo
{
return $this->belongsTo(MicropubClient::class, 'client_id', 'client_url');
}
/**
* Define the relationship with webmentions.
*/
public function webmentions(): MorphMany
{
return $this->morphMany(WebMention::class, 'commentable');
}
/**
* Define the relationship with places.
*/
public function place(): BelongsTo
{
return $this->belongsTo(Place::class);
}
/**
* Define the relationship with media.
*/
public function media(): HasMany
{
return $this->hasMany(Media::class);
}
/**
* Set the attributes to be indexed for searching with Scout.
* @return array<int, string>
*/
public function toSearchableArray(): array
{
@ -133,9 +106,6 @@ class Note extends Model
];
}
/**
* Normalize the note to Unicode FORM C.
*/
public function setNoteAttribute(?string $value): void
{
if ($value !== null) {
@ -195,58 +165,37 @@ class Note extends Model
return $note;
}
/**
* Generate the NewBase60 ID from primary ID.
*/
public function getNb60idAttribute(): string
{
// we cast to string because sometimes the nb60id is an “int”
return (string) resolve(Numbers::class)->numto60($this->id);
}
/**
* The Long URL for a note.
*/
public function getLongurlAttribute(): string
{
return config('app.url') . '/notes/' . $this->nb60id;
}
/**
* The Short URL for a note.
*/
public function getShorturlAttribute(): string
{
return config('app.shorturl') . '/notes/' . $this->nb60id;
}
/**
* Get the ISO8601 value for mf2.
*/
public function getIso8601Attribute(): string
{
return $this->updated_at->toISO8601String();
}
/**
* Get the ISO8601 value for mf2.
*/
public function getHumandiffAttribute(): string
{
return $this->updated_at->diffForHumans();
}
/**
* Get the publish date value for RSS feeds.
*/
public function getPubdateAttribute(): string
{
return $this->updated_at->toRSSString();
}
/**
* Get the latitude value.
*/
public function getLatitudeAttribute(): ?float
{
if ($this->place !== null) {
@ -262,9 +211,6 @@ class Note extends Model
return null;
}
/**
* Get the longitude value.
*/
public function getLongitudeAttribute(): ?float
{
if ($this->place !== null) {
@ -281,8 +227,9 @@ class Note extends Model
}
/**
* Get the address for a note. This is either a reverse geo-code from the
* location, or is derived from the associated place.
* Get the address for a note.
*
* This is either a reverse geo-code from the location, or is derived from the associated place.
*/
public function getAddressAttribute(): ?string
{
@ -337,9 +284,6 @@ class Note extends Model
* Show a specific form of the note for twitter.
*
* That is we swap the contacts names for their known Twitter handles.
*
*
* @throws TwitterContentException
*/
public function getTwitterContentAttribute(): string
{
@ -389,7 +333,7 @@ class Note extends Model
}
/**
* Swap contacts nicks for a full mf2 h-card.
* Swap contacts nicks for a full mf2 h-card.
*
* Take note that this method does two things, given @username (NOT [@username](URL)!)
* we try to create a fancy hcard from our contact info. If this is not possible
@ -473,9 +417,6 @@ class Note extends Model
);
}
/**
* Pass a note through the commonmark library.
*/
private function convertMarkdown(string $note): string
{
$config = [
@ -500,9 +441,6 @@ class Note extends Model
return $markdownConverter->convert($note)->getContent();
}
/**
* Do a reverse geocode lookup of a `lat,lng` value.
*/
public function reverseGeoCode(float $latitude, float $longitude): string
{
$latLng = $latitude . ',' . $longitude;

View file

@ -17,36 +17,20 @@ class Place extends Model
use HasFactory;
use Sluggable;
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
public function getRouteKeyName(): string
{
return 'slug';
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['name', 'slug'];
/**
* The attributes that should be cast.
*
* @var array
*/
/** @var array<string, string> */
protected $casts = [
'latitude' => 'float',
'longitude' => 'float',
];
/**
* Return the sluggable configuration array for this model.
*/
public function sluggable(): array
{
return [
@ -57,12 +41,7 @@ class Place extends Model
];
}
/**
* Define the relationship with Notes.
*
* @return HasMany
*/
public function notes()
public function notes(): HasMany
{
return $this->hasMany('App\Models\Note');
}

View file

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

View file

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

View file

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

View file

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

View file

@ -14,7 +14,7 @@ class NoteObserver
/**
* Listen to the Note created event.
*/
public function created(Note $note)
public function created(Note $note): void
{
$text = Arr::get($note->getAttributes(), 'note');
if ($text === null) {
@ -36,7 +36,7 @@ class NoteObserver
/**
* Listen to the Note updated event.
*/
public function updated(Note $note)
public function updated(Note $note): void
{
$text = Arr::get($note->getAttributes(), 'note');
if ($text === null) {
@ -60,7 +60,7 @@ class NoteObserver
/**
* Listen to the Note deleting event.
*/
public function deleting(Note $note)
public function deleting(Note $note): void
{
$note->tags()->detach();
}

View file

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

View file

@ -7,16 +7,16 @@ use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvid
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 = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any application authentication / authorization services.
* Register any authentication / authorization services.
*/
public function boot(): void
{

View file

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

View file

@ -10,9 +10,9 @@ use Illuminate\Support\Facades\Event;
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 = [
Registered::class => [
@ -22,13 +22,9 @@ class EventServiceProvider extends ServiceProvider
/**
* 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.
*
* @return void
*/
public function boot()
public function boot(): void
{
parent::boot();
@ -28,10 +26,8 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
* Register the Horizon gate.
*
* 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) {
return $user->name === 'jonny';

View file

@ -11,46 +11,38 @@ use Illuminate\Support\Facades\Route;
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.
*
* @return void
* Define your route model bindings, pattern filters, and other route configuration.
*/
public function boot()
public function boot(): void
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*
* @codeCoverageIgnore
*/
protected function configureRateLimiting()
protected function configureRateLimiting(): void
{
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;
use App\Models\Note;
use Illuminate\Http\Response;
class ActivityStreamsService
{
/**
* 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([
'@context' => 'https://www.w3.org/ns/activitystreams',
@ -28,10 +27,8 @@ class ActivityStreamsService
/**
* Return the relevant data to an AS2.0 request for a particular note.
*
* @return \Illuminate\Http\Response
*/
public function singleNoteResponse(Note $note)
public function singleNoteResponse(Note $note): Response
{
$data = json_encode([
'@context' => 'https://www.w3.org/ns/activitystreams',

View file

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

View file

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

View file

@ -11,8 +11,6 @@ class HCardService
{
/**
* Create a Place from h-card data, return the URL.
*
* @param array $request Data from request()->all()
*/
public function process(array $request): string
{
@ -28,8 +26,7 @@ class HCardService
$data['latitude'] = Arr::get($request, 'latitude');
$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,10 +13,7 @@ use Illuminate\Support\Arr;
class HEntryService
{
/**
* Create the relavent model from some h-entry data.
*
* @param array $request Data from request()->all()
* @param string|null $client The micropub client that made the request
* Create the relevant model from some h-entry data.
*/
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\Note;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
@ -14,11 +15,8 @@ class UpdateService
{
/**
* 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);
@ -42,10 +40,10 @@ class UpdateService
//got the note, are we dealing with a “replace” request?
if (Arr::get($request, 'replace')) {
foreach (Arr::get($request, 'replace') as $property => $value) {
if ($property == 'content') {
if ($property === 'content') {
$note->note = $value[0];
}
if ($property == 'syndication') {
if ($property === 'syndication') {
foreach ($value as $syndicationURL) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL;
@ -69,7 +67,7 @@ class UpdateService
//how about “add”
if (Arr::get($request, 'add')) {
foreach (Arr::get($request, 'add') as $property => $value) {
if ($property == 'syndication') {
if ($property === 'syndication') {
foreach ($value as $syndicationURL) {
if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) {
$note->facebook_url = $syndicationURL;
@ -82,7 +80,7 @@ class UpdateService
}
}
}
if ($property == 'photo') {
if ($property === 'photo') {
foreach ($value as $photoURL) {
if (Str::startsWith($photoURL, 'https://')) {
$media = new Media();

View file

@ -18,8 +18,6 @@ class NoteService extends Service
{
/**
* Create a new note.
*
* @param array $request Data from request()->all()
*/
public function create(array $request, ?string $client = null): Note
{
@ -66,8 +64,6 @@ class NoteService extends Service
/**
* Get the published time from the request to create a new note.
*
* @param array $request Data from request()->all()
*/
private function getPublished(array $request): ?string
{
@ -84,13 +80,11 @@ class NoteService extends Service
/**
* Get the location data from the request to create a new note.
*
* @param array $request Data from request()->all()
*/
private function getLocation(array $request): ?string
{
$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(
'/([0-9\.\-]+)/',
$location,
@ -105,8 +99,6 @@ class NoteService extends Service
/**
* Get the checkin data from the request to create a new note. This will be a Place.
*
* @param array $request Data from request()->all()
*/
private function getCheckin(array $request): ?Place
{
@ -150,12 +142,10 @@ class NoteService extends Service
/**
* Get the Swarm URL from the syndication data in the request to create a new note.
*
* @param array $request Data from request()->all()
*/
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');
}
@ -164,8 +154,6 @@ class NoteService extends Service
/**
* Get the syndication targets from the request to create a new note.
*
* @param array $request Data from request()->all()
*/
private function getSyndicationTargets(array $request): array
{
@ -187,8 +175,6 @@ class NoteService extends Service
/**
* Get the media URLs from the request to create a new note.
*
* @param array $request Data from request()->all()
*/
private function getMedia(array $request): array
{
@ -216,8 +202,6 @@ class NoteService extends Service
/**
* Get the Instagram photo URL from the request to create a new note.
*
* @param array $request Data from request()->all()
*/
private function getInstagramUrl(array $request): ?string
{

View file

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

View file

@ -13,9 +13,6 @@ class TokenService
{
/**
* Generate a JWT token.
*
* @param array The data to be encoded
* @return string The signed token
*/
public function getNewToken(array $data): string
{
@ -36,9 +33,6 @@ class TokenService
/**
* Check the token signature is valid.
*
* @param string The token
* @return mixed
*/
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
| 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
| loading of any our classes "manually". Feels great to relax.
| loading of any of our classes manually. It's great to relax.
|
*/

View file

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

View file

@ -84,12 +84,16 @@ return [
| considered valid. This security feature keeps tokens short-lived so
| 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' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'table' => 'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],

View file

@ -28,7 +28,7 @@ return [
| 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.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
| "postmark", "log", "array", "failover"
|
*/
@ -51,10 +51,16 @@ return [
'mailgun' => [
'transport' => 'mailgun',
// 'client' => [
// 'timeout' => 5,
// ],
],
'postmark' => [
'transport' => 'postmark',
// 'client' => [
// 'timeout' => 5,
// ],
],
'sendmail' => [

View file

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

View file

@ -6,6 +6,9 @@ use App\Models\Bookmark;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Bookmark>
*/
class BookmarkFactory extends Factory
{
/**
@ -18,9 +21,9 @@ class BookmarkFactory extends Factory
/**
* 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));

View file

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

View file

@ -6,6 +6,9 @@ use App\Models\Like;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Like>
*/
class LikeFactory extends Factory
{
/**
@ -18,9 +21,9 @@ class LikeFactory extends Factory
/**
* 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));

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,38 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (! Schema::hasTable('articles')) {
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('titleurl', 50)->unique();
$table->string('url', 120)->nullable();
$table->string('title');
$table->longText('main');
$table->tinyInteger('published')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('articles');
}
}

View file

@ -1,40 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateNotesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (! Schema::hasTable('notes')) {
Schema::create('notes', function (Blueprint $table) {
$table->increments('id');
$table->text('note');
$table->string('in_reply_to')->nullable();
$table->string('shorturl', 20)->nullable();
$table->string('location')->nullable();
$table->tinyInteger('photo')->nullable();
$table->string('tweet_id')->nullable();
$table->string('client_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('notes');
}
}

View file

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateTagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
$table->string('tag');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('tags');
}
}

View file

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateNoteTagTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('note_tag', function (Blueprint $table) {
$table->increments('id');
$table->integer('note_id')->unsigned();
$table->integer('tag_id')->unsigned();
$table->foreign('note_id')->references('id')->on('notes');
$table->foreign('tag_id')->references('id')->on('tags');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('note_tag');
}
}

View file

@ -1,34 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateContactsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('contacts', function (Blueprint $table) {
$table->increments('id');
$table->string('nick');
$table->string('name');
$table->string('homepage')->nullable();
$table->string('twitter')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('contacts');
}
}

View file

@ -1,38 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateWebMentionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('webmentions', function (Blueprint $table) {
$table->increments('id');
$table->string('source');
$table->string('target');
$table->integer('commentable_id')->nullable();
$table->string('commentable_type')->nullable();
$table->string('type')->nullable();
$table->text('content')->nullable();
$table->tinyInteger('verified')->default(1);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('webmentions');
}
}

View file

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateClientsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('clients', function (Blueprint $table) {
$table->increments('id');
$table->string('client_url');
$table->string('client_name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('clients');
}
}

View file

@ -1,36 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMediaTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('media', function (Blueprint $table) {
$table->increments('id');
$table->morphs('model');
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
$table->string('disk');
$table->unsignedInteger('size');
$table->text('manipulations');
$table->text('custom_properties');
$table->unsignedInteger('order_column')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::drop('media');
}
}

View file

@ -1,35 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreatePlacesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('places', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->text('location');
$table->text('polygon')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('places');
}
}

View file

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddPlaceRelationToNotes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('notes', function (Blueprint $table) {
$table->integer('place_id')->unsigned()->nullable();
$table->foreign('place_id')->references('id')->on('places');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('notes', function (Blueprint $table) {
$table->dropForeign('notes_place_id_foreign');
$table->dropColumn('place_id');
});
}
}

View file

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddJsonbMf2ColumnToWebmentionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('webmentions', function (Blueprint $table) {
$table->jsonb('mf2')->nullable();
$table->index(['mf2']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('webmentions', function (Blueprint $table) {
$table->dropIndex(['mf2']);
$table->dropColumn('mf2');
});
}
}

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