Started to increase the phpstan level

This commit is contained in:
Jan Böhmer 2023-06-13 10:36:34 +02:00
parent 71cd4057a7
commit fc3290271c
29 changed files with 119 additions and 55 deletions

View file

@ -37,6 +37,7 @@ use LogicException;
/**
* Class Attachment.
* @see \App\Tests\Entity\Attachments\AttachmentTest
* @template-covariant T of AttachmentContainingDBElement
*/
#[ORM\Entity(repositoryClass: AttachmentRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
@ -75,9 +76,9 @@ abstract class Attachment extends AbstractNamedDBElement
/**
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
*
* @phpstan-var class-string<T>
*/
protected const ALLOWED_ELEMENT_CLASS = '';
protected const ALLOWED_ELEMENT_CLASS = AttachmentContainingDBElement::class;
/**
* @var string|null the original filename the file had, when the user uploaded it
@ -101,6 +102,7 @@ abstract class Attachment extends AbstractNamedDBElement
/**
* ORM mapping is done in subclasses (like PartAttachment).
* @phpstan-param T|null $element
*/
protected ?AttachmentContainingDBElement $element = null;
@ -116,7 +118,7 @@ abstract class Attachment extends AbstractNamedDBElement
public function __construct()
{
//parent::__construct();
if ('' === static::ALLOWED_ELEMENT_CLASS) {
if (AttachmentContainingDBElement::class === static::ALLOWED_ELEMENT_CLASS) {
throw new LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
}
}

View file

@ -31,13 +31,17 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @template-covariant AT of Attachment
*/
#[ORM\MappedSuperclass]
abstract class AttachmentContainingDBElement extends AbstractNamedDBElement implements HasMasterAttachmentInterface, HasAttachmentsInterface
{
use MasterAttachmentTrait;
/**
* @var Attachment[]|Collection
* @var Collection<int, Attachment>
* @phpstan-var Collection<int, AT>
* ORM Mapping is done in subclasses (e.g. Part)
*/
#[Groups(['full'])]
@ -76,7 +80,7 @@ abstract class AttachmentContainingDBElement extends AbstractNamedDBElement impl
/**
* Gets all attachments associated with this element.
*
* @return Attachment[]|Collection
* @return Collection<Attachment>
*/
public function getAttachments(): Collection
{

View file

@ -35,6 +35,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* Class AttachmentType.
* @see \App\Tests\Entity\Attachments\AttachmentTypeTest
* @extends AbstractStructuralDBElement<AttachmentTypeAttachment, AttachmentTypeParameter>
*/
#[ORM\Entity(repositoryClass: StructuralDBElementRepository::class)]
#[ORM\Table(name: '`attachment_types`')]

View file

@ -27,6 +27,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* A attachment attached to an attachmentType element.
* @extends Attachment<AttachmentType>
*/
#[UniqueEntity(['name', 'attachment_type', 'element'])]
#[ORM\Entity]

View file

@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* An attachment attached to a category element.
* @extends Attachment<Category>
*/
#[UniqueEntity(['name', 'attachment_type', 'element'])]
#[ORM\Entity]