Applied rector with PHP8.1 migration rules

This commit is contained in:
Jan Böhmer 2023-06-11 14:15:46 +02:00
parent dc6a67c2f0
commit 7ee01d9a05
303 changed files with 1228 additions and 3465 deletions

View file

@ -30,8 +30,7 @@ use App\Validator\Constraints\ProjectSystem\ValidProjectBuildRequest;
*/
final class ProjectBuildRequest
{
private Project $project;
private int $number_of_builds;
private readonly int $number_of_builds;
/**
* @var array<int, float>
@ -48,19 +47,17 @@ final class ProjectBuildRequest
* @param Project $project The project that should be build
* @param int $number_of_builds The number of builds that should be created
*/
public function __construct(Project $project, int $number_of_builds)
public function __construct(private readonly Project $project, int $number_of_builds)
{
if ($number_of_builds < 1) {
throw new \InvalidArgumentException('Number of builds must be at least 1!');
}
$this->project = $project;
$this->number_of_builds = $number_of_builds;
$this->initializeArray();
//By default, use the first available lot of builds part if there is one.
if($project->getBuildPart() !== null) {
if($project->getBuildPart() instanceof \App\Entity\Parts\Part) {
$this->add_build_to_builds_part = true;
foreach( $project->getBuildPart()->getPartLots() as $lot) {
if (!$lot->isInstockUnknown()) {
@ -89,8 +86,6 @@ final class ProjectBuildRequest
/**
* Ensure that the projectBOMEntry belongs to the project, otherwise throw an exception.
* @param ProjectBOMEntry $entry
* @return void
*/
private function ensureBOMEntryValid(ProjectBOMEntry $entry): void
{
@ -101,7 +96,6 @@ final class ProjectBuildRequest
/**
* Returns the partlot where the builds should be added to, or null if it should not be added to any lot.
* @return PartLot|null
*/
public function getBuildsPartLot(): ?PartLot
{
@ -110,7 +104,6 @@ final class ProjectBuildRequest
/**
* Return if the builds should be added to the builds part of this project as new stock
* @return bool
*/
public function getAddBuildsToBuildsPart(): bool
{
@ -119,7 +112,6 @@ final class ProjectBuildRequest
/**
* Set if the builds should be added to the builds part of this project as new stock
* @param bool $new_value
* @return $this
*/
public function setAddBuildsToBuildsPart(bool $new_value): self
@ -136,17 +128,16 @@ final class ProjectBuildRequest
/**
* Set the partlot where the builds should be added to, or null if it should not be added to any lot.
* The part lot must belong to the project build part, or an exception is thrown!
* @param PartLot|null $new_part_lot
* @return $this
*/
public function setBuildsPartLot(?PartLot $new_part_lot): self
{
//Ensure that this new_part_lot belongs to the project
if (($new_part_lot !== null && $new_part_lot->getPart() !== $this->project->getBuildPart()) || $this->project->getBuildPart() === null) {
if (($new_part_lot instanceof \App\Entity\Parts\PartLot && $new_part_lot->getPart() !== $this->project->getBuildPart()) || !$this->project->getBuildPart() instanceof \App\Entity\Parts\Part) {
throw new \InvalidArgumentException('The given part lot does not belong to the projects build part!');
}
if ($new_part_lot !== null) {
if ($new_part_lot instanceof \App\Entity\Parts\PartLot) {
$this->setAddBuildsToBuildsPart(true);
}
@ -157,7 +148,6 @@ final class ProjectBuildRequest
/**
* Returns the comment where the user can write additional information about the build.
* @return string
*/
public function getComment(): string
{
@ -166,7 +156,6 @@ final class ProjectBuildRequest
/**
* Sets the comment where the user can write additional information about the build.
* @param string $comment
*/
public function setComment(string $comment): void
{
@ -176,9 +165,8 @@ final class ProjectBuildRequest
/**
* Returns the amount of parts that should be withdrawn from the given lot for the corresponding BOM entry.
* @param PartLot|int $lot The part lot (or the ID of the part lot) for which the withdrawal amount should be got
* @return float
*/
public function getLotWithdrawAmount($lot): float
public function getLotWithdrawAmount(\App\Entity\Parts\PartLot|int $lot): float
{
if ($lot instanceof PartLot) {
$lot_id = $lot->getID();
@ -198,10 +186,9 @@ final class ProjectBuildRequest
/**
* Sets the amount of parts that should be withdrawn from the given lot for the corresponding BOM entry.
* @param PartLot|int $lot The part lot (or the ID of the part lot) for which the withdrawal amount should be got
* @param float $amount
* @return $this
*/
public function setLotWithdrawAmount($lot, float $amount): self
public function setLotWithdrawAmount(\App\Entity\Parts\PartLot|int $lot, float $amount): self
{
if ($lot instanceof PartLot) {
$lot_id = $lot->getID();
@ -218,8 +205,6 @@ final class ProjectBuildRequest
/**
* Returns the sum of all withdraw amounts for the given BOM entry.
* @param ProjectBOMEntry $entry
* @return float
*/
public function getWithdrawAmountSum(ProjectBOMEntry $entry): float
{
@ -239,14 +224,13 @@ final class ProjectBuildRequest
/**
* Returns the number of available lots to take stock from for the given BOM entry.
* @param ProjectBOMEntry $projectBOMEntry
* @return PartLot[]|null Returns null if the entry is a non-part BOM entry
*/
public function getPartLotsForBOMEntry(ProjectBOMEntry $projectBOMEntry): ?array
{
$this->ensureBOMEntryValid($projectBOMEntry);
if ($projectBOMEntry->getPart() === null) {
if (!$projectBOMEntry->getPart() instanceof \App\Entity\Parts\Part) {
return null;
}
@ -256,8 +240,6 @@ final class ProjectBuildRequest
/**
* Returns the needed amount of parts for the given BOM entry.
* @param ProjectBOMEntry $entry
* @return float
*/
public function getNeededAmountForBOMEntry(ProjectBOMEntry $entry): float
{
@ -281,14 +263,11 @@ final class ProjectBuildRequest
*/
public function getPartBomEntries(): array
{
return $this->project->getBomEntries()->filter(function (ProjectBOMEntry $entry) {
return $entry->isPartBomEntry();
})->toArray();
return $this->project->getBomEntries()->filter(fn(ProjectBOMEntry $entry) => $entry->isPartBomEntry())->toArray();
}
/**
* Returns which project should be build
* @return Project
*/
public function getProject(): Project
{
@ -297,7 +276,6 @@ final class ProjectBuildRequest
/**
* Returns the number of builds that should be created.
* @return int
*/
public function getNumberOfBuilds(): int
{

View file

@ -30,10 +30,6 @@ use JsonSerializable;
*/
final class TreeViewNode implements JsonSerializable
{
private string $text;
private ?string $href;
private ?array $nodes;
private ?TreeViewNodeState $state = null;
private ?array $tags = null;
@ -51,12 +47,8 @@ final class TreeViewNode implements JsonSerializable
* @param array|null $nodes An array containing other TreeViewNodes. They will be used as children nodes of the
* newly created nodes. Set to null, if it should not have children.
*/
public function __construct(string $text, ?string $href = null, ?array $nodes = null)
public function __construct(private string $text, private ?string $href = null, private ?array $nodes = null)
{
$this->text = $text;
$this->href = $href;
$this->nodes = $nodes;
//$this->state = new TreeViewNodeState();
}
@ -94,8 +86,6 @@ final class TreeViewNode implements JsonSerializable
* Sets the node text.
*
* @param string $text the new node text
*
* @return TreeViewNode
*/
public function setText(string $text): self
{
@ -116,8 +106,6 @@ final class TreeViewNode implements JsonSerializable
* Sets the href link.
*
* @param string|null $href the new href link
*
* @return TreeViewNode
*/
public function setHref(?string $href): self
{
@ -140,8 +128,6 @@ final class TreeViewNode implements JsonSerializable
* Sets the children nodes.
*
* @param array|null $nodes The new children nodes
*
* @return TreeViewNode
*/
public function setNodes(?array $nodes): self
{
@ -165,7 +151,7 @@ final class TreeViewNode implements JsonSerializable
public function setDisabled(?bool $disabled): self
{
//Lazy loading of state, so it does not need to get serialized and transfered, when it is empty.
if (null === $this->state) {
if (!$this->state instanceof \App\Helpers\Trees\TreeViewNodeState) {
$this->state = new TreeViewNodeState();
}
@ -177,7 +163,7 @@ final class TreeViewNode implements JsonSerializable
public function setSelected(?bool $selected): self
{
//Lazy loading of state, so it does not need to get serialized and transfered, when it is empty.
if (null === $this->state) {
if (!$this->state instanceof \App\Helpers\Trees\TreeViewNodeState) {
$this->state = new TreeViewNodeState();
}
@ -189,7 +175,7 @@ final class TreeViewNode implements JsonSerializable
public function setExpanded(?bool $selected = true): self
{
//Lazy loading of state, so it does not need to get serialized and transfered, when it is empty.
if (null === $this->state) {
if (!$this->state instanceof \App\Helpers\Trees\TreeViewNodeState) {
$this->state = new TreeViewNodeState();
}
@ -215,17 +201,11 @@ final class TreeViewNode implements JsonSerializable
return $this;
}
/**
* @return string|null
*/
public function getIcon(): ?string
{
return $this->icon;
}
/**
* @param string|null $icon
*/
public function setIcon(?string $icon): self
{
$this->icon = $icon;
@ -252,7 +232,7 @@ final class TreeViewNode implements JsonSerializable
$ret['nodes'] = $this->nodes;
}
if (null !== $this->state) {
if ($this->state instanceof \App\Helpers\Trees\TreeViewNodeState) {
$ret['state'] = $this->state;
}