mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-09 18:04:33 +02:00
Fixed some inspection issues.
This commit is contained in:
parent
eef26f7ae6
commit
639829f5c5
97 changed files with 305 additions and 185 deletions
|
@ -63,6 +63,7 @@ use App\Entity\UserSystem\Group;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Exceptions\EntityNotSupportedException;
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use DateTime;
|
||||
use function array_key_exists;
|
||||
use function get_class;
|
||||
use InvalidArgumentException;
|
||||
|
@ -128,7 +129,7 @@ class EntityURLGenerator
|
|||
/**
|
||||
* Gets the URL to view the given element at a given timestamp.
|
||||
*/
|
||||
public function timeTravelURL(AbstractDBElement $entity, \DateTime $dateTime): string
|
||||
public function timeTravelURL(AbstractDBElement $entity, DateTime $dateTime): string
|
||||
{
|
||||
$map = [
|
||||
Part::class => 'part_info',
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Services\LogSystem;
|
||||
|
||||
use App\Entity\LogSystem\AbstractLogEntry;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class EventUndoHelper
|
||||
{
|
||||
|
@ -44,7 +45,7 @@ class EventUndoHelper
|
|||
public function setMode(string $mode): void
|
||||
{
|
||||
if (!in_array($mode, self::ALLOWED_MODES, true)) {
|
||||
throw new \InvalidArgumentException('Invalid mode passed!');
|
||||
throw new InvalidArgumentException('Invalid mode passed!');
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Services\LogSystem;
|
|||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parts\Part;
|
||||
|
||||
class HistoryHelper
|
||||
|
@ -38,7 +39,7 @@ class HistoryHelper
|
|||
* Returns an array containing all elements that are associated with the argument.
|
||||
* The returned array contains the given element.
|
||||
*
|
||||
* @psalm-return array<\App\Entity\Parameters\AbstractParameter|array-key, mixed>
|
||||
* @psalm-return array<AbstractParameter|array-key, mixed>
|
||||
*/
|
||||
public function getAssociatedElements(AbstractDBElement $element): array
|
||||
{
|
||||
|
|
|
@ -33,9 +33,14 @@ use App\Entity\LogSystem\AbstractLogEntry;
|
|||
use App\Entity\LogSystem\CollectionElementDeleted;
|
||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||
use Brick\Math\BigDecimal;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
class TimeTravel
|
||||
{
|
||||
|
@ -74,16 +79,16 @@ class TimeTravel
|
|||
*
|
||||
* @param AbstractLogEntry[] $reverted_elements
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = []): void
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, DateTime $timestamp, array $reverted_elements = []): void
|
||||
{
|
||||
if (!$element instanceof TimeStampableInterface) {
|
||||
throw new \InvalidArgumentException('$element must have a Timestamp!');
|
||||
throw new InvalidArgumentException('$element must have a Timestamp!');
|
||||
}
|
||||
|
||||
if ($timestamp > new \DateTime('now')) {
|
||||
throw new \InvalidArgumentException('You can not travel to the future (yet)...');
|
||||
if ($timestamp > new DateTime('now')) {
|
||||
throw new InvalidArgumentException('You can not travel to the future (yet)...');
|
||||
}
|
||||
|
||||
//Skip this process if already were reverted...
|
||||
|
@ -168,7 +173,7 @@ class TimeTravel
|
|||
/**
|
||||
* Apply the changeset in the given LogEntry to the element.
|
||||
*
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logEntry): void
|
||||
{
|
||||
|
@ -207,7 +212,7 @@ class TimeTravel
|
|||
|
||||
protected function getField(AbstractDBElement $element, string $field)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
@ -215,11 +220,11 @@ class TimeTravel
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime|int|null $new_value
|
||||
* @param DateTime|int|null $new_value
|
||||
*/
|
||||
protected function setField(AbstractDBElement $element, string $field, $new_value): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\Misc;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* This Parser allows to parse number ranges like 1-3, 4, 5.
|
||||
*/
|
||||
|
@ -53,7 +55,7 @@ class RangeParser
|
|||
} elseif (empty($number)) { //Allow empty tokens
|
||||
continue;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Invalid range encoutered: '.$number);
|
||||
throw new InvalidArgumentException('Invalid range encoutered: '.$number);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +76,7 @@ class RangeParser
|
|||
$this->parse($range_str);
|
||||
|
||||
return true;
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,9 +74,9 @@ class MoneyFormatter
|
|||
|
||||
$number_formatter = new NumberFormatter($this->locale, NumberFormatter::CURRENCY);
|
||||
if ($show_all_digits) {
|
||||
$number_formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals);
|
||||
$number_formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $decimals);
|
||||
} else {
|
||||
$number_formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
|
||||
$number_formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
|
||||
}
|
||||
|
||||
return $number_formatter->formatCurrency((float) $value, $iso_code);
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace App\Services\Parameters;
|
|||
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parameters\PartParameter;
|
||||
use InvalidArgumentException;
|
||||
|
||||
use function preg_match;
|
||||
|
||||
class ParameterExtractor
|
||||
{
|
||||
|
@ -41,7 +44,7 @@ class ParameterExtractor
|
|||
public function extractParameters(string $input, string $class = PartParameter::class): array
|
||||
{
|
||||
if (!is_a($class, AbstractParameter::class, true)) {
|
||||
throw new \InvalidArgumentException('$class must be a child class of AbstractParameter!');
|
||||
throw new InvalidArgumentException('$class must be a child class of AbstractParameter!');
|
||||
}
|
||||
|
||||
//Restrict search length
|
||||
|
@ -67,7 +70,7 @@ class ParameterExtractor
|
|||
$regex = '/^(.*) *(?:=|:) *(.+)/u';
|
||||
|
||||
$matches = [];
|
||||
\preg_match($regex, $input, $matches);
|
||||
preg_match($regex, $input, $matches);
|
||||
if (!empty($matches)) {
|
||||
[, $name, $value] = $matches;
|
||||
$value = trim($value);
|
||||
|
|
|
@ -28,6 +28,7 @@ use App\Entity\Parts\Part;
|
|||
use App\Repository\DBElementRepository;
|
||||
use App\Repository\PartRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
|
@ -67,7 +68,7 @@ final class PartsTableActionHandler
|
|||
//Iterate over the parts and apply the action to it:
|
||||
foreach ($selected_parts as $part) {
|
||||
if (!$part instanceof Part) {
|
||||
throw new \InvalidArgumentException('$selected_parts must be an array of Part elements!');
|
||||
throw new InvalidArgumentException('$selected_parts must be an array of Part elements!');
|
||||
}
|
||||
|
||||
//We modify parts, so you have to have the permission to modify it
|
||||
|
@ -102,7 +103,7 @@ final class PartsTableActionHandler
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('The given action is unknown! ('.$action.')');
|
||||
throw new InvalidArgumentException('The given action is unknown! ('.$action.')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,15 +43,14 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class PasswordResetManager
|
||||
|
@ -88,7 +87,7 @@ class PasswordResetManager
|
|||
$user->setPwResetToken($this->passwordEncoder->hash($unencrypted_token, null));
|
||||
|
||||
//Determine the expiration datetime of
|
||||
$expiration_date = new \DateTime();
|
||||
$expiration_date = new DateTime();
|
||||
$expiration_date->add(date_interval_create_from_date_string('1 day'));
|
||||
$user->setPwResetExpires($expiration_date);
|
||||
|
||||
|
@ -135,7 +134,7 @@ class PasswordResetManager
|
|||
}
|
||||
|
||||
//Check if token is expired yet
|
||||
if ($user->getPwResetExpires() < new \DateTime()) {
|
||||
if ($user->getPwResetExpires() < new DateTime()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -149,7 +148,7 @@ class PasswordResetManager
|
|||
|
||||
//Remove token
|
||||
$user->setPwResetToken(null);
|
||||
$user->setPwResetExpires(new \DateTime());
|
||||
$user->setPwResetExpires(new DateTime());
|
||||
|
||||
//Save to DB
|
||||
$this->em->flush();
|
||||
|
|
|
@ -46,6 +46,7 @@ use App\Configuration\PermissionsConfiguration;
|
|||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Security\Interfaces\HasPermissionsInterface;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
|
@ -172,7 +173,7 @@ class PermissionResolver
|
|||
public function listOperationsForPermission(string $permission): array
|
||||
{
|
||||
if (!$this->isValidPermission($permission)) {
|
||||
throw new \InvalidArgumentException(sprintf('A permission with that name is not existing! Got %s.', $permission));
|
||||
throw new InvalidArgumentException(sprintf('A permission with that name is not existing! Got %s.', $permission));
|
||||
}
|
||||
$operations = $this->permission_structure['perms'][$permission]['operations'];
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ use Brick\Math\RoundingMode;
|
|||
use Doctrine\ORM\PersistentCollection;
|
||||
use Locale;
|
||||
|
||||
use function count;
|
||||
|
||||
class PricedetailHelper
|
||||
{
|
||||
protected $base_currency;
|
||||
|
@ -74,7 +76,7 @@ class PricedetailHelper
|
|||
foreach ($orderdetails as $orderdetail) {
|
||||
$pricedetails = $orderdetail->getPricedetails();
|
||||
//The orderdetail must have pricedetails, otherwise this will not work!
|
||||
if (0 === \count($pricedetails)) {
|
||||
if (0 === count($pricedetails)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -121,7 +123,7 @@ class PricedetailHelper
|
|||
foreach ($orderdetails as $orderdetail) {
|
||||
$pricedetails = $orderdetail->getPricedetails();
|
||||
//The orderdetail must have pricedetails, otherwise this will not work!
|
||||
if (0 === \count($pricedetails)) {
|
||||
if (0 === count($pricedetails)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ use App\Entity\Parts\Supplier;
|
|||
use App\Entity\PriceInformations\Currency;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class StatisticsHelper
|
||||
{
|
||||
|
@ -61,8 +64,8 @@ class StatisticsHelper
|
|||
/**
|
||||
* Returns the summed instocked over all parts (only parts without a measurement unit).
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getPartsInstockSum(): float
|
||||
{
|
||||
|
@ -72,8 +75,8 @@ class StatisticsHelper
|
|||
/**
|
||||
* Returns the number of all parts which have price informations.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getPartsCountWithPrice(): int
|
||||
{
|
||||
|
@ -98,7 +101,7 @@ class StatisticsHelper
|
|||
];
|
||||
|
||||
if (!isset($arr[$type])) {
|
||||
throw new \InvalidArgumentException('No count for the given type available!');
|
||||
throw new InvalidArgumentException('No count for the given type available!');
|
||||
}
|
||||
|
||||
/** @var EntityRepository $repo */
|
||||
|
@ -126,8 +129,8 @@ class StatisticsHelper
|
|||
/**
|
||||
* Gets the count of all external (only containing an URL) attachments.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getExternalAttachmentsCount(): int
|
||||
{
|
||||
|
@ -137,8 +140,8 @@ class StatisticsHelper
|
|||
/**
|
||||
* Gets the count of all attachments where the user uploaded an file.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
* @throws NonUniqueResultException
|
||||
*/
|
||||
public function getUserUploadedAttachmentsCount(): int
|
||||
{
|
||||
|
|
|
@ -42,6 +42,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\TFA;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* This class generates random backup codes for two factor authentication.
|
||||
*/
|
||||
|
@ -59,10 +62,10 @@ class BackupCodeGenerator
|
|||
public function __construct(int $code_length, int $code_count)
|
||||
{
|
||||
if ($code_length > 32) {
|
||||
throw new \RuntimeException('Backup code can have maximum 32 digits!');
|
||||
throw new RuntimeException('Backup code can have maximum 32 digits!');
|
||||
}
|
||||
if ($code_length < 6) {
|
||||
throw new \RuntimeException('Code must have at least 6 digits to ensure security!');
|
||||
throw new RuntimeException('Code must have at least 6 digits to ensure security!');
|
||||
}
|
||||
|
||||
$this->code_count = $code_count;
|
||||
|
@ -75,7 +78,7 @@ class BackupCodeGenerator
|
|||
*
|
||||
* @return string The generated backup code (e.g. 1f3870be2)
|
||||
*
|
||||
* @throws \Exception if no entropy source is available
|
||||
* @throws Exception if no entropy source is available
|
||||
*/
|
||||
public function generateSingleCode(): string
|
||||
{
|
||||
|
|
|
@ -46,6 +46,8 @@ use App\Entity\Parts\Part;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use function array_slice;
|
||||
|
||||
/**
|
||||
* A service related for searching for tags. Mostly useful for autocomplete reasons.
|
||||
*/
|
||||
|
@ -101,7 +103,7 @@ class TagFinder
|
|||
|
||||
$results = array_unique($results);
|
||||
//Limit the returned tag count to specified value.
|
||||
return \array_slice($results, 0, $options['return_limit']);
|
||||
return array_slice($results, 0, $options['return_limit']);
|
||||
}
|
||||
|
||||
protected function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
|
@ -59,10 +59,14 @@ use App\Services\EntityURLGenerator;
|
|||
use App\Services\MarkdownParser;
|
||||
use App\Services\UserCacheKeyGenerator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
use RecursiveIteratorIterator;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function count;
|
||||
|
||||
class TreeViewGenerator
|
||||
{
|
||||
protected $urlGenerator;
|
||||
|
@ -131,7 +135,7 @@ class TreeViewGenerator
|
|||
|
||||
$generic = $this->getGenericTree($class, $parent);
|
||||
$treeIterator = new TreeViewNodeIterator($generic);
|
||||
$recursiveIterator = new \RecursiveIteratorIterator($treeIterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$recursiveIterator = new RecursiveIteratorIterator($treeIterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||
foreach ($recursiveIterator as $item) {
|
||||
/** @var TreeViewNode $item */
|
||||
if (null !== $selectedElement && $item->getId() === $selectedElement->getID()) {
|
||||
|
@ -139,7 +143,7 @@ class TreeViewGenerator
|
|||
}
|
||||
|
||||
if (!empty($item->getNodes())) {
|
||||
$item->addTag((string) \count($item->getNodes()));
|
||||
$item->addTag((string) count($item->getNodes()));
|
||||
}
|
||||
|
||||
if (!empty($href_type) && null !== $item->getId()) {
|
||||
|
@ -218,10 +222,10 @@ class TreeViewGenerator
|
|||
public function getGenericTree(string $class, ?AbstractStructuralDBElement $parent = null): array
|
||||
{
|
||||
if (!is_a($class, AbstractNamedDBElement::class, true)) {
|
||||
throw new \InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
|
||||
throw new InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
|
||||
}
|
||||
if (null !== $parent && !is_a($parent, $class)) {
|
||||
throw new \InvalidArgumentException('$parent must be of the type $class!');
|
||||
throw new InvalidArgumentException('$parent must be of the type $class!');
|
||||
}
|
||||
|
||||
/** @var StructuralDBElementRepository $repo */
|
||||
|
|
|
@ -43,6 +43,7 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use Locale;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
|
@ -65,7 +66,7 @@ class UserCacheKeyGenerator
|
|||
*/
|
||||
public function generateKey(?User $user = null): string
|
||||
{
|
||||
$locale = \Locale::getDefault();
|
||||
$locale = Locale::getDefault();
|
||||
|
||||
//If no user was specified, use the currently used one.
|
||||
if (null === $user) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue