Skip to content

Commit

Permalink
Fix PR
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlagler committed Jan 27, 2025
1 parent 7390f88 commit aae511f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ private function setAuthorData(AuthorInterface $dimensionContent, array $data):
if (\array_key_exists('lastModified', $data)) {
$dimensionContent->setLastModified(
$data['lastModified'] && (\array_key_exists('lastModifiedEnabled', $data) && $data['lastModifiedEnabled'])
? new \DateTime($data['lastModified'])
? new \DateTimeImmutable($data['lastModified'])
: null
);
}

if (\array_key_exists('authored', $data)) {
$dimensionContent->setAuthored(
$data['authored']
? new \DateTime($data['authored'])
? new \DateTimeImmutable($data['authored'])
: null
);
}
Expand Down
8 changes: 4 additions & 4 deletions Content/Domain/Model/AuthorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ interface AuthorInterface
{
public function getLastModifiedEnabled(): ?bool;

public function getLastModified(): ?\DateTime;
public function getLastModified(): ?\DateTimeImmutable;

public function setLastModified(?\DateTime $lastModified): void;
public function setLastModified(?\DateTimeImmutable $lastModified): void;

public function getAuthor(): ?ContactInterface;

public function setAuthor(?ContactInterface $author): void;

public function getAuthored(): ?\DateTime;
public function getAuthored(): ?\DateTimeImmutable;

public function setAuthored(?\DateTime $authored): void;
public function setAuthored(?\DateTimeImmutable $authored): void;
}
12 changes: 6 additions & 6 deletions Content/Domain/Model/AuthorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ trait AuthorTrait
private $author;

/**
* @var \DateTime|null
* @var \DateTimeImmutable|null
*/
private $authored;

/**
* @var \DateTime|null
* @var \DateTimeImmutable|null
*/
private $lastModified;

Expand All @@ -40,12 +40,12 @@ public function getLastModifiedEnabled(): ?bool
return null !== $this->lastModified;
}

public function getLastModified(): ?\DateTime
public function getLastModified(): ?\DateTimeImmutable
{
return $this->lastModified;
}

public function setLastModified(?\DateTime $lastModified): void
public function setLastModified(?\DateTimeImmutable $lastModified): void
{
$this->lastModified = $lastModified;
}
Expand All @@ -60,12 +60,12 @@ public function setAuthor(?ContactInterface $author): void
$this->author = $author;
}

public function getAuthored(): ?\DateTime
public function getAuthored(): ?\DateTimeImmutable
{
return $this->authored;
}

public function setAuthored(?\DateTime $authored): void
public function setAuthored(?\DateTimeImmutable $authored): void
{
$this->authored = $authored;
}
Expand Down
4 changes: 2 additions & 2 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
}

if ($reflection->implementsInterface(AuthorInterface::class)) {
$this->addField($metadata, 'authored', 'datetime', ['nullable' => true]);
$this->addField($metadata, 'lastModified', 'datetime', ['nullable' => true]);
$this->addField($metadata, 'authored', 'datetime_immutable', ['nullable' => true]);
$this->addField($metadata, 'lastModified', 'datetime_immutable', ['nullable' => true]);
$this->addManyToOne($event, $metadata, 'author', ContactInterface::class, true);
}

Expand Down
6 changes: 3 additions & 3 deletions Content/Infrastructure/Sulu/Structure/ContentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getLastModifiedEnabled(): ?bool
return null;
}

public function getLastModified(): ?\DateTime
public function getLastModified(): ?\DateTimeImmutable
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getLastModified();
Expand All @@ -176,14 +176,14 @@ public function getLastModified(): ?\DateTime
}

/**
* @param \DateTime|null $lastModified
* @param \DateTimeImmutable|null $lastModified
*/
public function setLastModified($lastModified): void
{
throw $this->createReadOnlyException(__METHOD__);
}

public function getAuthored(): ?\DateTime
public function getAuthored(): ?\DateTimeImmutable

Check failure on line 186 in Content/Infrastructure/Sulu/Structure/ContentDocument.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Return type (DateTimeImmutable|null) of method Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentDocument::getAuthored() should be compatible with return type (DateTime) of method Sulu\Component\Content\Document\Behavior\LocalizedAuthorBehavior::getAuthored()
{
if ($this->content instanceof AuthorInterface) {
return $this->content->getAuthored();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testMapDataNull(): void
$unlocalizedDimensionContent = new ExampleDimensionContent($example);
$localizedDimensionContent = new ExampleDimensionContent($example);
$localizedDimensionContent->setAuthor(new Contact());
$localizedDimensionContent->setAuthored(new \DateTime());
$localizedDimensionContent->setAuthored(new \DateTimeImmutable());

$this->contactFactory->create(Argument::cetera())
->shouldNotBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function testMergeSet(): void
$merger = $this->getAuthorMergerInstance();

$contact = $this->prophesize(ContactInterface::class);
$authoredDate = new \DateTime('2020-05-08T00:00:00+00:00');
$lastModifiedDate = new \DateTime('2020-05-08T00:00:00+00:00');
$authoredDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');
$lastModifiedDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');

$source = $this->prophesize(DimensionContentInterface::class);
$source->willImplement(AuthorInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testEnhanceNotImplementAuthorInterface(): void

$data = [
'author' => 1,
'authored' => new \DateTime('2020-05-08T00:00:00+00:00'),
'authored' => new \DateTimeImmutable('2020-05-08T00:00:00+00:00'),
];

$this->assertSame(
Expand All @@ -76,8 +76,8 @@ public function testEnhance(): void
$contact = $this->prophesize(ContactInterface::class);
$contact->getId()->shouldBeCalled()->willReturn(1);
$object->getAuthor()->willReturn($contact->reveal());
$authored = new \DateTime('2020-05-08T00:00:00+00:00');
$lastModified = new \DateTime('2022-05-08T00:00:00+00:00');
$authored = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');
$lastModified = new \DateTimeImmutable('2022-05-08T00:00:00+00:00');

$data = [
'author' => $contact->reveal(),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Content/Domain/Model/AuthorTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testGetSetAuthor(): void
public function testGetSetAuthored(): void
{
$model = $this->getAuthorInstance();
$authored = new \DateTime('2020-05-08T00:00:00+00:00');
$authored = new \DateTimeImmutable('2020-05-08T00:00:00+00:00');
$this->assertNull($model->getAuthored());
$model->setAuthored($authored);
$this->assertSame($authored, $model->getAuthored());
Expand All @@ -51,7 +51,7 @@ public function testGetSetAuthored(): void
public function testGetSetLastModified(): void
{
$model = $this->getAuthorInstance();
$lastModified = new \DateTime('2024-05-08T00:00:00+00:00');
$lastModified = new \DateTimeImmutable('2024-05-08T00:00:00+00:00');
$model->setLastModified($lastModified);
$this->assertTrue($model->getLastModifiedEnabled());
$this->assertSame($lastModified, $model->getLastModified());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public function testGetLastModified(): void
$content = $this->prophesize(TemplateInterface::class);
$content->willImplement(AuthorInterface::class);
$content->getLastModifiedEnabled()->willReturn(true);
$authored = new \DateTime('2020-01-01');
$lastModified = new \DateTime('2022-01-01');
$authored = new \DateTimeImmutable('2020-01-01');
$lastModified = new \DateTimeImmutable('2022-01-01');
$content->getLastModified()->willReturn($lastModified);
$content->getAuthored()->willReturn($authored);
$document = $this->createContentDocument($content->reveal());
Expand All @@ -194,7 +194,7 @@ public function testGetLastModified(): void
public function testSetLastModified(): void
{
$this->expectException(\BadMethodCallException::class);
$lastModified = new \DateTime('2020-01-01');
$lastModified = new \DateTimeImmutable('2020-01-01');
$document = $this->createContentDocument();

$document->setLastModified($lastModified);
Expand All @@ -203,7 +203,7 @@ public function testSetLastModified(): void
public function testSetAuthored(): void
{
$this->expectException(\BadMethodCallException::class);
$authored = new \DateTime('2020-01-01');
$authored = new \DateTimeImmutable('2020-01-01');
$document = $this->createContentDocument();

$document->setAuthored($authored);

Check failure on line 209 in Tests/Unit/Content/Infrastructure/Sulu/Structure/ContentDocumentTest.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #1 $authored of method Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Structure\ContentDocument::setAuthored() expects DateTime, DateTimeImmutable given.
Expand Down

0 comments on commit aae511f

Please sign in to comment.