mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 04:30:08 +02:00
Fixed some inspection issues.
This commit is contained in:
parent
eef26f7ae6
commit
639829f5c5
97 changed files with 305 additions and 185 deletions
|
@ -26,6 +26,7 @@ namespace App\Services\LabelSystem;
|
|||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
|
||||
use Com\Tecnick\Barcode\Barcode;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class BarcodeGenerator
|
||||
{
|
||||
|
@ -64,7 +65,7 @@ final class BarcodeGenerator
|
|||
case 'none':
|
||||
return null;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown label type!');
|
||||
throw new InvalidArgumentException('Unknown label type!');
|
||||
}
|
||||
|
||||
$bobj = $barcode->getBarcodeObj($type, $this->getContent($options, $target));
|
||||
|
@ -85,7 +86,7 @@ final class BarcodeGenerator
|
|||
case 'none':
|
||||
return null;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown label type!');
|
||||
throw new InvalidArgumentException('Unknown label type!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Entity\Base\AbstractDBElement;
|
|||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
final class BarcodeContentGenerator
|
||||
|
@ -88,6 +89,6 @@ final class BarcodeContentGenerator
|
|||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Unknown object class '.get_class($target));
|
||||
throw new InvalidArgumentException('Unknown object class '.get_class($target));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ use App\Entity\Parts\Manufacturer;
|
|||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use DateTime;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
final class BarcodeExampleElementsGenerator
|
||||
{
|
||||
|
@ -43,7 +46,7 @@ final class BarcodeExampleElementsGenerator
|
|||
case 'storelocation':
|
||||
return $this->getStorelocation();
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown $type.');
|
||||
throw new InvalidArgumentException('Unknown $type.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +81,7 @@ final class BarcodeExampleElementsGenerator
|
|||
|
||||
$lot->setDescription('Example Lot');
|
||||
$lot->setComment('Lot comment');
|
||||
$lot->setExpirationDate(new \DateTime('+1 days'));
|
||||
$lot->setExpirationDate(new DateTime('+1 days'));
|
||||
$lot->setStorageLocation($this->getStructuralData(Storelocation::class));
|
||||
$lot->setAmount(123);
|
||||
|
||||
|
@ -103,7 +106,7 @@ final class BarcodeExampleElementsGenerator
|
|||
private function getStructuralData(string $class): AbstractStructuralDBElement
|
||||
{
|
||||
if (!is_a($class, AbstractStructuralDBElement::class, true)) {
|
||||
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
|
||||
throw new InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
|
||||
}
|
||||
|
||||
/** @var AbstractStructuralDBElement $parent */
|
||||
|
@ -112,7 +115,7 @@ final class BarcodeExampleElementsGenerator
|
|||
|
||||
/** @var AbstractStructuralDBElement $child */
|
||||
$child = new $class();
|
||||
$child->setName((new \ReflectionClass($class))->getShortName());
|
||||
$child->setName((new ReflectionClass($class))->getShortName());
|
||||
$child->setParent($parent);
|
||||
|
||||
return $child;
|
||||
|
|
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\LabelSystem\Barcodes;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class BarcodeNormalizer
|
||||
{
|
||||
private const PREFIX_TYPE_MAP = [
|
||||
|
@ -54,7 +56,7 @@ final class BarcodeNormalizer
|
|||
$id = (int) $matches[2];
|
||||
|
||||
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) {
|
||||
throw new \InvalidArgumentException('Unknown prefix '.$prefix);
|
||||
throw new InvalidArgumentException('Unknown prefix '.$prefix);
|
||||
}
|
||||
|
||||
return [self::PREFIX_TYPE_MAP[$prefix], $id];
|
||||
|
@ -66,7 +68,7 @@ final class BarcodeNormalizer
|
|||
$id = (int) $matches[2];
|
||||
|
||||
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) {
|
||||
throw new \InvalidArgumentException('Unknown prefix '.$prefix);
|
||||
throw new InvalidArgumentException('Unknown prefix '.$prefix);
|
||||
}
|
||||
|
||||
return [self::PREFIX_TYPE_MAP[$prefix], $id];
|
||||
|
@ -82,6 +84,6 @@ final class BarcodeNormalizer
|
|||
return ['part', (int) $matches[1]];
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Unknown barcode format!');
|
||||
throw new InvalidArgumentException('Unknown barcode format!');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Services\LabelSystem\Barcodes;
|
|||
use App\Entity\Parts\PartLot;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
final class BarcodeRedirector
|
||||
|
@ -67,7 +68,7 @@ final class BarcodeRedirector
|
|||
return $this->urlGenerator->generate('part_list_store_location', ['id' => $id]);
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown $type: '.$type);
|
||||
throw new InvalidArgumentException('Unknown $type: '.$type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ use App\Entity\Parts\Part;
|
|||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
use Dompdf\Dompdf;
|
||||
use InvalidArgumentException;
|
||||
|
||||
final class LabelGenerator
|
||||
{
|
||||
|
@ -52,7 +53,7 @@ final class LabelGenerator
|
|||
public function generateLabel(LabelOptions $options, $elements): string
|
||||
{
|
||||
if (!is_array($elements) && !is_object($elements)) {
|
||||
throw new \InvalidArgumentException('$element must be an object or an array of objects!');
|
||||
throw new InvalidArgumentException('$element must be an object or an array of objects!');
|
||||
}
|
||||
|
||||
if (!is_array($elements)) {
|
||||
|
@ -61,7 +62,7 @@ final class LabelGenerator
|
|||
|
||||
foreach ($elements as $element) {
|
||||
if (!$this->supports($options, $element)) {
|
||||
throw new \InvalidArgumentException('The given options are not compatible with the given element!');
|
||||
throw new InvalidArgumentException('The given options are not compatible with the given element!');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,7 @@ final class LabelGenerator
|
|||
{
|
||||
$supported_type = $options->getSupportedElement();
|
||||
if (!isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) {
|
||||
throw new \InvalidArgumentException('Supported type name of the Label options not known!');
|
||||
throw new InvalidArgumentException('Supported type name of the Label options not known!');
|
||||
}
|
||||
|
||||
return is_a($element, static::CLASS_SUPPORT_MAPPING[$supported_type]);
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Entity\Contracts\NamedElementInterface;
|
|||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Exceptions\TwigModeException;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\Error;
|
||||
|
@ -56,7 +57,7 @@ final class LabelHTMLGenerator
|
|||
public function getLabelHTML(LabelOptions $options, array $elements): string
|
||||
{
|
||||
if (empty($elements)) {
|
||||
throw new \InvalidArgumentException('$elements must not be empty');
|
||||
throw new InvalidArgumentException('$elements must not be empty');
|
||||
}
|
||||
|
||||
$twig_elements = [];
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Services\LabelSystem\PlaceholderProviders;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use DateTime;
|
||||
use IntlDateFormatter;
|
||||
use Locale;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
@ -65,7 +66,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
|
|||
return 'anonymous';
|
||||
}
|
||||
|
||||
$now = new \DateTime();
|
||||
$now = new DateTime();
|
||||
|
||||
if ('[[DATETIME]]' === $placeholder) {
|
||||
$formatter = IntlDateFormatter::create(
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Services\LabelSystem\PlaceholderProviders;
|
|||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\SIFormatter;
|
||||
use Parsedown;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class PartProvider implements PlaceholderProviderInterface
|
||||
|
@ -88,7 +89,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
return $this->translator->trans('m_status.'.$part->getManufacturingStatus());
|
||||
}
|
||||
|
||||
$parsedown = new \Parsedown();
|
||||
$parsedown = new Parsedown();
|
||||
|
||||
if ('[[DESCRIPTION]]' === $placeholder) {
|
||||
return $parsedown->line($part->getDescription());
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Services\LabelSystem\PlaceholderProviders;
|
||||
|
||||
use App\Entity\Contracts\TimeStampableInterface;
|
||||
use DateTime;
|
||||
use IntlDateFormatter;
|
||||
use Locale;
|
||||
|
||||
|
@ -35,11 +36,11 @@ final class TimestampableElementProvider implements PlaceholderProviderInterface
|
|||
$formatter = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
|
||||
|
||||
if ('[[LAST_MODIFIED]]' === $placeholder) {
|
||||
return $formatter->format($label_target->getLastModified() ?? new \DateTime());
|
||||
return $formatter->format($label_target->getLastModified() ?? new DateTime());
|
||||
}
|
||||
|
||||
if ('[[CREATION_DATE]]' === $placeholder) {
|
||||
return $formatter->format($label_target->getAddedDate() ?? new \DateTime());
|
||||
return $formatter->format($label_target->getAddedDate() ?? new DateTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,11 @@ use App\Entity\PriceInformations\Pricedetail;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Twig\AppExtension;
|
||||
use App\Twig\Sandbox\InheritanceSecurityPolicy;
|
||||
use InvalidArgumentException;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\SandboxExtension;
|
||||
use Twig\Extra\Intl\IntlExtension;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use Twig\Sandbox\SecurityPolicyInterface;
|
||||
|
||||
final class SandboxedTwigProvider
|
||||
|
@ -104,10 +106,10 @@ final class SandboxedTwigProvider
|
|||
public function getTwig(LabelOptions $options): Environment
|
||||
{
|
||||
if ('twig' !== $options->getLinesMode()) {
|
||||
throw new \InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!');
|
||||
throw new InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!');
|
||||
}
|
||||
|
||||
$loader = new \Twig\Loader\ArrayLoader([
|
||||
$loader = new ArrayLoader([
|
||||
'lines' => $options->getLines(),
|
||||
]);
|
||||
$twig = new Environment($loader);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue