Fixing various phpcs issues

This commit is contained in:
Jonny Barnes 2019-10-27 19:31:33 +00:00
parent 21c89f721c
commit ef03d2209f
18 changed files with 148 additions and 90 deletions

View file

@ -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)

View file

@ -16,7 +16,7 @@ class ArticlesController extends Controller
*
* @param int $year
* @param int $month
* @return \Illuminate\View\View
* @return View
*/
public function index(int $year = null, int $month = null): View
{
@ -34,7 +34,7 @@ class ArticlesController extends Controller
* @param int $year
* @param int $month
* @param string $slug
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
* @return RedirectResponse|View
*/
public function show(int $year, int $month, string $slug)
{
@ -54,7 +54,7 @@ class ArticlesController extends Controller
* and redirect to it.
*
* @param int $idFromUrl
* @return \Illuminte\Http\RedirectResponse
* @return RedirectResponse
*/
public function onlyIdInUrl(int $idFromUrl): RedirectResponse
{

View file

@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
}

View file

@ -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()
@ -39,14 +41,14 @@ class NotesController extends Controller
* Show a single note.
*
* @param string $urlId The id of the note
* @return \Illuminate\View\View|\Illuminate\Http\JsonResponse
* @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'));
@ -56,7 +58,7 @@ class NotesController extends Controller
* Redirect /note/{decID} to /notes/{nb60id}.
*
* @param int $decId The decimal id of the note
* @return \Illuminate\Http\RedirectResponse
* @return RedirectResponse
*/
public function redirect(int $decId): RedirectResponse
{
@ -67,7 +69,7 @@ class NotesController extends Controller
* Show all notes tagged with {tag}.
*
* @param string $tag
* @return \Illuminate\View\View
* @return View
*/
public function tagged(string $tag): View
{

View file

@ -13,7 +13,10 @@ use Illuminate\Queue\SerializesModels;
class AddClientToDatabase implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
protected $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
]);

View file

@ -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,12 +15,14 @@ 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;
@ -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
* @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) == '/') {

View file

@ -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)
{

View file

@ -15,8 +15,12 @@ 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;
/**
@ -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;

View file

@ -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 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();

View file

@ -15,8 +15,11 @@ use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
class SaveProfileImage implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/** @var array */
protected $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));

View file

@ -6,16 +6,22 @@ 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;
/**
@ -102,13 +108,14 @@ class SendWebMentions implements ShouldQueue
* Get the URLs from a note.
*
* @param string $html
* @return array $urls
* @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.
*
* @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
);
}

View file

@ -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)
{

View file

@ -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)
{

View file

@ -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');
}

View file

@ -10,10 +10,10 @@ 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
{
@ -21,7 +21,7 @@ class BookmarkService
* Create a new Bookmark.
*
* @param array $request Data from request()->all()
* @return Bookmark $bookmark
* @return Bookmark
*/
public function createBookmark(array $request): Bookmark
{
@ -83,6 +83,7 @@ class BookmarkService
*
* @param string $url
* @return string The uuid for the screenshot
* @throws CouldNotTakeBrowsershot
*/
public function saveScreenshot(string $url): string
{
@ -104,6 +105,7 @@ class BookmarkService
*
* @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();
}
}

View file

@ -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",

View file

@ -2,7 +2,5 @@
<ruleset name="jonnybarnes.uk">
<description>Custom configuration for code running jonnybarnes.uk</description>
<file>./app/</file>
<rule ref="PSR2">
<exclude name="PSR2.Namespaces.UseDeclaration" />
</rule>
<rule ref="PSR12" />
</ruleset>