fix style

This commit is contained in:
shibafu 2019-03-03 00:29:43 +09:00
parent f21e58650d
commit e966995dea
9 changed files with 12 additions and 8 deletions

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Metadata; use App\Metadata;
use App\MetadataResolver\MetadataResolver; use App\MetadataResolver\MetadataResolver;
use App\Utilities\Formatter; use App\Utilities\Formatter;

View File

@ -2,8 +2,8 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware; use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware class TrustProxies extends Middleware
{ {

View File

@ -2,9 +2,9 @@
namespace App\MetadataResolver; namespace App\MetadataResolver;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Exception\TransferException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
class ActivityPubResolver implements Resolver, Parser class ActivityPubResolver implements Resolver, Parser
{ {
@ -40,7 +40,7 @@ class ActivityPubResolver implements Resolver, Parser
$metadata = new Metadata(); $metadata = new Metadata();
$metadata->title = isset($object['attributedTo']) ? $this->getTitleFromActor($object['attributedTo']) : ''; $metadata->title = isset($object['attributedTo']) ? $this->getTitleFromActor($object['attributedTo']) : '';
$metadata->description .= isset($object['summary']) ? $object['summary'] . " | " : ''; $metadata->description .= isset($object['summary']) ? $object['summary'] . ' | ' : '';
$metadata->description .= isset($object['content']) ? $this->html2text($object['content']) : ''; $metadata->description .= isset($object['content']) ? $this->html2text($object['content']) : '';
$metadata->image = $object['attachment'][0]['url'] ?? ''; $metadata->image = $object['attachment'][0]['url'] ?? '';
@ -53,6 +53,7 @@ class ActivityPubResolver implements Resolver, Parser
$res = $this->activityClient->get($url); $res = $this->activityClient->get($url);
if ($res->getStatusCode() !== 200) { if ($res->getStatusCode() !== 200) {
Log::info(self::class . ': Actorの取得に失敗 URL=' . $url); Log::info(self::class . ': Actorの取得に失敗 URL=' . $url);
return ''; return '';
} }
@ -65,6 +66,7 @@ class ActivityPubResolver implements Resolver, Parser
return $title; return $title;
} catch (TransferException $e) { } catch (TransferException $e) {
Log::info(self::class . ': Actorの取得に失敗 URL=' . $url); Log::info(self::class . ': Actorの取得に失敗 URL=' . $url);
return ''; return '';
} }
} }
@ -75,6 +77,7 @@ class ActivityPubResolver implements Resolver, Parser
$html = preg_replace('~<br\s*/?\s*>|</p>\s*<p[^>]*>~i', "\n", $html); $html = preg_replace('~<br\s*/?\s*>|</p>\s*<p[^>]*>~i', "\n", $html);
$dom = new \DOMDocument(); $dom = new \DOMDocument();
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
return $dom->textContent; return $dom->textContent;
} }
} }

View File

@ -21,6 +21,7 @@ class FantiaResolver implements Resolver
$this->client = $client; $this->client = $client;
$this->ogpResolver = $ogpResolver; $this->ogpResolver = $ogpResolver;
} }
public function resolve(string $url): Metadata public function resolve(string $url): Metadata
{ {
preg_match("~\d+~", $url, $match); preg_match("~\d+~", $url, $match);

View File

@ -53,6 +53,7 @@ class MetadataResolver implements Resolver
if (isset($this->defaultResolver)) { if (isset($this->defaultResolver)) {
/** @var Resolver $resolver */ /** @var Resolver $resolver */
$resolver = app($this->defaultResolver); $resolver = app($this->defaultResolver);
return $resolver->resolve($url); return $resolver->resolve($url);
} }

View File

@ -28,7 +28,6 @@ class ToranoanaResolver implements Resolver
$res = $this->client->get($url, ['cookies' => $cookieJar]); $res = $this->client->get($url, ['cookies' => $cookieJar]);
if ($res->getStatusCode() === 200) { if ($res->getStatusCode() === 200) {
return $this->ogpResolver->parse($res->getBody()); return $this->ogpResolver->parse($res->getBody());
} else { } else {
throw new \RuntimeException("{$res->getStatusCode()}: $url"); throw new \RuntimeException("{$res->getStatusCode()}: $url");

View File

@ -1,8 +1,8 @@
<?php <?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBioAndUrlToUsers extends Migration class AddBioAndUrlToUsers extends Migration
{ {

View File

@ -43,6 +43,7 @@ trait CreateMockedResolver
$this->handler = new MockHandler([$mockResponse]); $this->handler = new MockHandler([$mockResponse]);
$client = new Client(['handler' => $this->handler]); $client = new Client(['handler' => $this->handler]);
$this->resolver = app()->make($resolverClass, ['client' => $client]); $this->resolver = app()->make($resolverClass, ['client' => $client]);
return $this->resolver; return $this->resolver;
} }