diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d76fb55e..a6ed6c7c 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -21,7 +21,7 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @param Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) @@ -37,7 +37,7 @@ class Kernel extends ConsoleKernel */ protected function commands() { - $this->load(__DIR__.'/Commands'); + $this->load(__DIR__ . '/Commands'); require base_path('routes/console.php'); } diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php index 3c1e9f21..c8e13a77 100644 --- a/app/Http/Controllers/ArticlesController.php +++ b/app/Http/Controllers/ArticlesController.php @@ -14,9 +14,9 @@ class ArticlesController extends Controller /** * Show all articles (with pagination). * - * @param int $year - * @param int $month - * @return \Illuminate\View\View + * @param int $year + * @param int $month + * @return View */ public function index(int $year = null, int $month = null): View { @@ -31,10 +31,10 @@ class ArticlesController extends Controller /** * Show a single article. * - * @param int $year - * @param int $month - * @param string $slug - * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View + * @param int $year + * @param int $month + * @param string $slug + * @return RedirectResponse|View */ public function show(int $year, int $month, string $slug) { @@ -43,7 +43,7 @@ class ArticlesController extends Controller return redirect('/blog/' . $article->updated_at->year . '/' . $article->updated_at->format('m') - .'/' . $slug); + . '/' . $slug); } return view('articles.show', compact('article')); @@ -53,8 +53,8 @@ class ArticlesController extends Controller * We only have the ID, work out post title, year and month * and redirect to it. * - * @param int $idFromUrl - * @return \Illuminte\Http\RedirectResponse + * @param int $idFromUrl + * @return RedirectResponse */ public function onlyIdInUrl(int $idFromUrl): RedirectResponse { diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a0a2a8a3..ce1176dd 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + use AuthorizesRequests; + use DispatchesJobs; + use ValidatesRequests; } diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index 92e4ee5d..72994314 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -6,8 +6,10 @@ namespace App\Http\Controllers; use App\Models\Note; use App\Services\ActivityStreamsService; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\View\View; use Jonnybarnes\IndieWeb\Numbers; @@ -18,12 +20,12 @@ class NotesController extends Controller /** * Show all the notes. This is also the homepage. * - * @return \Illuminate\View\View|\Illuminate\Http\JsonResponse + * @return ViewFactory|View|Response */ public function index() { if (request()->wantsActivityStream()) { - return (new ActivityStreamsService)->siteOwnerResponse(); + return (new ActivityStreamsService())->siteOwnerResponse(); } $notes = Note::latest() @@ -38,15 +40,15 @@ class NotesController extends Controller /** * Show a single note. * - * @param string $urlId The id of the note - * @return \Illuminate\View\View|\Illuminate\Http\JsonResponse + * @param string $urlId The id of the note + * @return View|JsonResponse|Response */ public function show(string $urlId) { $note = Note::nb60($urlId)->with('webmentions')->firstOrFail(); if (request()->wantsActivityStream()) { - return (new ActivityStreamsService)->singleNoteResponse($note); + return (new ActivityStreamsService())->singleNoteResponse($note); } return view('notes.show', compact('note')); @@ -55,8 +57,8 @@ class NotesController extends Controller /** * Redirect /note/{decID} to /notes/{nb60id}. * - * @param int $decId The decimal id of the note - * @return \Illuminate\Http\RedirectResponse + * @param int $decId The decimal id of the note + * @return RedirectResponse */ public function redirect(int $decId): RedirectResponse { @@ -66,8 +68,8 @@ class NotesController extends Controller /** * Show all notes tagged with {tag}. * - * @param string $tag - * @return \Illuminate\View\View + * @param string $tag + * @return View */ public function tagged(string $tag): View { diff --git a/app/Http/Middleware/CSPHeader.php b/app/Http/Middleware/CSPHeader.php index 1725380e..cfd2e1dc 100644 --- a/app/Http/Middleware/CSPHeader.php +++ b/app/Http/Middleware/CSPHeader.php @@ -65,12 +65,12 @@ block-all-mixed-content; \ report-to csp-endpoint; \ report-uri https://jonnybarnes.report-uri.io/r/default/csp/enforce;") )->header( - 'Report-To', - '{' . + 'Report-To', + '{' . "'url': 'https://jonnybarnes.report-uri.io/r/default/csp/enforce', " . "'group': 'csp-endpoint'," . "'max-age': 10886400" . - '}' - ); + '}' + ); } } diff --git a/app/Jobs/AddClientToDatabase.php b/app/Jobs/AddClientToDatabase.php index c7f801dc..1263b0fa 100644 --- a/app/Jobs/AddClientToDatabase.php +++ b/app/Jobs/AddClientToDatabase.php @@ -13,14 +13,17 @@ use Illuminate\Queue\SerializesModels; class AddClientToDatabase implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; protected $client_id; /** * Create a new job instance. * - * @param string $client_id + * @param string $client_id */ public function __construct(string $client_id) { @@ -35,7 +38,7 @@ class AddClientToDatabase implements ShouldQueue public function handle() { if (MicropubClient::where('client_url', $this->client_id)->count() == 0) { - $client = MicropubClient::create([ + MicropubClient::create([ 'client_url' => $this->client_id, 'client_name' => $this->client_id, // default client name is the URL ]); diff --git a/app/Jobs/DownloadWebMention.php b/app/Jobs/DownloadWebMention.php index dbe0a34a..087dab50 100644 --- a/app/Jobs/DownloadWebMention.php +++ b/app/Jobs/DownloadWebMention.php @@ -5,7 +5,9 @@ declare(strict_types=1); namespace App\Jobs; use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\FileSystem\FileSystem; use Illuminate\Queue\InteractsWithQueue; @@ -13,19 +15,21 @@ use Illuminate\Queue\SerializesModels; class DownloadWebMention implements ShouldQueue { - use InteractsWithQueue, Queueable, SerializesModels; + use InteractsWithQueue; + use Queueable; + use SerializesModels; /** * The webmention source URL. * - * @var + * @var string */ protected $source; /** * Create a new job instance. * - * @param string $source + * @param string $source */ public function __construct(string $source) { @@ -35,7 +39,9 @@ class DownloadWebMention implements ShouldQueue /** * Execute the job. * - * @param \GuzzleHttp\Client $guzzle + * @param Client $guzzle + * @throws GuzzleException + * @throws FileNotFoundException */ public function handle(Client $guzzle) { @@ -73,13 +79,12 @@ 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 The URL - * @return string The path name + * @param string $url + * @return string The path name */ - private function createFilenameFromURL($url) + private function createFilenameFromURL(string $url) { $filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url); if (substr($filepath, -1) == '/') { diff --git a/app/Jobs/ProcessBookmark.php b/app/Jobs/ProcessBookmark.php index fcb35432..d38edcd6 100644 --- a/app/Jobs/ProcessBookmark.php +++ b/app/Jobs/ProcessBookmark.php @@ -15,14 +15,18 @@ use Illuminate\Queue\SerializesModels; class ProcessBookmark implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var Bookmark */ protected $bookmark; /** * Create a new job instance. * - * @param \App\Models\Bookmark $bookmark + * @param Bookmark $bookmark */ public function __construct(Bookmark $bookmark) { diff --git a/app/Jobs/ProcessMedia.php b/app/Jobs/ProcessMedia.php index 6001cb67..4fadb397 100644 --- a/app/Jobs/ProcessMedia.php +++ b/app/Jobs/ProcessMedia.php @@ -15,14 +15,18 @@ use Intervention\Image\ImageManager; class ProcessMedia implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var string */ protected $filename; /** * Create a new job instance. * - * @param string $filename + * @param string $filename */ public function __construct(string $filename) { @@ -32,7 +36,7 @@ class ProcessMedia implements ShouldQueue /** * Execute the job. * - * @param \Intervention\Image\ImageManager $manager + * @param ImageManager $manager */ public function handle(ImageManager $manager) { @@ -49,7 +53,7 @@ class ProcessMedia implements ShouldQueue if ($image->width() > 1000) { $filenameParts = explode('.', $this->filename); $extension = array_pop($filenameParts); - // the following acheives this data flow + // the following achieves this data flow // foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar $basename = ltrim(array_reduce($filenameParts, function ($carry, $item) { return $carry . '.' . $item; @@ -57,7 +61,7 @@ class ProcessMedia implements ShouldQueue $medium = $image->resize(1000, null, function ($constraint) { $constraint->aspectRatio(); }); - Storage::disk('s3')->put('media/'. $basename . '-medium.' . $extension, (string) $medium->encode()); + Storage::disk('s3')->put('media/' . $basename . '-medium.' . $extension, (string) $medium->encode()); $small = $image->resize(500, null, function ($constraint) { $constraint->aspectRatio(); }); diff --git a/app/Jobs/ProcessWebMention.php b/app/Jobs/ProcessWebMention.php index 692f2731..a6e7d3a0 100644 --- a/app/Jobs/ProcessWebMention.php +++ b/app/Jobs/ProcessWebMention.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace App\Jobs; use App\Exceptions\RemoteContentNotFoundException; +use GuzzleHttp\Exception\GuzzleException; +use Jonnybarnes\WebmentionsParser\Exceptions\InvalidMentionException; use App\Models\{Note, WebMention}; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; @@ -16,18 +18,23 @@ use Mf2; class ProcessWebMention implements ShouldQueue { - use InteractsWithQueue, Queueable, SerializesModels; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var Note */ protected $note; + + /** @var string */ protected $source; /** * Create a new job instance. * - * @param \App\Note $note - * @param string $source + * @param Note $note + * @param string $source */ - public function __construct(Note $note, $source) + public function __construct(Note $note, string $source) { $this->note = $note; $this->source = $source; @@ -36,15 +43,18 @@ class ProcessWebMention implements ShouldQueue /** * Execute the job. * - * @param \Jonnybarnes\WebmentionsParser\Parser $parser - * @param \GuzzleHttp\Client $guzzle + * @param Parser $parser + * @param Client $guzzle + * @throws RemoteContentNotFoundException + * @throws GuzzleException + * @throws InvalidMentionException */ public function handle(Parser $parser, Client $guzzle) { try { $response = $guzzle->request('GET', $this->source); } catch (RequestException $e) { - throw new RemoteContentNotFoundException; + throw new RemoteContentNotFoundException(); } $this->saveRemoteContent((string) $response->getBody(), $this->source); $microformats = Mf2\parse((string) $response->getBody(), $this->source); @@ -59,7 +69,7 @@ class ProcessWebMention implements ShouldQueue return; } - // webmenion is still a reply, so update content + // webmention is still a reply, so update content dispatch(new SaveProfileImage($microformats)); $webmention->mf2 = json_encode($microformats); $webmention->save(); @@ -91,7 +101,7 @@ class ProcessWebMention implements ShouldQueue $webmention->source = $this->source; $webmention->target = $this->note->longurl; $webmention->commentable_id = $this->note->id; - $webmention->commentable_type = 'App\Note'; + $webmention->commentable_type = 'App\Model\Note'; $webmention->type = $type; $webmention->mf2 = json_encode($microformats); $webmention->save(); diff --git a/app/Jobs/SaveProfileImage.php b/app/Jobs/SaveProfileImage.php index 6594db0c..44073f23 100644 --- a/app/Jobs/SaveProfileImage.php +++ b/app/Jobs/SaveProfileImage.php @@ -15,14 +15,17 @@ use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException; class SaveProfileImage implements ShouldQueue { - use InteractsWithQueue, Queueable, SerializesModels; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var array */ protected $microformats; /** * Create a new job instance. * - * @param array $microformats + * @param array $microformats */ public function __construct(array $microformats) { @@ -32,7 +35,7 @@ class SaveProfileImage implements ShouldQueue /** * Execute the job. * - * @param \Jonnybarnes\WebmentionsParser\Authorship $authorship + * @param Authorship $authorship */ public function handle(Authorship $authorship) { @@ -44,14 +47,16 @@ class SaveProfileImage implements ShouldQueue $photo = $author['properties']['photo'][0]; $home = $author['properties']['url'][0]; //dont save pbs.twimg.com links - if (parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com' - && parse_url($photo, PHP_URL_HOST) != 'twitter.com') { + if ( + parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com' + && parse_url($photo, PHP_URL_HOST) != 'twitter.com' + ) { $client = resolve(Client::class); try { $response = $client->get($photo); $image = $response->getBody(true); } catch (RequestException $e) { - // we are openning and reading the default image so that + // we are opening and reading the default image so that $default = public_path() . '/assets/profile-images/default-image'; $handle = fopen($default, 'rb'); $image = fread($handle, filesize($default)); diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index eaa303e2..6d1972a6 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -6,22 +6,28 @@ namespace App\Jobs; use App\Models\Note; use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Uri; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Str; +use function GuzzleHttp\Psr7\uri_for; + class SendWebMentions implements ShouldQueue { - use InteractsWithQueue, Queueable, SerializesModels; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var Note */ protected $note; /** * Create the job instance, inject dependencies. * - * @param Note $note + * @param Note $note */ public function __construct(Note $note) { @@ -58,7 +64,7 @@ class SendWebMentions implements ShouldQueue /** * Discover if a URL has a webmention endpoint. * - * @param string $url + * @param string $url * @return string|null */ public function discoverWebmentionEndpoint(string $url) @@ -101,14 +107,15 @@ class SendWebMentions implements ShouldQueue /** * Get the URLs from a note. * - * @param string $html - * @return array $urls + * @param string $html + * @return array */ - public function getLinks($html) + public function getLinks(string $html): array { if ($html == '' || is_null($html)) { return []; } + $urls = []; $dom = new \DOMDocument(); $dom->loadHTML($html); @@ -123,19 +130,21 @@ class SendWebMentions implements ShouldQueue /** * Resolve a URI if necessary. * - * @param string $url - * @param string $base The base of the URL + * @todo Update deprecated resolve method + * + * @param string $url + * @param string $base The base of the URL * @return string */ public function resolveUri(string $url, string $base): string { - $endpoint = \GuzzleHttp\Psr7\uri_for($url); + $endpoint = uri_for($url); if ($endpoint->getScheme() != '') { return (string) $endpoint; } - return (string) \GuzzleHttp\Psr7\Uri::resolve( - \GuzzleHttp\Psr7\uri_for($base), + return (string) Uri::resolve( + uri_for($base), $endpoint ); } diff --git a/app/Jobs/SyndicateBookmarkToTwitter.php b/app/Jobs/SyndicateBookmarkToTwitter.php index a8b7a7f2..6eb40ab7 100644 --- a/app/Jobs/SyndicateBookmarkToTwitter.php +++ b/app/Jobs/SyndicateBookmarkToTwitter.php @@ -6,6 +6,7 @@ namespace App\Jobs; use App\Models\Bookmark; use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -14,14 +15,18 @@ use Illuminate\Queue\SerializesModels; class SyndicateBookmarkToTwitter implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var Bookmark */ protected $bookmark; /** * Create a new job instance. * - * @param \App\Models\Bookmark $bookmark + * @param Bookmark $bookmark */ public function __construct(Bookmark $bookmark) { @@ -31,7 +36,8 @@ class SyndicateBookmarkToTwitter implements ShouldQueue /** * Execute the job. * - * @param \GuzzleHttp\Client $guzzle + * @param Client $guzzle + * @throws GuzzleException */ public function handle(Client $guzzle) { diff --git a/app/Jobs/SyndicateNoteToTwitter.php b/app/Jobs/SyndicateNoteToTwitter.php index 7a7e476f..4ac64a07 100644 --- a/app/Jobs/SyndicateNoteToTwitter.php +++ b/app/Jobs/SyndicateNoteToTwitter.php @@ -6,6 +6,7 @@ namespace App\Jobs; use App\Models\Note; use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; @@ -13,14 +14,17 @@ use Illuminate\Queue\SerializesModels; class SyndicateNoteToTwitter implements ShouldQueue { - use InteractsWithQueue, Queueable, SerializesModels; + use InteractsWithQueue; + use Queueable; + use SerializesModels; + /** @var Note */ protected $note; /** * Create a new job instance. * - * @param \App\Models\Note $note + * @param Note $note */ public function __construct(Note $note) { @@ -30,7 +34,8 @@ class SyndicateNoteToTwitter implements ShouldQueue /** * Execute the job. * - * @param \GuzzleHttp\Client $guzzle + * @param Client $guzzle + * @throws GuzzleException */ public function handle(Client $guzzle) { diff --git a/app/Models/Note.php b/app/Models/Note.php index 3cc8ae26..d4b09dc0 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -387,8 +387,10 @@ class Note extends Model // here we check the matched contact from the note corresponds to a contact // in the database - if (count(array_unique(array_values($this->contacts))) === 1 - && array_unique(array_values($this->contacts))[0] === null) { + if ( + count(array_unique(array_values($this->contacts))) === 1 + && array_unique(array_values($this->contacts))[0] === null + ) { throw new TwitterContentException('The matched contact is not in the database'); } diff --git a/app/Services/BookmarkService.php b/app/Services/BookmarkService.php index 16f5bfd0..871bf078 100644 --- a/app/Services/BookmarkService.php +++ b/app/Services/BookmarkService.php @@ -10,18 +10,18 @@ use App\Jobs\SyndicateBookmarkToTwitter; use App\Models\{Bookmark, Tag}; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; -use Illuminate\Http\Request; use Illuminate\Support\{Arr, Str}; use Ramsey\Uuid\Uuid; use Spatie\Browsershot\Browsershot; +use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot; class BookmarkService { /** * Create a new Bookmark. * - * @param array $request Data from request()->all() - * @return Bookmark $bookmark + * @param array $request Data from request()->all() + * @return Bookmark */ public function createBookmark(array $request): Bookmark { @@ -81,8 +81,9 @@ class BookmarkService /** * Given a URL, use browsershot to save an image of the page. * - * @param string $url + * @param string $url * @return string The uuid for the screenshot + * @throws CouldNotTakeBrowsershot */ public function saveScreenshot(string $url): string { @@ -102,8 +103,9 @@ class BookmarkService /** * Given a URL, attempt to save it to the Internet Archive. * - * @param string $url + * @param string $url * @return string + * @throws InternetArchiveException */ public function getArchiveLink(string $url): string { @@ -112,7 +114,7 @@ class BookmarkService $response = $client->request('GET', 'https://web.archive.org/save/' . $url); } catch (ClientException $e) { //throw an exception to be caught - throw new InternetArchiveException; + throw new InternetArchiveException(); } if ($response->hasHeader('Content-Location')) { if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) { @@ -121,6 +123,6 @@ class BookmarkService } //throw an exception to be caught - throw new InternetArchiveException; + throw new InternetArchiveException(); } } diff --git a/composer.json b/composer.json index 1d576568..7301b426 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "php": "^7.2", "ext-intl": "*", "ext-json": "*", + "ext-dom": "*", "cviebrock/eloquent-sluggable": "~6.0", "fideloper/proxy": "~4.0", "guzzlehttp/guzzle": "~6.0", diff --git a/phpcs.xml b/phpcs.xml index 141a41f6..c06a7330 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,7 +2,5 @@ Custom configuration for code running jonnybarnes.uk ./app/ - - - +