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
|
@ -44,13 +44,8 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach
|
|||
'storage_location' => 'storelocation',
|
||||
];
|
||||
|
||||
private ObjectNormalizer $normalizer;
|
||||
private StructuralElementFromNameDenormalizer $locationDenormalizer;
|
||||
|
||||
public function __construct(ObjectNormalizer $normalizer, StructuralElementFromNameDenormalizer $locationDenormalizer)
|
||||
public function __construct(private readonly ObjectNormalizer $normalizer, private readonly StructuralElementFromNameDenormalizer $locationDenormalizer)
|
||||
{
|
||||
$this->normalizer = $normalizer;
|
||||
$this->locationDenormalizer = $locationDenormalizer;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, string $format = null): bool
|
||||
|
@ -120,12 +115,12 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach
|
|||
throw new \InvalidArgumentException('This normalizer only supports Part objects!');
|
||||
}
|
||||
|
||||
if ((isset($data['instock']) && trim($data['instock']) !== "") || (isset($data['storelocation']) && trim($data['storelocation']) !== "")) {
|
||||
if ((isset($data['instock']) && trim((string) $data['instock']) !== "") || (isset($data['storelocation']) && trim((string) $data['storelocation']) !== "")) {
|
||||
$partLot = new PartLot();
|
||||
|
||||
if (isset($data['instock']) && $data['instock'] !== "") {
|
||||
//Replace comma with dot
|
||||
$instock = (float) str_replace(',', '.', $data['instock']);
|
||||
$instock = (float) str_replace(',', '.', (string) $data['instock']);
|
||||
|
||||
$partLot->setAmount($instock);
|
||||
} else {
|
||||
|
@ -157,7 +152,7 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Cach
|
|||
$pricedetail = new Pricedetail();
|
||||
$pricedetail->setMinDiscountQuantity(1);
|
||||
$pricedetail->setPriceRelatedQuantity(1);
|
||||
$price = BigDecimal::of(str_replace(',', '.', $data['price']));
|
||||
$price = BigDecimal::of(str_replace(',', '.', (string) $data['price']));
|
||||
$pricedetail->setPrice($price);
|
||||
|
||||
$orderdetail->addPricedetail($pricedetail);
|
||||
|
|
|
@ -31,15 +31,10 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
|||
class StructuralElementDenormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface, CacheableSupportsMethodInterface
|
||||
{
|
||||
|
||||
private DenormalizerInterface $normalizer;
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private array $object_cache = [];
|
||||
|
||||
public function __construct(ObjectNormalizer $normalizer, EntityManagerInterface $entityManager)
|
||||
public function __construct(private readonly ObjectNormalizer $normalizer, private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->normalizer = $normalizer;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
|
||||
|
@ -61,7 +56,7 @@ class StructuralElementDenormalizer implements \Symfony\Component\Serializer\Nor
|
|||
|
||||
$path = $deserialized_entity->getFullPath(AbstractStructuralDBElement::PATH_DELIMITER_ARROW);
|
||||
$db_elements = $repo->getEntityByPath($path, AbstractStructuralDBElement::PATH_DELIMITER_ARROW);
|
||||
if ($db_elements) {
|
||||
if ($db_elements !== []) {
|
||||
//We already have the entity in the database, so we can return it
|
||||
return end($db_elements);
|
||||
}
|
||||
|
|
|
@ -28,11 +28,8 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
|||
|
||||
class StructuralElementFromNameDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(private readonly EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function supportsDenormalization($data, string $type, string $format = null): bool
|
||||
|
@ -54,14 +51,14 @@ class StructuralElementFromNameDenormalizer implements DenormalizerInterface, Ca
|
|||
foreach ($elements as $element) {
|
||||
$this->em->persist($element);
|
||||
}
|
||||
if (empty($elements)) {
|
||||
if ($elements === []) {
|
||||
return null;
|
||||
}
|
||||
return end($elements);
|
||||
}
|
||||
|
||||
$elements = $repo->getEntityByPath($data, $path_delimiter);
|
||||
if (empty($elements)) {
|
||||
if ($elements === []) {
|
||||
return null;
|
||||
}
|
||||
return end($elements);
|
||||
|
|
|
@ -27,11 +27,8 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
|||
|
||||
class StructuralElementNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
public function __construct(ObjectNormalizer $normalizer)
|
||||
public function __construct(private readonly ObjectNormalizer $normalizer)
|
||||
{
|
||||
$this->normalizer = $normalizer;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, string $format = null): bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue