Removed public readonly prop from entity, as it can cause errors when a proxy is generated

This commit is contained in:
Alejandro Celaya 2023-01-15 13:12:17 +01:00
parent a93edf158e
commit d8add9291f
2 changed files with 8 additions and 3 deletions

View File

@ -12,7 +12,7 @@ class DeviceLongUrl extends AbstractEntity
{
private function __construct(
private readonly ShortUrl $shortUrl, // No need to read this field. It's used by doctrine
public readonly DeviceType $deviceType,
private readonly DeviceType $deviceType,
private string $longUrl,
) {
}
@ -27,6 +27,11 @@ class DeviceLongUrl extends AbstractEntity
return $this->longUrl;
}
public function deviceType(): DeviceType
{
return $this->deviceType;
}
public function updateLongUrl(string $longUrl): void
{
$this->longUrl = $longUrl;

View File

@ -170,7 +170,7 @@ class ShortUrl extends AbstractEntity
}
foreach ($shortUrlEdit->deviceLongUrls as $deviceLongUrlPair) {
$deviceLongUrl = $this->deviceLongUrls->findFirst(
fn ($_, DeviceLongUrl $d) => $d->deviceType === $deviceLongUrlPair->deviceType,
fn ($_, DeviceLongUrl $d) => $d->deviceType() === $deviceLongUrlPair->deviceType,
);
if ($deviceLongUrl !== null) {
@ -322,7 +322,7 @@ class ShortUrl extends AbstractEntity
{
$data = [];
foreach ($this->deviceLongUrls as $deviceUrl) {
$data[$deviceUrl->deviceType->value] = $deviceUrl->longUrl();
$data[$deviceUrl->deviceType()->value] = $deviceUrl->longUrl();
}
return $data;