mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 11:24:31 +02:00
Applied rector suggestions
This commit is contained in:
parent
4106bcef5f
commit
20f32c7f12
170 changed files with 808 additions and 761 deletions
|
@ -69,7 +69,7 @@ class EntityMerger
|
|||
{
|
||||
$merger = $this->findMergerForObject($target, $other, $context);
|
||||
if ($merger === null) {
|
||||
throw new \RuntimeException('No merger found for merging '.get_class($other).' into '.get_class($target));
|
||||
throw new \RuntimeException('No merger found for merging '.$other::class.' into '.$target::class);
|
||||
}
|
||||
return $merger->merge($target, $other, $context);
|
||||
}
|
||||
|
|
|
@ -85,9 +85,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useOtherValueIfNotNull(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return $target_value ?? $other_value;
|
||||
},
|
||||
fn($target_value, $other_value) => $target_value ?? $other_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -106,9 +104,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useOtherValueIfNotEmtpy(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return empty($target_value) ? $other_value : $target_value;
|
||||
},
|
||||
fn($target_value, $other_value) => empty($target_value) ? $other_value : $target_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -126,9 +122,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useLargerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return max($target_value, $other_value);
|
||||
},
|
||||
fn($target_value, $other_value) => max($target_value, $other_value),
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -146,9 +140,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useSmallerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return min($target_value, $other_value);
|
||||
},
|
||||
fn($target_value, $other_value) => min($target_value, $other_value),
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -166,9 +158,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useTrueValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function (bool $target_value, bool $other_value): bool {
|
||||
return $target_value || $other_value;
|
||||
},
|
||||
fn(bool $target_value, bool $other_value): bool => $target_value || $other_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -232,10 +222,8 @@ trait EntityMergerHelperTrait
|
|||
continue 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($target_collection->contains($item)) {
|
||||
continue;
|
||||
}
|
||||
} elseif ($target_collection->contains($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$clones[] = clone $item;
|
||||
|
@ -257,11 +245,9 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function mergeAttachments(AttachmentContainingDBElement $target, AttachmentContainingDBElement $other): object
|
||||
{
|
||||
return $this->mergeCollections($target, $other, 'attachments', function (Attachment $t, Attachment $o): bool {
|
||||
return $t->getName() === $o->getName()
|
||||
&& $t->getAttachmentType() === $o->getAttachmentType()
|
||||
&& $t->getPath() === $o->getPath();
|
||||
});
|
||||
return $this->mergeCollections($target, $other, 'attachments', fn(Attachment $t, Attachment $o): bool => $t->getName() === $o->getName()
|
||||
&& $t->getAttachmentType() === $o->getAttachmentType()
|
||||
&& $t->getPath() === $o->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,16 +258,14 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function mergeParameters(AbstractStructuralDBElement|Part $target, AbstractStructuralDBElement|Part $other): object
|
||||
{
|
||||
return $this->mergeCollections($target, $other, 'parameters', function (AbstractParameter $t, AbstractParameter $o): bool {
|
||||
return $t->getName() === $o->getName()
|
||||
&& $t->getSymbol() === $o->getSymbol()
|
||||
&& $t->getUnit() === $o->getUnit()
|
||||
&& $t->getValueMax() === $o->getValueMax()
|
||||
&& $t->getValueMin() === $o->getValueMin()
|
||||
&& $t->getValueTypical() === $o->getValueTypical()
|
||||
&& $t->getValueText() === $o->getValueText()
|
||||
&& $t->getGroup() === $o->getGroup();
|
||||
});
|
||||
return $this->mergeCollections($target, $other, 'parameters', fn(AbstractParameter $t, AbstractParameter $o): bool => $t->getName() === $o->getName()
|
||||
&& $t->getSymbol() === $o->getSymbol()
|
||||
&& $t->getUnit() === $o->getUnit()
|
||||
&& $t->getValueMax() === $o->getValueMax()
|
||||
&& $t->getValueMin() === $o->getValueMin()
|
||||
&& $t->getValueTypical() === $o->getValueTypical()
|
||||
&& $t->getValueText() === $o->getValueText()
|
||||
&& $t->getGroup() === $o->getGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ use App\Entity\PriceInformations\Orderdetail;
|
|||
* This class merges two parts together.
|
||||
*
|
||||
* @implements EntityMergerInterface<Part>
|
||||
* @see \App\Tests\Services\EntityMergers\Mergers\PartMergerTest
|
||||
*/
|
||||
class PartMerger implements EntityMergerInterface
|
||||
{
|
||||
|
@ -99,7 +100,7 @@ class PartMerger implements EntityMergerInterface
|
|||
return $target;
|
||||
}
|
||||
|
||||
private static function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool {
|
||||
private function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool {
|
||||
//We compare the translation keys, as it contains info about the type and other type info
|
||||
return $t->getOther() === $o->getOther()
|
||||
&& $t->getTypeTranslationKey() === $o->getTypeTranslationKey();
|
||||
|
@ -117,7 +118,7 @@ class PartMerger implements EntityMergerInterface
|
|||
$this->mergeParameters($target, $other);
|
||||
|
||||
//Merge the associations
|
||||
$this->mergeCollections($target, $other, 'associated_parts_as_owner', self::comparePartAssociations(...));
|
||||
$this->mergeCollections($target, $other, 'associated_parts_as_owner', $this->comparePartAssociations(...));
|
||||
|
||||
//We have to recreate the associations towards the other part, as they are not created by the merger
|
||||
foreach ($other->getAssociatedPartsAsOther() as $association) {
|
||||
|
@ -131,7 +132,7 @@ class PartMerger implements EntityMergerInterface
|
|||
}
|
||||
//Ensure that the association is not already present
|
||||
foreach ($owner->getAssociatedPartsAsOwner() as $existing_association) {
|
||||
if (self::comparePartAssociations($existing_association, $clone)) {
|
||||
if ($this->comparePartAssociations($existing_association, $clone)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue