Skip to content

Commit

Permalink
fix: Fixed Collection<int, classname> type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed May 19, 2023
1 parent d88a179 commit 3a670bb
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 97 deletions.
2 changes: 1 addition & 1 deletion lib/Documents/src/Models/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setRaw(bool $raw): static;
public function getDownscaledDocument(): ?DocumentInterface;

/**
* @return Collection<FolderInterface>
* @return Collection<int, FolderInterface>
*/
public function getFolders(): Collection;

Expand Down
6 changes: 2 additions & 4 deletions lib/Documents/src/Models/FolderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
interface FolderInterface
{
/**
* @return Collection<DocumentInterface>
* @return Collection<int, DocumentInterface>
*/
public function getDocuments(): Collection;

Expand All @@ -25,10 +25,8 @@ public function addDocument(DocumentInterface $document): static;
*/
public function removeDocument(DocumentInterface $document): static;

/**
* @return bool
*/
public function getVisible(): bool;
public function isVisible(): bool;

/**
* @param bool $visible
Expand Down
4 changes: 2 additions & 2 deletions lib/Documents/src/Models/HasThumbnailInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function getOriginal(): ?HasThumbnailInterface;
public function setOriginal(?HasThumbnailInterface $original): static;

/**
* @return Collection<static>
* @return Collection<int, static>
*/
public function getThumbnails(): Collection;

/**
* @param Collection<static> $thumbnails
* @param Collection<int, static> $thumbnails
* @return $this
*/
public function setThumbnails(Collection $thumbnails): static;
Expand Down
6 changes: 3 additions & 3 deletions lib/EntityGenerator/src/Field/ManyToManyFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getFieldAnnotation(): string
return '
/**
*' . implode(PHP_EOL . static::ANNOTATION_PREFIX, $this->getFieldAutodoc()) . '
* @var Collection<' . $this->getFullyQualifiedClassName() . '>
* @var Collection<int, ' . $this->getFullyQualifiedClassName() . '>
*/' . PHP_EOL;
}

Expand All @@ -99,7 +99,7 @@ public function getFieldGetter(): string
{
return '
/**
* @return Collection<' . $this->getFullyQualifiedClassName() . '>
* @return Collection<int, ' . $this->getFullyQualifiedClassName() . '>
*/
public function ' . $this->field->getGetterName() . '(): Collection
{
Expand All @@ -114,7 +114,7 @@ public function getFieldSetter(): string
{
return '
/**
* @param Collection<' . $this->getFullyQualifiedClassName() . '>|' . $this->getFullyQualifiedClassName() . '[] $' . $this->field->getVarName() . '
* @param Collection<int, ' . $this->getFullyQualifiedClassName() . '>|' . $this->getFullyQualifiedClassName() . '[] $' . $this->field->getVarName() . '
* @return $this
*/
public function ' . $this->field->getSetterName() . '(Collection|array $' . $this->field->getVarName() . '): static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getFieldAnnotation(): string
/**
* ' . $this->field->getLabel() . '
*
* @var Collection<' . $this->getProxyClassname() . '>
* @var Collection<int, ' . $this->getProxyClassname() . '>
*/' . PHP_EOL;
}

Expand All @@ -104,7 +104,7 @@ public function getFieldGetter(): string
{
return '
/**
* @return Collection<' . $this->getProxyClassname() . '>
* @return Collection<int, ' . $this->getProxyClassname() . '>
*/
public function ' . $this->getProxiedGetterName() . '(): Collection
{
Expand Down
26 changes: 13 additions & 13 deletions lib/EntityGenerator/tests/mocks/GeneratedNodesSources/NSMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe
* orderBy:
* - field: sortingLastDateTime
* direction: DESC
* @var Collection<\App\Entity\Base\Event>
* @var Collection<int, \App\Entity\Base\Event>
*/
#[
SymfonySerializer\SerializedName(serializedName: "eventReferences"),
Expand All @@ -449,15 +449,15 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe
private Collection $eventReferences;

/**
* @return Collection<\App\Entity\Base\Event>
* @return Collection<int, \App\Entity\Base\Event>
*/
public function getEventReferences(): Collection
{
return $this->eventReferences;
}

/**
* @param Collection<\App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferences
* @param Collection<int, \App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferences
* @return $this
*/
public function setEventReferences(Collection|array $eventReferences): static
Expand All @@ -475,7 +475,7 @@ public function setEventReferences(Collection|array $eventReferences): static
/**
* Remontée d'événements manuelle
*
* @var Collection<\App\Entity\PositionedCity>
* @var Collection<int, \App\Entity\PositionedCity>
*/
#[
Serializer\Exclude,
Expand All @@ -491,7 +491,7 @@ public function setEventReferences(Collection|array $eventReferences): static
private Collection $eventReferencesProxiedProxy;

/**
* @return Collection<\App\Entity\PositionedCity>
* @return Collection<int, \App\Entity\PositionedCity>
*/
public function getEventReferencesProxiedProxy(): Collection
{
Expand Down Expand Up @@ -575,7 +575,7 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences
* orderBy:
* - field: sortingLastDateTime
* direction: DESC
* @var Collection<\App\Entity\Base\Event>
* @var Collection<int, \App\Entity\Base\Event>
*/
#[
ORM\ManyToMany(targetEntity: \App\Entity\Base\Event::class),
Expand All @@ -590,15 +590,15 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences
private Collection $eventReferencesExcluded;

/**
* @return Collection<\App\Entity\Base\Event>
* @return Collection<int, \App\Entity\Base\Event>
*/
public function getEventReferencesExcluded(): Collection
{
return $this->eventReferencesExcluded;
}

/**
* @param Collection<\App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferencesExcluded
* @param Collection<int, \App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferencesExcluded
* @return $this
*/
public function setEventReferencesExcluded(Collection|array $eventReferencesExcluded): static
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne = null): static
* orderBy:
* - field: name
* direction: asc
* @var Collection<\MyCustomEntity>
* @var Collection<int, \MyCustomEntity>
*/
#[
SymfonySerializer\SerializedName(serializedName: "fooManyToMany"),
Expand All @@ -1043,15 +1043,15 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne = null): static
private Collection $fooManyToMany;

/**
* @return Collection<\MyCustomEntity>
* @return Collection<int, \MyCustomEntity>
*/
public function getFooManyToMany(): Collection
{
return $this->fooManyToMany;
}

/**
* @param Collection<\MyCustomEntity>|\MyCustomEntity[] $fooManyToMany
* @param Collection<int, \MyCustomEntity>|\MyCustomEntity[] $fooManyToMany
* @return $this
*/
public function setFooManyToMany(Collection|array $fooManyToMany): static
Expand All @@ -1069,7 +1069,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static
/**
* For many_to_many proxied field
*
* @var Collection<\Themes\MyTheme\Entities\PositionedCity>
* @var Collection<int, \Themes\MyTheme\Entities\PositionedCity>
*/
#[
Serializer\Exclude,
Expand All @@ -1085,7 +1085,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static
private Collection $fooManyToManyProxiedProxy;

/**
* @return Collection<\Themes\MyTheme\Entities\PositionedCity>
* @return Collection<int, \Themes\MyTheme\Entities\PositionedCity>
*/
public function getFooManyToManyProxiedProxy(): Collection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe
* orderBy:
* - field: sortingLastDateTime
* direction: DESC
* @var Collection<\App\Entity\Base\Event>
* @var Collection<int, \App\Entity\Base\Event>
*/
#[
SymfonySerializer\SerializedName(serializedName: "eventReferences"),
Expand All @@ -449,15 +449,15 @@ public function setSingleEventReference(?\App\Entity\Base\Event $singleEventRefe
private Collection $eventReferences;

/**
* @return Collection<\App\Entity\Base\Event>
* @return Collection<int, \App\Entity\Base\Event>
*/
public function getEventReferences(): Collection
{
return $this->eventReferences;
}

/**
* @param Collection<\App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferences
* @param Collection<int, \App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferences
* @return $this
*/
public function setEventReferences(Collection|array $eventReferences): static
Expand All @@ -475,7 +475,7 @@ public function setEventReferences(Collection|array $eventReferences): static
/**
* Remontée d'événements manuelle
*
* @var Collection<\App\Entity\PositionedCity>
* @var Collection<int, \App\Entity\PositionedCity>
*/
#[
Serializer\Exclude,
Expand All @@ -491,7 +491,7 @@ public function setEventReferences(Collection|array $eventReferences): static
private Collection $eventReferencesProxiedProxy;

/**
* @return Collection<\App\Entity\PositionedCity>
* @return Collection<int, \App\Entity\PositionedCity>
*/
public function getEventReferencesProxiedProxy(): Collection
{
Expand Down Expand Up @@ -575,7 +575,7 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences
* orderBy:
* - field: sortingLastDateTime
* direction: DESC
* @var Collection<\App\Entity\Base\Event>
* @var Collection<int, \App\Entity\Base\Event>
*/
#[
ORM\ManyToMany(targetEntity: \App\Entity\Base\Event::class),
Expand All @@ -590,15 +590,15 @@ public function setEventReferencesProxied(Collection|array|null $eventReferences
private Collection $eventReferencesExcluded;

/**
* @return Collection<\App\Entity\Base\Event>
* @return Collection<int, \App\Entity\Base\Event>
*/
public function getEventReferencesExcluded(): Collection
{
return $this->eventReferencesExcluded;
}

/**
* @param Collection<\App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferencesExcluded
* @param Collection<int, \App\Entity\Base\Event>|\App\Entity\Base\Event[] $eventReferencesExcluded
* @return $this
*/
public function setEventReferencesExcluded(Collection|array $eventReferencesExcluded): static
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne = null): static
* orderBy:
* - field: name
* direction: asc
* @var Collection<\MyCustomEntity>
* @var Collection<int, \MyCustomEntity>
*/
#[
SymfonySerializer\SerializedName(serializedName: "fooManyToMany"),
Expand All @@ -1043,15 +1043,15 @@ public function setFooManyToOne(?\MyCustomEntity $fooManyToOne = null): static
private Collection $fooManyToMany;

/**
* @return Collection<\MyCustomEntity>
* @return Collection<int, \MyCustomEntity>
*/
public function getFooManyToMany(): Collection
{
return $this->fooManyToMany;
}

/**
* @param Collection<\MyCustomEntity>|\MyCustomEntity[] $fooManyToMany
* @param Collection<int, \MyCustomEntity>|\MyCustomEntity[] $fooManyToMany
* @return $this
*/
public function setFooManyToMany(Collection|array $fooManyToMany): static
Expand All @@ -1069,7 +1069,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static
/**
* For many_to_many proxied field
*
* @var Collection<\Themes\MyTheme\Entities\PositionedCity>
* @var Collection<int, \Themes\MyTheme\Entities\PositionedCity>
*/
#[
Serializer\Exclude,
Expand All @@ -1085,7 +1085,7 @@ public function setFooManyToMany(Collection|array $fooManyToMany): static
private Collection $fooManyToManyProxiedProxy;

/**
* @return Collection<\Themes\MyTheme\Entities\PositionedCity>
* @return Collection<int, \Themes\MyTheme\Entities\PositionedCity>
*/
public function getFooManyToManyProxiedProxy(): Collection
{
Expand Down
3 changes: 0 additions & 3 deletions lib/Models/src/Roadiz/Core/AbstractEntities/LeafInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

interface LeafInterface extends PositionedInterface, Comparable
{
/**
* @return Collection<int, static>
*/
public function getChildren(): Collection;

/**
Expand Down
9 changes: 4 additions & 5 deletions lib/Models/src/Roadiz/Core/AbstractEntities/LeafTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public function getChildren(): Collection
return $this->children;
}

/**
* @param Collection<int, static> $children
* @return $this
*/
public function setChildren(Collection $children): static
{
$this->children = $children;
Expand All @@ -30,7 +26,7 @@ public function setChildren(Collection $children): static
}

/**
* @param static $child
* @param LeafInterface $child
* @return $this
*/
public function addChild(LeafInterface $child): static
Expand Down Expand Up @@ -77,6 +73,9 @@ public function setParent(?LeafInterface $parent = null): static
if ($parent === $this) {
throw new \InvalidArgumentException('An entity cannot have itself as a parent.');
}
if (get_class($parent) !== get_class($this)) {
throw new \InvalidArgumentException('Parent must be the same class as the current entity.');
}

$this->parent = $parent;
$this->parent?->addChild($this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
interface BlocksAwareWebResponseInterface extends WebResponseInterface
{
/**
* @return Collection<WalkerInterface>|null
* @return Collection<int, WalkerInterface>|null
*/
public function getBlocks(): ?Collection;

/**
* @param Collection<WalkerInterface>|null $blocks
* @param Collection<int, WalkerInterface>|null $blocks
* @return BlocksAwareWebResponseInterface
*/
public function setBlocks(?Collection $blocks): BlocksAwareWebResponseInterface;
Expand Down
Loading

0 comments on commit 3a670bb

Please sign in to comment.