mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -37,7 +37,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
/**
|
||||
* Class AttachmentType.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: 'App\Repository\Parts\DeviceRepository')]
|
||||
#[ORM\Entity(repositoryClass: \App\Repository\Parts\DeviceRepository::class)]
|
||||
#[ORM\Table(name: 'projects')]
|
||||
class Project extends AbstractStructuralDBElement
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ class Project extends AbstractStructuralDBElement
|
|||
|
||||
#[ORM\ManyToOne(targetEntity: 'Project', inversedBy: 'children')]
|
||||
#[ORM\JoinColumn(name: 'parent_id')]
|
||||
protected ?AbstractStructuralDBElement $parent;
|
||||
protected ?AbstractStructuralDBElement $parent = null;
|
||||
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full'])]
|
||||
|
@ -72,7 +72,7 @@ class Project extends AbstractStructuralDBElement
|
|||
/**
|
||||
* @var Part|null The (optional) part that represents the builds of this project in the stock
|
||||
*/
|
||||
#[ORM\OneToOne(targetEntity: 'App\Entity\Parts\Part', mappedBy: 'built_project', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OneToOne(targetEntity: \App\Entity\Parts\Part::class, mappedBy: 'built_project', cascade: ['persist'], orphanRemoval: true)]
|
||||
protected ?Part $build_part = null;
|
||||
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)]
|
||||
|
@ -85,13 +85,13 @@ class Project extends AbstractStructuralDBElement
|
|||
/**
|
||||
* @var Collection<int, ProjectAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Attachments\ProjectAttachment', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\Attachments\ProjectAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
/** @var Collection<int, ProjectParameter>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Parameters\ProjectParameter', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\Parameters\ProjectParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
@ -174,8 +174,6 @@ class Project extends AbstractStructuralDBElement
|
|||
* Set the "order_only_missing_parts" attribute.
|
||||
*
|
||||
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute
|
||||
*
|
||||
* @return Project
|
||||
*/
|
||||
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self
|
||||
{
|
||||
|
@ -193,7 +191,6 @@ class Project extends AbstractStructuralDBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ProjectBOMEntry $entry
|
||||
* @return $this
|
||||
*/
|
||||
public function addBomEntry(ProjectBOMEntry $entry): self
|
||||
|
@ -204,7 +201,6 @@ class Project extends AbstractStructuralDBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ProjectBOMEntry $entry
|
||||
* @return $this
|
||||
*/
|
||||
public function removeBomEntry(ProjectBOMEntry $entry): self
|
||||
|
@ -213,18 +209,11 @@ class Project extends AbstractStructuralDBElement
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @return Project
|
||||
*/
|
||||
public function setDescription(string $description): Project
|
||||
{
|
||||
$this->description = $description;
|
||||
|
@ -249,16 +238,14 @@ class Project extends AbstractStructuralDBElement
|
|||
|
||||
/**
|
||||
* Checks if this project has an associated part representing the builds of this project in the stock.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBuildPart(): bool
|
||||
{
|
||||
return $this->build_part !== null;
|
||||
return $this->build_part instanceof \App\Entity\Parts\Part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the part representing the builds of this project in the stock, if it is existing
|
||||
* @return Part|null
|
||||
*/
|
||||
public function getBuildPart(): ?Part
|
||||
{
|
||||
|
@ -267,12 +254,11 @@ class Project extends AbstractStructuralDBElement
|
|||
|
||||
/**
|
||||
* Sets the part representing the builds of this project in the stock.
|
||||
* @param Part|null $build_part
|
||||
*/
|
||||
public function setBuildPart(?Part $build_part): void
|
||||
{
|
||||
$this->build_part = $build_part;
|
||||
if ($build_part) {
|
||||
if ($build_part instanceof \App\Entity\Parts\Part) {
|
||||
$build_part->setBuiltProject($this);
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +269,7 @@ class Project extends AbstractStructuralDBElement
|
|||
//If this project has subprojects, and these have builds part, they must be included in the BOM
|
||||
foreach ($this->getChildren() as $child) {
|
||||
/** @var $child Project */
|
||||
if ($child->getBuildPart() === null) {
|
||||
if (!$child->getBuildPart() instanceof \App\Entity\Parts\Part) {
|
||||
continue;
|
||||
}
|
||||
//We have to search all bom entries for the build part
|
||||
|
|
|
@ -82,7 +82,7 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
/**
|
||||
* @var Part|null The part associated with this
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\Parts\Part', inversedBy: 'project_bom_entries')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\Parts\Part::class, inversedBy: 'project_bom_entries')]
|
||||
#[ORM\JoinColumn(name: 'id_part')]
|
||||
protected ?Part $part = null;
|
||||
|
||||
|
@ -91,52 +91,36 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
*/
|
||||
#[Assert\AtLeastOneOf([new BigDecimalPositive(), new Assert\IsNull()])]
|
||||
#[ORM\Column(type: 'big_decimal', precision: 11, scale: 5, nullable: true)]
|
||||
protected ?BigDecimal $price;
|
||||
protected ?BigDecimal $price = null;
|
||||
|
||||
/**
|
||||
* @var ?Currency The currency for the price of this non-part BOM entry
|
||||
* @Selectable()
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\PriceInformations\Currency')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\PriceInformations\Currency::class)]
|
||||
#[ORM\JoinColumn]
|
||||
protected ?Currency $price_currency = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//$this->price = BigDecimal::zero()->toScale(5);
|
||||
$this->price = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getQuantity(): float
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $quantity
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setQuantity(float $quantity): ProjectBOMEntry
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMountnames(): string
|
||||
{
|
||||
return $this->mountnames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mountnames
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setMountnames(string $mountnames): ProjectBOMEntry
|
||||
{
|
||||
$this->mountnames = $mountnames;
|
||||
|
@ -153,7 +137,6 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setName(?string $name): ProjectBOMEntry
|
||||
{
|
||||
|
@ -161,36 +144,22 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getComment(): string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setComment(string $comment): ProjectBOMEntry
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project|null
|
||||
*/
|
||||
public function getProject(): ?Project
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project|null $project
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setProject(?Project $project): ProjectBOMEntry
|
||||
{
|
||||
$this->project = $project;
|
||||
|
@ -199,18 +168,11 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* @return Part|null
|
||||
*/
|
||||
public function getPart(): ?Part
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Part|null $part
|
||||
* @return ProjectBOMEntry
|
||||
*/
|
||||
public function setPart(?Part $part): ProjectBOMEntry
|
||||
{
|
||||
$this->part = $part;
|
||||
|
@ -220,7 +182,6 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
/**
|
||||
* Returns the price of this BOM entry, if existing.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @return BigDecimal|null
|
||||
*/
|
||||
public function getPrice(): ?BigDecimal
|
||||
{
|
||||
|
@ -230,24 +191,17 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
/**
|
||||
* Sets the price of this BOM entry.
|
||||
* Prices are only valid on non-Part BOM entries.
|
||||
* @param BigDecimal|null $price
|
||||
*/
|
||||
public function setPrice(?BigDecimal $price): void
|
||||
{
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Currency|null
|
||||
*/
|
||||
public function getPriceCurrency(): ?Currency
|
||||
{
|
||||
return $this->price_currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Currency|null $price_currency
|
||||
*/
|
||||
public function setPriceCurrency(?Currency $price_currency): void
|
||||
{
|
||||
$this->price_currency = $price_currency;
|
||||
|
@ -259,20 +213,18 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
*/
|
||||
public function isPartBomEntry(): bool
|
||||
{
|
||||
return $this->part !== null;
|
||||
return $this->part instanceof \App\Entity\Parts\Part;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function validate(ExecutionContextInterface $context, $payload): void
|
||||
{
|
||||
//Round quantity to whole numbers, if the part is not a decimal part
|
||||
if ($this->part) {
|
||||
if (!$this->part->getPartUnit() || $this->part->getPartUnit()->isInteger()) {
|
||||
$this->quantity = round($this->quantity);
|
||||
}
|
||||
if ($this->part instanceof \App\Entity\Parts\Part && (!$this->part->getPartUnit() || $this->part->getPartUnit()->isInteger())) {
|
||||
$this->quantity = round($this->quantity);
|
||||
}
|
||||
//Non-Part BOM entries are rounded
|
||||
if ($this->part === null) {
|
||||
if (!$this->part instanceof \App\Entity\Parts\Part) {
|
||||
$this->quantity = round($this->quantity);
|
||||
}
|
||||
|
||||
|
@ -296,14 +248,14 @@ class ProjectBOMEntry extends AbstractDBElement
|
|||
}
|
||||
|
||||
//Prices are only allowed on non-part BOM entries
|
||||
if ($this->part !== null && $this->price !== null) {
|
||||
if ($this->part instanceof \App\Entity\Parts\Part && $this->price instanceof \Brick\Math\BigDecimal) {
|
||||
$context->buildViolation('project.bom_entry.price_not_allowed_on_parts')
|
||||
->atPath('price')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
//Check that the part is not the build representation part of this device or one of its parents
|
||||
if ($this->part && $this->part->getBuiltProject() !== null) {
|
||||
if ($this->part && $this->part->getBuiltProject() instanceof \App\Entity\ProjectSystem\Project) {
|
||||
//Get the associated project
|
||||
$associated_project = $this->part->getBuiltProject();
|
||||
//Check that it is not the same as the current project neither one of its parents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue