Fixing various phpcs issues
This commit is contained in:
parent
21c89f721c
commit
ef03d2209f
18 changed files with 148 additions and 90 deletions
|
@ -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
|
||||
]);
|
||||
|
|
|
@ -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) == '/') {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue