mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 04:08:57 +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
|
@ -50,12 +50,8 @@ use InvalidArgumentException;
|
|||
|
||||
final class BarcodeGenerator
|
||||
{
|
||||
private BarcodeContentGenerator $barcodeContentGenerator;
|
||||
|
||||
|
||||
public function __construct(BarcodeContentGenerator $barcodeContentGenerator)
|
||||
public function __construct(private readonly BarcodeContentGenerator $barcodeContentGenerator)
|
||||
{
|
||||
$this->barcodeContentGenerator = $barcodeContentGenerator;
|
||||
}
|
||||
|
||||
public function generateHTMLBarcode(LabelOptions $options, object $target): ?string
|
||||
|
@ -126,18 +122,11 @@ final class BarcodeGenerator
|
|||
|
||||
public function getContent(LabelOptions $options, AbstractDBElement $target): ?string
|
||||
{
|
||||
switch ($options->getBarcodeType()) {
|
||||
case 'qr':
|
||||
case 'datamatrix':
|
||||
return $this->barcodeContentGenerator->getURLContent($target);
|
||||
case 'code39':
|
||||
case 'code93':
|
||||
case 'code128':
|
||||
return $this->barcodeContentGenerator->get1DBarcodeContent($target);
|
||||
case 'none':
|
||||
return null;
|
||||
default:
|
||||
throw new InvalidArgumentException('Unknown label type!');
|
||||
}
|
||||
return match ($options->getBarcodeType()) {
|
||||
'qr', 'datamatrix' => $this->barcodeContentGenerator->getURLContent($target),
|
||||
'code39', 'code93', 'code128' => $this->barcodeContentGenerator->get1DBarcodeContent($target),
|
||||
'none' => null,
|
||||
default => throw new InvalidArgumentException('Unknown label type!'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,11 +62,8 @@ final class BarcodeContentGenerator
|
|||
Storelocation::class => 'location',
|
||||
];
|
||||
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $urlGenerator)
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,17 +94,17 @@ final class BarcodeContentGenerator
|
|||
|
||||
private function classToString(array $map, object $target): string
|
||||
{
|
||||
$class = get_class($target);
|
||||
$class = $target::class;
|
||||
if (isset($map[$class])) {
|
||||
return $map[$class];
|
||||
}
|
||||
|
||||
foreach ($map as $class => $string) {
|
||||
if (is_a($target, $class)) {
|
||||
if ($target instanceof $class) {
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Unknown object class '.get_class($target));
|
||||
throw new InvalidArgumentException('Unknown object class '.$target::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|||
|
||||
final class BarcodeRedirector
|
||||
{
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $urlGenerator, EntityManagerInterface $entityManager)
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator, private readonly EntityManagerInterface $em)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +71,7 @@ final class BarcodeRedirector
|
|||
case 'lot':
|
||||
//Try to determine the part to the given lot
|
||||
$lot = $this->em->find(PartLot::class, $id);
|
||||
if (null === $lot) {
|
||||
if (!$lot instanceof \App\Entity\Parts\PartLot) {
|
||||
throw new EntityNotFoundException();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,16 +57,12 @@ final class LabelExampleElementsGenerator
|
|||
{
|
||||
public function getElement(string $type): object
|
||||
{
|
||||
switch ($type) {
|
||||
case 'part':
|
||||
return $this->getExamplePart();
|
||||
case 'part_lot':
|
||||
return $this->getExamplePartLot();
|
||||
case 'storelocation':
|
||||
return $this->getStorelocation();
|
||||
default:
|
||||
throw new InvalidArgumentException('Unknown $type.');
|
||||
}
|
||||
return match ($type) {
|
||||
'part' => $this->getExamplePart(),
|
||||
'part_lot' => $this->getExamplePartLot(),
|
||||
'storelocation' => $this->getStorelocation(),
|
||||
default => throw new InvalidArgumentException('Unknown $type.'),
|
||||
};
|
||||
}
|
||||
|
||||
public function getExamplePart(): Part
|
||||
|
|
|
@ -58,11 +58,8 @@ final class LabelGenerator
|
|||
|
||||
public const MM_TO_POINTS_FACTOR = 2.83465;
|
||||
|
||||
private LabelHTMLGenerator $labelHTMLGenerator;
|
||||
|
||||
public function __construct(LabelHTMLGenerator $labelHTMLGenerator)
|
||||
public function __construct(private readonly LabelHTMLGenerator $labelHTMLGenerator)
|
||||
{
|
||||
$this->labelHTMLGenerator = $labelHTMLGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,29 +52,13 @@ use Twig\Error\Error;
|
|||
|
||||
final class LabelHTMLGenerator
|
||||
{
|
||||
private Environment $twig;
|
||||
private ElementTypeNameGenerator $elementTypeNameGenerator;
|
||||
private LabelTextReplacer $replacer;
|
||||
private BarcodeGenerator $barcodeGenerator;
|
||||
private SandboxedTwigProvider $sandboxedTwigProvider;
|
||||
private string $partdb_title;
|
||||
private \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(ElementTypeNameGenerator $elementTypeNameGenerator, LabelTextReplacer $replacer, Environment $twig,
|
||||
BarcodeGenerator $barcodeGenerator, SandboxedTwigProvider $sandboxedTwigProvider, \Symfony\Bundle\SecurityBundle\Security $security, string $partdb_title)
|
||||
public function __construct(private readonly ElementTypeNameGenerator $elementTypeNameGenerator, private readonly LabelTextReplacer $replacer, private readonly Environment $twig, private readonly BarcodeGenerator $barcodeGenerator, private readonly SandboxedTwigProvider $sandboxedTwigProvider, private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly string $partdb_title)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
|
||||
$this->replacer = $replacer;
|
||||
$this->barcodeGenerator = $barcodeGenerator;
|
||||
$this->sandboxedTwigProvider = $sandboxedTwigProvider;
|
||||
$this->security = $security;
|
||||
$this->partdb_title = $partdb_title;
|
||||
}
|
||||
|
||||
public function getLabelHTML(LabelOptions $options, array $elements): string
|
||||
{
|
||||
if (empty($elements)) {
|
||||
if ($elements === []) {
|
||||
throw new InvalidArgumentException('$elements must not be empty');
|
||||
}
|
||||
|
||||
|
|
|
@ -50,15 +50,8 @@ use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
|||
|
||||
final class LabelProfileDropdownHelper
|
||||
{
|
||||
private TagAwareCacheInterface $cache;
|
||||
private EntityManagerInterface $entityManager;
|
||||
private UserCacheKeyGenerator $keyGenerator;
|
||||
|
||||
public function __construct(TagAwareCacheInterface $treeCache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator)
|
||||
public function __construct(private readonly TagAwareCacheInterface $cache, private readonly EntityManagerInterface $entityManager, private readonly UserCacheKeyGenerator $keyGenerator)
|
||||
{
|
||||
$this->cache = $treeCache;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->keyGenerator = $keyGenerator;
|
||||
}
|
||||
|
||||
public function getDropdownProfiles(string $type): array
|
||||
|
|
|
@ -49,11 +49,8 @@ use App\Services\LabelSystem\PlaceholderProviders\PlaceholderProviderInterface;
|
|||
*/
|
||||
final class LabelTextReplacer
|
||||
{
|
||||
private iterable $providers;
|
||||
|
||||
public function __construct(iterable $providers)
|
||||
public function __construct(private readonly iterable $providers)
|
||||
{
|
||||
$this->providers = $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,9 +86,7 @@ final class LabelTextReplacer
|
|||
public function replace(string $lines, object $target): string
|
||||
{
|
||||
$patterns = [
|
||||
'/(\[\[[A-Z_0-9]+\]\])/' => function ($match) use ($target) {
|
||||
return $this->handlePlaceholder($match[0], $target);
|
||||
},
|
||||
'/(\[\[[A-Z_0-9]+\]\])/' => fn($match) => $this->handlePlaceholder($match[0], $target),
|
||||
];
|
||||
|
||||
return preg_replace_callback_array($patterns, $lines);
|
||||
|
|
|
@ -46,11 +46,8 @@ use App\Services\ElementTypeNameGenerator;
|
|||
|
||||
final class AbstractDBElementProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
private ElementTypeNameGenerator $elementTypeNameGenerator;
|
||||
|
||||
public function __construct(ElementTypeNameGenerator $elementTypeNameGenerator)
|
||||
public function __construct(private readonly ElementTypeNameGenerator $elementTypeNameGenerator)
|
||||
{
|
||||
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
|
||||
}
|
||||
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
|
|
@ -26,13 +26,8 @@ use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
|
|||
|
||||
final class BarcodeProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
private BarcodeGenerator $barcodeGenerator;
|
||||
private BarcodeContentGenerator $barcodeContentGenerator;
|
||||
|
||||
public function __construct(BarcodeGenerator $barcodeGenerator, BarcodeContentGenerator $barcodeContentGenerator)
|
||||
public function __construct(private readonly BarcodeGenerator $barcodeGenerator, private readonly BarcodeContentGenerator $barcodeContentGenerator)
|
||||
{
|
||||
$this->barcodeGenerator = $barcodeGenerator;
|
||||
$this->barcodeContentGenerator = $barcodeContentGenerator;
|
||||
}
|
||||
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
@ -40,7 +35,7 @@ final class BarcodeProvider implements PlaceholderProviderInterface
|
|||
if ('[[1D_CONTENT]]' === $placeholder) {
|
||||
try {
|
||||
return $this->barcodeContentGenerator->get1DBarcodeContent($label_target);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException) {
|
||||
return 'ERROR!';
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +43,7 @@ final class BarcodeProvider implements PlaceholderProviderInterface
|
|||
if ('[[2D_CONTENT]]' === $placeholder) {
|
||||
try {
|
||||
return $this->barcodeContentGenerator->getURLContent($label_target);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException) {
|
||||
return 'ERROR!';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,15 +53,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
*/
|
||||
final class GlobalProviders implements PlaceholderProviderInterface
|
||||
{
|
||||
private string $partdb_title;
|
||||
private \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
private UrlGeneratorInterface $url_generator;
|
||||
|
||||
public function __construct(string $partdb_title, \Symfony\Bundle\SecurityBundle\Security $security, UrlGeneratorInterface $url_generator)
|
||||
public function __construct(private readonly string $partdb_title, private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly UrlGeneratorInterface $url_generator)
|
||||
{
|
||||
$this->partdb_title = $partdb_title;
|
||||
$this->security = $security;
|
||||
$this->url_generator = $url_generator;
|
||||
}
|
||||
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
|
|
@ -49,13 +49,8 @@ use Locale;
|
|||
|
||||
final class PartLotProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
private LabelTextReplacer $labelTextReplacer;
|
||||
private AmountFormatter $amountFormatter;
|
||||
|
||||
public function __construct(LabelTextReplacer $labelTextReplacer, AmountFormatter $amountFormatter)
|
||||
public function __construct(private readonly LabelTextReplacer $labelTextReplacer, private readonly AmountFormatter $amountFormatter)
|
||||
{
|
||||
$this->labelTextReplacer = $labelTextReplacer;
|
||||
$this->amountFormatter = $amountFormatter;
|
||||
}
|
||||
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
|
@ -74,7 +69,7 @@ final class PartLotProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[EXPIRATION_DATE]]' === $placeholder) {
|
||||
if (null === $label_target->getExpirationDate()) {
|
||||
if (!$label_target->getExpirationDate() instanceof \DateTimeInterface) {
|
||||
return '';
|
||||
}
|
||||
$formatter = IntlDateFormatter::create(
|
||||
|
@ -95,19 +90,19 @@ final class PartLotProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[LOCATION]]' === $placeholder) {
|
||||
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : '';
|
||||
return $label_target->getStorageLocation() instanceof \App\Entity\Parts\Storelocation ? $label_target->getStorageLocation()->getName() : '';
|
||||
}
|
||||
|
||||
if ('[[LOCATION_FULL]]' === $placeholder) {
|
||||
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : '';
|
||||
return $label_target->getStorageLocation() instanceof \App\Entity\Parts\Storelocation ? $label_target->getStorageLocation()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ('[[OWNER]]' === $placeholder) {
|
||||
return $label_target->getOwner() ? $label_target->getOwner()->getFullName() : '';
|
||||
return $label_target->getOwner() instanceof \App\Entity\UserSystem\User ? $label_target->getOwner()->getFullName() : '';
|
||||
}
|
||||
|
||||
if ('[[OWNER_USERNAME]]' === $placeholder) {
|
||||
return $label_target->getOwner() ? $label_target->getOwner()->getUsername() : '';
|
||||
return $label_target->getOwner() instanceof \App\Entity\UserSystem\User ? $label_target->getOwner()->getUsername() : '';
|
||||
}
|
||||
|
||||
return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart());
|
||||
|
|
|
@ -48,13 +48,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
final class PartProvider implements PlaceholderProviderInterface
|
||||
{
|
||||
private SIFormatter $siFormatter;
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(SIFormatter $SIFormatter, TranslatorInterface $translator)
|
||||
public function __construct(private readonly SIFormatter $siFormatter, private readonly TranslatorInterface $translator)
|
||||
{
|
||||
$this->siFormatter = $SIFormatter;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function replace(string $placeholder, object $part, array $options = []): ?string
|
||||
|
@ -64,27 +59,27 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[CATEGORY]]' === $placeholder) {
|
||||
return $part->getCategory() ? $part->getCategory()->getName() : '';
|
||||
return $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getName() : '';
|
||||
}
|
||||
|
||||
if ('[[CATEGORY_FULL]]' === $placeholder) {
|
||||
return $part->getCategory() ? $part->getCategory()->getFullPath() : '';
|
||||
return $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ('[[MANUFACTURER]]' === $placeholder) {
|
||||
return $part->getManufacturer() ? $part->getManufacturer()->getName() : '';
|
||||
return $part->getManufacturer() instanceof \App\Entity\Parts\Manufacturer ? $part->getManufacturer()->getName() : '';
|
||||
}
|
||||
|
||||
if ('[[MANUFACTURER_FULL]]' === $placeholder) {
|
||||
return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : '';
|
||||
return $part->getManufacturer() instanceof \App\Entity\Parts\Manufacturer ? $part->getManufacturer()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ('[[FOOTPRINT]]' === $placeholder) {
|
||||
return $part->getFootprint() ? $part->getFootprint()->getName() : '';
|
||||
return $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getName() : '';
|
||||
}
|
||||
|
||||
if ('[[FOOTPRINT_FULL]]' === $placeholder) {
|
||||
return $part->getFootprint() ? $part->getFootprint()->getFullPath() : '';
|
||||
return $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ('[[MASS]]' === $placeholder) {
|
||||
|
@ -114,7 +109,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[DESCRIPTION_T]]' === $placeholder) {
|
||||
return strip_tags($parsedown->line($part->getDescription()));
|
||||
return strip_tags((string) $parsedown->line($part->getDescription()));
|
||||
}
|
||||
|
||||
if ('[[COMMENT]]' === $placeholder) {
|
||||
|
@ -122,7 +117,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[COMMENT_T]]' === $placeholder) {
|
||||
return strip_tags($parsedown->line($part->getComment()));
|
||||
return strip_tags((string) $parsedown->line($part->getComment()));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -28,11 +28,11 @@ class StorelocationProvider implements PlaceholderProviderInterface
|
|||
{
|
||||
if ($label_target instanceof Storelocation) {
|
||||
if ('[[OWNER]]' === $placeholder) {
|
||||
return $label_target->getOwner() ? $label_target->getOwner()->getFullName() : '';
|
||||
return $label_target->getOwner() instanceof \App\Entity\UserSystem\User ? $label_target->getOwner()->getFullName() : '';
|
||||
}
|
||||
|
||||
if ('[[OWNER_USERNAME]]' === $placeholder) {
|
||||
return $label_target->getOwner() ? $label_target->getOwner()->getUsername() : '';
|
||||
return $label_target->getOwner() instanceof \App\Entity\UserSystem\User ? $label_target->getOwner()->getUsername() : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,10 +58,10 @@ final class StructuralDBElementProvider implements PlaceholderProviderInterface
|
|||
return $label_target->getFullPath();
|
||||
}
|
||||
if ('[[PARENT]]' === $placeholder) {
|
||||
return $label_target->getParent() ? $label_target->getParent()->getName() : '';
|
||||
return $label_target->getParent() instanceof \App\Entity\Base\AbstractStructuralDBElement ? $label_target->getParent()->getName() : '';
|
||||
}
|
||||
if ('[[PARENT_FULL_PATH]]' === $placeholder) {
|
||||
return $label_target->getParent() ? $label_target->getParent()->getFullPath() : '';
|
||||
return $label_target->getParent() instanceof \App\Entity\Base\AbstractStructuralDBElement ? $label_target->getParent()->getFullPath() : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,11 +114,8 @@ final class SandboxedTwigProvider
|
|||
];
|
||||
private const ALLOWED_PROPERTIES = [];
|
||||
|
||||
private FormatExtension $appExtension;
|
||||
|
||||
public function __construct(FormatExtension $appExtension)
|
||||
public function __construct(private readonly FormatExtension $appExtension)
|
||||
{
|
||||
$this->appExtension = $appExtension;
|
||||
}
|
||||
|
||||
public function getTwig(LabelOptions $options): Environment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue