mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-03 15:04:32 +02:00
Fixed some more phpstan issues
This commit is contained in:
parent
2f46fbfc7a
commit
e8771ea118
77 changed files with 192 additions and 109 deletions
|
@ -242,7 +242,8 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
/**
|
||||
* Get the element, associated with this Attachment (for example a "Part" object).
|
||||
*
|
||||
* @return AttachmentContainingDBElement the associated Element
|
||||
* @return AttachmentContainingDBElement|null the associated Element
|
||||
* @phpstan-return T|null
|
||||
*/
|
||||
public function getElement(): ?AttachmentContainingDBElement
|
||||
{
|
||||
|
@ -360,7 +361,6 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
|
||||
/**
|
||||
* Sets the element that is associated with this attachment.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setElement(AttachmentContainingDBElement $element): self
|
||||
|
@ -437,7 +437,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
$tmp = explode('/', $path);
|
||||
//Builtins must have a %PLACEHOLDER% construction
|
||||
|
||||
return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
|
||||
return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,12 +28,14 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a currency element.
|
||||
* @extends Attachment<Currency>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
class CurrencyAttachment extends Attachment
|
||||
{
|
||||
final public const ALLOWED_ELEMENT_CLASS = Currency::class;
|
||||
|
||||
/**
|
||||
* @var Currency|null the element this attachment is associated with
|
||||
*/
|
||||
|
|
|
@ -28,12 +28,14 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a footprint element.
|
||||
* @extends Attachment<Footprint>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
class FootprintAttachment extends Attachment
|
||||
{
|
||||
final public const ALLOWED_ELEMENT_CLASS = Footprint::class;
|
||||
|
||||
/**
|
||||
* @var Footprint|null the element this attachment is associated with
|
||||
*/
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a Group element.
|
||||
* @extends Attachment<Group>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -47,6 +47,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* A attachment attached to a user element.
|
||||
* @extends Attachment<LabelProfile>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a manufacturer element.
|
||||
* @extends Attachment<Manufacturer>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -29,6 +29,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a measurement unit element.
|
||||
* @extends Attachment<MeasurementUnit>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* A attachment attached to a part element.
|
||||
* @extends Attachment<Part>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* A attachment attached to a device element.
|
||||
* @extends Attachment<Project>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a measurement unit element.
|
||||
* @extends Attachment<Storelocation>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* A attachment attached to a supplier element.
|
||||
* @extends Attachment<Supplier>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|||
|
||||
/**
|
||||
* An attachment attached to a user element.
|
||||
* @extends Attachment<User>
|
||||
*/
|
||||
#[UniqueEntity(['name', 'attachment_type', 'element'])]
|
||||
#[ORM\Entity]
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Entity\Attachments\AttachmentContainingDBElement;
|
|||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parameters\ParametersTrait;
|
||||
use App\Repository\AbstractPartsContainingRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
@ -41,4 +42,10 @@ abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElem
|
|||
{
|
||||
#[Groups(['full'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->parameters = new ArrayCollection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
|||
*/
|
||||
public function isRoot(): bool
|
||||
{
|
||||
return !$this->parent instanceof \App\Entity\Base\AbstractStructuralDBElement;
|
||||
return $this->parent === null;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -207,7 +207,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
|||
/**
|
||||
* Get the parent of this element.
|
||||
*
|
||||
* @return AbstractStructuralDBElement|null The parent element. Null if this element, does not have a parent.
|
||||
* @return static|null The parent element. Null if this element, does not have a parent.
|
||||
*/
|
||||
public function getParent(): ?self
|
||||
{
|
||||
|
|
|
@ -50,6 +50,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
* The class properties are split over various traits in directory PartTraits.
|
||||
* Otherwise, this class would be too big, to be maintained.
|
||||
* @see \App\Tests\Entity\Parts\PartTest
|
||||
* @extends AttachmentContainingDBElement<PartAttachment>
|
||||
* @template-use ParametersTrait<PartParameter>
|
||||
*/
|
||||
#[UniqueEntity(fields: ['ipn'], message: 'part.ipn.must_be_unique')]
|
||||
#[ORM\Entity(repositoryClass: PartRepository::class)]
|
||||
|
|
|
@ -107,12 +107,12 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
protected bool $needs_refill = false;
|
||||
|
||||
/**
|
||||
* @var Part The part that is stored in this lot
|
||||
* @var Part|null The part that is stored in this lot
|
||||
*/
|
||||
#[Assert\NotNull]
|
||||
#[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'partLots')]
|
||||
#[ORM\JoinColumn(name: 'id_part', nullable: false, onDelete: 'CASCADE')]
|
||||
protected Part $part;
|
||||
protected ?Part $part = null;
|
||||
|
||||
/**
|
||||
* @var User|null The owner of this part lot
|
||||
|
@ -226,7 +226,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
/**
|
||||
* Return the part that is stored in this part lot.
|
||||
*/
|
||||
public function getPart(): Part
|
||||
public function getPart(): ?Part
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ trait InstockTrait
|
|||
$sum = 0;
|
||||
foreach ($this->getPartLots() as $lot) {
|
||||
//Don't use the in stock value, if it is unknown
|
||||
if ($lot->isInstockUnknown() || $lot->isExpired() ?? false) {
|
||||
if ($lot->isInstockUnknown() || ($lot->isExpired() ?? false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,12 +47,9 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
{
|
||||
use TimestampTrait;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
#[Assert\Positive]
|
||||
#[ORM\Column(type: Types::FLOAT, name: 'quantity')]
|
||||
protected float $quantity;
|
||||
protected float $quantity = 1.0;
|
||||
|
||||
/**
|
||||
* @var string A comma separated list of the names, where this parts should be placed
|
||||
|
@ -71,7 +68,7 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
* @var string An optional comment for this BOM entry
|
||||
*/
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
protected string $comment;
|
||||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var Project|null
|
||||
|
|
|
@ -43,25 +43,25 @@ class U2FKey implements LegacyU2FKeyInterface
|
|||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::STRING, length: 128)]
|
||||
public string $keyHandle;
|
||||
public string $keyHandle = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
public string $publicKey;
|
||||
public string $publicKey = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
public string $certificate;
|
||||
public string $certificate = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
public int $counter;
|
||||
public string $counter = '0';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(type: Types::INTEGER)]
|
||||
|
@ -72,7 +72,7 @@ class U2FKey implements LegacyU2FKeyInterface
|
|||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
protected string $name;
|
||||
protected string $name = '';
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'u2fKeys')]
|
||||
protected ?User $user = null;
|
||||
|
@ -114,7 +114,7 @@ class U2FKey implements LegacyU2FKeyInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getCounter(): int
|
||||
public function getCounter(): string
|
||||
{
|
||||
return $this->counter;
|
||||
}
|
||||
|
|
|
@ -900,7 +900,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
{
|
||||
return new PublicKeyCredentialUserEntity(
|
||||
$this->getUsername(),
|
||||
(string) $this->getId(),
|
||||
(string) $this->getID(),
|
||||
$this->getFullName(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Entity\UserSystem;
|
|||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Webauthn\PublicKeyCredentialSource as BasePublicKeyCredentialSource;
|
||||
|
||||
#[ORM\Entity]
|
||||
|
@ -40,7 +41,8 @@ class WebauthnKey extends BasePublicKeyCredentialSource
|
|||
protected int $id;
|
||||
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
protected string $name;
|
||||
#[NotBlank]
|
||||
protected string $name = '';
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'webauthn_keys')]
|
||||
protected ?User $user = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue