Updated Visit entity so that the short URL is nullable

This commit is contained in:
Alejandro Celaya committed 2021-02-09 23:09:42 +01:00
1 parent a1fb44f2a6
commit 23cffce861
3 files changed
+5 -12

No files matched your search

+2 -9
View File
@@ -18,7 +18,7 @@ class Visit extends AbstractEntity implements JsonSerializable
private Chronos $date; private Chronos $date;
private ?string $remoteAddr = null; private ?string $remoteAddr = null;
private string $userAgent; private string $userAgent;
private ShortUrl $shortUrl; private ?ShortUrl $shortUrl;
private ?VisitLocation $visitLocation = null; private ?VisitLocation $visitLocation = null;
public function __construct(ShortUrl $shortUrl, Visitor $visitor, bool $anonymize = true, ?Chronos $date = null) public function __construct(ShortUrl $shortUrl, Visitor $visitor, bool $anonymize = true, ?Chronos $date = null)
@@ -54,7 +54,7 @@ class Visit extends AbstractEntity implements JsonSerializable
return ! empty($this->remoteAddr); return ! empty($this->remoteAddr);
} }
public function getShortUrl(): ShortUrl public function getShortUrl(): ?ShortUrl
{ {
return $this->shortUrl; return $this->shortUrl;
} }
@@ -75,13 +75,6 @@ class Visit extends AbstractEntity implements JsonSerializable
return $this; return $this;
} }
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return array data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
@@ -10,6 +10,7 @@ use Fig\Http\Message\RequestMethodInterface;
use GuzzleHttp\ClientInterface; use GuzzleHttp\ClientInterface;
use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Promise\Utils;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
@@ -20,7 +21,6 @@ use Throwable;
use function Functional\map; use function Functional\map;
use function Functional\partial_left; use function Functional\partial_left;
use function GuzzleHttp\Promise\settle;
class NotifyVisitToWebHooks class NotifyVisitToWebHooks
{ {
@@ -69,7 +69,7 @@ class NotifyVisitToWebHooks
$requestPromises = $this->performRequests($requestOptions, $visitId); $requestPromises = $this->performRequests($requestOptions, $visitId);
// Wait for all the promises to finish, ignoring rejections, as in those cases we only want to log the error. // Wait for all the promises to finish, ignoring rejections, as in those cases we only want to log the error.
settle($requestPromises)->wait(); Utils::settle($requestPromises)->wait();
} }
private function buildRequestOptions(Visit $visit): array private function buildRequestOptions(Visit $visit): array
@@ -38,7 +38,7 @@ final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface
$topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl->getShortCode()); $topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl->getShortCode());
return new Update($topic, $this->serialize([ return new Update($topic, $this->serialize([
'shortUrl' => $this->transformer->transform($visit->getShortUrl()), 'shortUrl' => $this->transformer->transform($shortUrl),
'visit' => $visit, 'visit' => $visit,
])); ]));
} }