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

@ -9,20 +9,12 @@ use App\Services\LogSystem\EventLogger;
final class PartLotWithdrawAddHelper
{
private EventLogger $eventLogger;
private EventCommentHelper $eventCommentHelper;
public function __construct(EventLogger $eventLogger, EventCommentHelper $eventCommentHelper)
public function __construct(private readonly EventLogger $eventLogger, private readonly EventCommentHelper $eventCommentHelper)
{
$this->eventLogger = $eventLogger;
$this->eventCommentHelper = $eventCommentHelper;
}
/**
* Checks whether the given part can
* @param PartLot $partLot
* @return bool
*/
public function canAdd(PartLot $partLot): bool
{
@ -32,16 +24,11 @@ final class PartLotWithdrawAddHelper
}
//So far all other restrictions are defined at the storelocation level
if($partLot->getStorageLocation() === null) {
if(!$partLot->getStorageLocation() instanceof \App\Entity\Parts\Storelocation) {
return true;
}
//We can not add parts if the storage location of the lot is marked as full
if($partLot->getStorageLocation()->isFull()) {
return false;
}
return true;
return !$partLot->getStorageLocation()->isFull();
}
public function canWithdraw(PartLot $partLot): bool
@ -50,13 +37,8 @@ final class PartLotWithdrawAddHelper
if ($partLot->isInstockUnknown()) {
return false;
}
//Part must contain more than 0 parts
if ($partLot->getAmount() <= 0) {
return false;
}
return true;
return $partLot->getAmount() > 0;
}
/**
@ -153,7 +135,6 @@ final class PartLotWithdrawAddHelper
* @param PartLot $target The part lot to which the parts should be added
* @param float $amount The amount of parts that should be moved
* @param string|null $comment A comment describing the reason for the move
* @return void
*/
public function move(PartLot $origin, PartLot $target, float $amount, ?string $comment = null): void
{

View file

@ -37,15 +37,8 @@ use Symfony\Component\Security\Core\Security;
final class PartsTableActionHandler
{
private EntityManagerInterface $entityManager;
private \Symfony\Bundle\SecurityBundle\Security $security;
private UrlGeneratorInterface $urlGenerator;
public function __construct(EntityManagerInterface $entityManager, \Symfony\Bundle\SecurityBundle\Security $security, UrlGeneratorInterface $urlGenerator)
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly UrlGeneratorInterface $urlGenerator)
{
$this->entityManager = $entityManager;
$this->security = $security;
$this->urlGenerator = $urlGenerator;
}
/**
@ -86,10 +79,8 @@ final class PartsTableActionHandler
if ($action === 'generate_label') {
$targets = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts));
} else { //For lots we have to extract the part lots
$targets = implode(',', array_map(static function (Part $part) {
//We concat the lot IDs of every part with a comma (which are later concated with a comma too per part)
return implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPartLots()->toArray()));
}, $selected_parts));
$targets = implode(',', array_map(static fn(Part $part): string => //We concat the lot IDs of every part with a comma (which are later concated with a comma too per part)
implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPartLots()->toArray())), $selected_parts));
}
return new RedirectResponse(
@ -106,18 +97,11 @@ final class PartsTableActionHandler
$matches = [];
if (preg_match('/^export_(json|yaml|xml|csv)$/', $action, $matches)) {
$ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts));
switch ($target_id) {
case 1:
default:
$level = 'simple';
break;
case 2:
$level = 'extended';
break;
case 3:
$level = 'full';
break;
}
$level = match ($target_id) {
2 => 'extended',
3 => 'full',
default => 'simple',
};
return new RedirectResponse(

View file

@ -34,12 +34,10 @@ use function count;
class PricedetailHelper
{
protected string $base_currency;
protected string $locale;
public function __construct(string $base_currency)
public function __construct(protected string $base_currency)
{
$this->base_currency = $base_currency;
$this->locale = Locale::getDefault();
}
@ -67,9 +65,7 @@ class PricedetailHelper
} else {
// We have to sort the pricedetails manually
$array = $pricedetails->map(
static function (Pricedetail $pricedetail) {
return $pricedetail->getMinDiscountQuantity();
}
static fn(Pricedetail $pricedetail) => $pricedetail->getMinDiscountQuantity()
)->toArray();
sort($array);
$max_amount = end($array);
@ -154,13 +150,13 @@ class PricedetailHelper
$pricedetail = $orderdetail->findPriceForQty($amount);
//When we don't have information about this amount, ignore it
if (null === $pricedetail) {
if (!$pricedetail instanceof \App\Entity\PriceInformations\Pricedetail) {
continue;
}
$converted = $this->convertMoneyToCurrency($pricedetail->getPricePerUnit(), $pricedetail->getCurrency(), $currency);
//Ignore price information that can not be converted to base currency.
if (null !== $converted) {
if ($converted instanceof \Brick\Math\BigDecimal) {
$avg = $avg->plus($converted);
++$count;
}
@ -193,9 +189,9 @@ class PricedetailHelper
$val_base = $value;
//Convert value to base currency
if (null !== $originCurrency) {
if ($originCurrency instanceof \App\Entity\PriceInformations\Currency) {
//Without an exchange rate we can not calculate the exchange rate
if (null === $originCurrency->getExchangeRate() || $originCurrency->getExchangeRate()->isZero()) {
if (!$originCurrency->getExchangeRate() instanceof \Brick\Math\BigDecimal || $originCurrency->getExchangeRate()->isZero()) {
return null;
}
@ -204,9 +200,9 @@ class PricedetailHelper
$val_target = $val_base;
//Convert value in base currency to target currency
if (null !== $targetCurrency) {
if ($targetCurrency instanceof \App\Entity\PriceInformations\Currency) {
//Without an exchange rate we can not calculate the exchange rate
if (null === $targetCurrency->getExchangeRate()) {
if (!$targetCurrency->getExchangeRate() instanceof \Brick\Math\BigDecimal) {
return null;
}