Updated Visit entity so that the short URL is nullable

This commit is contained in:
Alejandro Celaya
2021-02-07 11:02:50 +01:00
parent a1fb44f2a6
commit 23cffce861
3 changed files with 5 additions and 12 deletions

View File

@@ -18,7 +18,7 @@ class Visit extends AbstractEntity implements JsonSerializable
private Chronos $date;
private ?string $remoteAddr = null;
private string $userAgent;
private ShortUrl $shortUrl;
private ?ShortUrl $shortUrl;
private ?VisitLocation $visitLocation = 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);
}
public function getShortUrl(): ShortUrl
public function getShortUrl(): ?ShortUrl
{
return $this->shortUrl;
}
@@ -75,13 +75,6 @@ class Visit extends AbstractEntity implements JsonSerializable
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
{
return [

View File

@@ -10,6 +10,7 @@ use Fig\Http\Message\RequestMethodInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Promise\Utils;
use GuzzleHttp\RequestOptions;
use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
@@ -20,7 +21,6 @@ use Throwable;
use function Functional\map;
use function Functional\partial_left;
use function GuzzleHttp\Promise\settle;
class NotifyVisitToWebHooks
{
@@ -69,7 +69,7 @@ class NotifyVisitToWebHooks
$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.
settle($requestPromises)->wait();
Utils::settle($requestPromises)->wait();
}
private function buildRequestOptions(Visit $visit): array

View File

@@ -38,7 +38,7 @@ final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface
$topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl->getShortCode());
return new Update($topic, $this->serialize([
'shortUrl' => $this->transformer->transform($visit->getShortUrl()),
'shortUrl' => $this->transformer->transform($shortUrl),
'visit' => $visit,
]));
}