Fixed some deprecations.

This commit is contained in:
Jan Böhmer 2022-08-14 19:09:07 +02:00
parent 4fa8eef1bf
commit 5fd608f42a
59 changed files with 202 additions and 165 deletions

View file

@ -146,9 +146,9 @@ class CleanAttachmentsCommand extends Command
/**
* This function removes all empty folders inside $path. Taken from https://stackoverflow.com/a/1833681.
*
* @param string $path The path in which the empty folders should be deleted
* @param string $path The path in which the empty folders should be deleted
*/
protected function removeEmptySubFolders($path): bool
protected function removeEmptySubFolders(string $path): bool
{
$empty = true;
foreach (glob($path.DIRECTORY_SEPARATOR.'*') as $file) {

View file

@ -76,7 +76,7 @@ class ShowEventLogCommand extends Command
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

View file

@ -31,7 +31,7 @@ class UserListCommand extends Command
;
}
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

View file

@ -71,7 +71,7 @@ class ManufacturerController extends BaseAdminController
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper)
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper): \Symfony\Component\HttpFoundation\RedirectResponse
{
return $this->_delete($request, $entity, $recursionHelper);
}

View file

@ -59,6 +59,7 @@ use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
@ -200,7 +201,7 @@ class UserSettingsController extends AbstractController
*
* @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager)
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager, FormFactoryInterface $formFactory)
{
/** @var User */
$user = $this->getUser();
@ -330,7 +331,8 @@ class UserSettingsController extends AbstractController
return $this->redirectToRoute('user_settings');
}
$backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class, [
$backup_form = $formFactory->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class, [
'label' => 'tfa_backup.regenerate_codes',
'attr' => [
'class' => 'btn-danger',

View file

@ -66,6 +66,7 @@ class EntityColumn extends AbstractColumn
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
* @param mixed $value The single value of the column
* @return mixed
*/
public function normalize($value)
{
@ -73,7 +74,7 @@ class EntityColumn extends AbstractColumn
return $value;
}
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): self
{
parent::configureOptions($resolver);

View file

@ -28,12 +28,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class IconLinkColumn extends AbstractColumn
{
/**
* @param $value
* @return mixed
*/
public function normalize($value)
{
return $value;
}
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): self
{
parent::configureOptions($resolver);
$resolver->setDefaults([
@ -51,7 +55,7 @@ class IconLinkColumn extends AbstractColumn
return $this;
}
public function render($value, $context)
public function render($value, $context): string
{
$href = $this->getHref($value, $context);
$icon = $this->getIcon($value, $context);

View file

@ -55,7 +55,12 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
class LocaleDateTimeColumn extends AbstractColumn
{
public function normalize($value)
/**
* @param $value
* @return bool|mixed|string
* @throws \Exception
*/
public function normalize($value): string
{
if (null === $value) {
return $this->options['nullValue'];
@ -81,7 +86,7 @@ class LocaleDateTimeColumn extends AbstractColumn
return $formatter->format($value->getTimestamp());
}
protected function configureOptions(OptionsResolver $resolver)
protected function configureOptions(OptionsResolver $resolver): self
{
parent::configureOptions($resolver);

View file

@ -57,12 +57,16 @@ class LogEntryExtraColumn extends AbstractColumn
$this->formatter = $formatter;
}
/**
* @param $value
* @return mixed
*/
public function normalize($value)
{
return $value;
}
public function render($value, $context)
public function render($value, $context): string
{
return $this->formatter->format($context);
}

View file

@ -78,12 +78,16 @@ class LogEntryTargetColumn extends AbstractColumn
$this->translator = $translator;
}
/**
* @param $value
* @return mixed
*/
public function normalize($value)
{
return $value;
}
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): self
{
parent::configureOptions($resolver);
$resolver->setDefault('show_associated', true);
@ -92,7 +96,7 @@ class LogEntryTargetColumn extends AbstractColumn
return $this;
}
public function render($value, $context)
public function render($value, $context): string
{
if ($context instanceof UserNotAllowedLogEntry && $this->options['showAccessDeniedPath']) {
return htmlspecialchars($context->getPath());

View file

@ -58,6 +58,7 @@ class MarkdownColumn extends AbstractColumn
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
* @param mixed $value The single value of the column
* @return mixed
*/
public function normalize($value)
{

View file

@ -68,13 +68,14 @@ class PartAttachmentsColumn extends AbstractColumn
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
* @param mixed $value The single value of the column
* @return mixed
*/
public function normalize($value)
{
return $value;
}
public function render($value, $context)
public function render($value, $context): string
{
if (!$context instanceof Part) {
throw new RuntimeException('$context must be a Part object!');
@ -107,7 +108,7 @@ class PartAttachmentsColumn extends AbstractColumn
return $tmp;
}
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): self
{
parent::configureOptions($resolver);

View file

@ -42,12 +42,16 @@ class RevertLogColumn extends AbstractColumn
$this->security = $security;
}
/**
* @param $value
* @return mixed
*/
public function normalize($value)
{
return $value;
}
public function render($value, $context)
public function render($value, $context): string
{
if (
$context instanceof CollectionElementDeleted

View file

@ -58,6 +58,7 @@ class TagsColumn extends AbstractColumn
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
* @param mixed $value The single value of the column
* @return mixed
*/
public function normalize($value)
{
@ -68,7 +69,7 @@ class TagsColumn extends AbstractColumn
return explode(',', $value);
}
public function render($tags, $context)
public function render($tags, $context): string
{
$html = '';
$count = 10;

View file

@ -64,11 +64,11 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
/**
* Set the purge mode
*
* @param int $mode
* @param int $mode
*
* @return void
*/
public function setPurgeMode($mode)
public function setPurgeMode(int $mode): void
{
$this->purgeMode = $mode;
}
@ -78,13 +78,13 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
*
* @return int
*/
public function getPurgeMode()
public function getPurgeMode(): int
{
return $this->purgeMode;
}
/** @inheritDoc */
public function setEntityManager(EntityManagerInterface $em)
public function setEntityManager(EntityManagerInterface $em): void
{
$this->em = $em;
}
@ -94,13 +94,13 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
*
* @return EntityManagerInterface
*/
public function getObjectManager()
public function getObjectManager(): ?EntityManagerInterface
{
return $this->em;
}
/** @inheritDoc */
public function purge()
public function purge(): void
{
$classes = [];
@ -199,7 +199,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
*
* @return ClassMetadata[]
*/
private function getCommitOrder(EntityManagerInterface $em, array $classes)
private function getCommitOrder(EntityManagerInterface $em, array $classes): array
{
$sorter = new TopologicalSorter();
@ -258,7 +258,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
*
* @return array
*/
private function getAssociationTables(array $classes, AbstractPlatform $platform)
private function getAssociationTables(array $classes, AbstractPlatform $platform): array
{
$associationTables = [];

View file

@ -150,12 +150,12 @@ abstract class AbstractCompany extends AbstractPartsContainingDBElement
/**
* Get the link to the website of an article.
*
* @param string $partnr * NULL for returning the URL with a placeholder for the part number
* @param string|null $partnr * NULL for returning the URL with a placeholder for the part number
* * or the part number for returning the direct URL to the article
*
* @return string the link to the article
*/
public function getAutoProductUrl($partnr = null): string
public function getAutoProductUrl(string $partnr = null): string
{
if (is_string($partnr)) {
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);

View file

@ -120,11 +120,12 @@ class U2FKey implements TwoFactorKeyInterface
$this->counter = $data->counter;
}
public function getKeyHandle()
public function getKeyHandle(): string
{
return $this->keyHandle;
}
public function setKeyHandle($keyHandle): self
{
$this->keyHandle = $keyHandle;
@ -132,7 +133,7 @@ class U2FKey implements TwoFactorKeyInterface
return $this;
}
public function getPublicKey()
public function getPublicKey(): string
{
return $this->publicKey;
}
@ -144,7 +145,7 @@ class U2FKey implements TwoFactorKeyInterface
return $this;
}
public function getCertificate()
public function getCertificate(): string
{
return $this->certificate;
}
@ -156,7 +157,7 @@ class U2FKey implements TwoFactorKeyInterface
return $this;
}
public function getCounter()
public function getCounter(): int
{
return $this->counter;
}
@ -168,7 +169,7 @@ class U2FKey implements TwoFactorKeyInterface
return $this;
}
public function getName()
public function getName(): string
{
return $this->name;
}

View file

@ -213,7 +213,7 @@ class EventLoggerSubscriber implements EventSubscriber
return true;
}
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return[
Events::onFlush,

View file

@ -58,7 +58,7 @@ class LogAccessDeniedSubscriber implements EventSubscriberInterface
$this->logger->logAndFlush($log_entry);
}
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return ['kernel.exception' => 'onKernelException'];
}

View file

@ -102,7 +102,7 @@ class LogDBMigrationSubscriber implements EventSubscriber
}
}
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return [
Events::onMigrationsMigrated,

View file

@ -185,7 +185,7 @@ class AttachmentFormType extends AbstractType
]);
}
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'attachment';
}

View file

@ -72,7 +72,7 @@ final class PermissionsMapper implements DataMapperInterface
* @param mixed $viewData View data of the compound form being initialized
* @param FormInterface[]|Traversable $forms A list of {@link FormInterface} instances
*/
public function mapDataToForms($viewData, $forms)
public function mapDataToForms($viewData, $forms): void
{
foreach ($forms as $form) {
if ($this->inherit) {

View file

@ -33,12 +33,12 @@ class BigDecimalMoneyType extends AbstractType implements DataTransformerInterfa
$builder->addModelTransformer($this);
}
public function getParent()
public function getParent(): string
{
return MoneyType::class;
}
public function transform($value)
public function transform($value): ?string
{
if (null === $value) {
return null;
@ -51,7 +51,7 @@ class BigDecimalMoneyType extends AbstractType implements DataTransformerInterfa
return $value;
}
public function reverseTransform($value)
public function reverseTransform($value): ?BigDecimal
{
if (null === $value) {
return null;

View file

@ -33,12 +33,12 @@ class BigDecimalNumberType extends AbstractType implements DataTransformerInterf
$builder->addModelTransformer($this);
}
public function getParent()
public function getParent(): string
{
return NumberType::class;
}
public function transform($value)
public function transform($value): ?string
{
if (null === $value) {
return null;
@ -51,7 +51,7 @@ class BigDecimalNumberType extends AbstractType implements DataTransformerInterf
return $value;
}
public function reverseTransform($value)
public function reverseTransform($value): ?BigDecimal
{
if (null === $value) {
return null;

View file

@ -96,7 +96,7 @@ class MasterPictureAttachmentType extends AbstractType
$resolver->setAllowedValues('filter', ['', 'picture', '3d_model']);
}
public function getParent()
public function getParent(): string
{
return ChoiceType::class;
}

View file

@ -21,7 +21,7 @@ class RichTextEditorType extends AbstractType
}
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'rich_text_editor';
}
@ -33,7 +33,7 @@ class RichTextEditorType extends AbstractType
parent::finishView($view, $form, $options); // TODO: Change the autogenerated stub
}
protected function optionsToAttrArray(array $options)
protected function optionsToAttrArray(array $options): array
{
$tmp = [];
@ -49,7 +49,7 @@ class RichTextEditorType extends AbstractType
return $tmp;
}
public function getParent()
public function getParent(): string
{
return TextareaType::class;
}

View file

@ -176,7 +176,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
*/
public function mapDataToForms($viewData, $forms)
public function mapDataToForms($viewData, $forms): void
{
$forms = iterator_to_array($forms);

View file

@ -148,7 +148,7 @@ class StructuralEntityType extends AbstractType
parent::buildView($view, $form, $options);
}
public function getParent()
public function getParent(): string
{
return ChoiceType::class;
}

View file

@ -68,7 +68,7 @@ final class TriStateCheckboxType extends AbstractType implements DataTransformer
]);
}
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'tristate';
}

View file

@ -28,7 +28,7 @@ class BigDecimalType extends Type
{
public const BIG_DECIMAL = 'big_decimal';
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration);
}
@ -50,7 +50,7 @@ class BigDecimalType extends Type
/**
* @param BigDecimal|null $value
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if (null === $value) {
return null;
@ -59,12 +59,12 @@ class BigDecimalType extends Type
return (string) $value;
}
public function getName()
public function getName(): string
{
return self::BIG_DECIMAL;
}
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}

View file

@ -33,7 +33,7 @@ class LabelResponse extends Response
parent::__construct($content, $status, $headers);
}
public function setContent($content)
public function setContent($content): self
{
parent::setContent($content);
@ -43,7 +43,7 @@ class LabelResponse extends Response
return $this;
}
public function prepare(Request $request)
public function prepare(Request $request): self
{
parent::prepare($request);
@ -81,13 +81,13 @@ class LabelResponse extends Response
/**
* Sets the Content-Disposition header with the given filename.
*
* @param string $disposition ResponseHeaderBag::DISPOSITION_INLINE or ResponseHeaderBag::DISPOSITION_ATTACHMENT
* @param string $filename Optionally use this UTF-8 encoded filename instead of the real name of the file
* @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
* @param string $disposition ResponseHeaderBag::DISPOSITION_INLINE or ResponseHeaderBag::DISPOSITION_ATTACHMENT
* @param string $filename Optionally use this UTF-8 encoded filename instead of the real name of the file
* @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
*
* @return $this
*/
public function setContentDisposition($disposition, $filename, $filenameFallback = ''): self
public function setContentDisposition(string $disposition, string $filename, string $filenameFallback = ''): self
{
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
$encoding = mb_detect_encoding($filename, null, true) ?: '8bit';

View file

@ -94,7 +94,7 @@ final class TreeViewNodeState implements JsonSerializable
return $this;
}
public function jsonSerialize()
public function jsonSerialize(): array
{
$ret = [];
if (null !== $this->selected) {

View file

@ -56,7 +56,7 @@ class UTCDateTimeType extends DateTimeType
{
private static $utc_timezone;
public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if (!self::$utc_timezone) {
self::$utc_timezone = new DateTimeZone('UTC');
@ -69,7 +69,7 @@ class UTCDateTimeType extends DateTimeType
return parent::convertToDatabaseValue($value, $platform);
}
public function convertToPHPValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform): ?DateTime
{
if (!self::$utc_timezone) {
self::$utc_timezone = new DateTimeZone('UTC');

View file

@ -52,7 +52,7 @@ use App\Entity\UserSystem\User;
class LogEntryRepository extends DBElementRepository
{
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
//Emulate a target element criteria by splitting it manually in the needed criterias
if (isset($criteria['target']) && $criteria['target'] instanceof AbstractDBElement) {
@ -70,13 +70,13 @@ class LogEntryRepository extends DBElementRepository
* Find log entries associated with the given element (the history of the element).
*
* @param AbstractDBElement $element The element for which the history should be generated
* @param string $order By default newest entries are shown first. Change this to ASC to show oldest entries first.
* @param string $order By default newest entries are shown first. Change this to ASC to show oldest entries first.
* @param null $limit
* @param null $offset
*
* @return AbstractLogEntry[]
*/
public function getElementHistory(AbstractDBElement $element, $order = 'DESC', $limit = null, $offset = null): array
public function getElementHistory(AbstractDBElement $element, string $order = 'DESC', $limit = null, $offset = null): array
{
return $this->findBy(['element' => $element], ['timestamp' => $order], $limit, $offset);
}
@ -175,11 +175,11 @@ class LogEntryRepository extends DBElementRepository
/**
* Gets the last log entries ordered by timestamp.
*
* @param string $order
* @param string $order
* @param null $limit
* @param null $offset
*/
public function getLogsOrderedByTimestamp($order = 'DESC', $limit = null, $offset = null): array
public function getLogsOrderedByTimestamp(string $order = 'DESC', $limit = null, $offset = null): array
{
return $this->findBy([], ['timestamp' => $order], $limit, $offset);
}
@ -226,7 +226,7 @@ class LogEntryRepository extends DBElementRepository
return $this->getLastUser($element, ElementCreatedLogEntry::class);
}
protected function getLastUser(AbstractDBElement $element, string $class)
protected function getLastUser(AbstractDBElement $element, string $class): ?User
{
$qb = $this->createQueryBuilder('log');
$qb->select('log')

View file

@ -52,9 +52,9 @@ class AttachmentVoter extends ExtendedVoter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
return $this->resolver->inherit($user, 'parts_attachments', $attribute) ?? false;
}
@ -62,12 +62,12 @@ class AttachmentVoter extends ExtendedVoter
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
protected function supports($attribute, $subject)
protected function supports(string $attribute, $subject): bool
{
if (is_a($subject, Attachment::class, true)) {
return in_array($attribute, $this->resolver->listOperationsForPermission('parts_attachments'), false);

View file

@ -92,7 +92,7 @@ abstract class ExtendedVoter extends Voter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
abstract protected function voteOnUser($attribute, $subject, User $user): bool;
abstract protected function voteOnUser(string $attribute, $subject, User $user): bool;
}

View file

@ -51,9 +51,9 @@ class GroupVoter extends ExtendedVoter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
return $this->resolver->inherit($user, 'groups', $attribute) ?? false;
}
@ -61,12 +61,12 @@ class GroupVoter extends ExtendedVoter
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
protected function supports($attribute, $subject)
protected function supports(string $attribute, $subject): bool
{
if (is_a($subject, Group::class, true)) {
return $this->resolver->isValidOperation('groups', $attribute);

View file

@ -37,12 +37,12 @@ class LabelProfileVoter extends ExtendedVoter
'revert_element' => 'revert_element',
];
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false;
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if ($subject instanceof LabelProfile) {
if (!isset(self::MAPPING[$attribute])) {

View file

@ -49,7 +49,7 @@ class LogEntryVoter extends ExtendedVoter
{
public const ALLOWED_OPS = ['read', 'delete'];
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
if ('delete' === $attribute) {
return $this->resolver->inherit($user, 'system', 'delete_logs') ?? false;
@ -70,7 +70,7 @@ class LogEntryVoter extends ExtendedVoter
return false;
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if ($subject instanceof AbstractLogEntry) {
return in_array($subject, static::ALLOWED_OPS, true);

View file

@ -33,7 +33,7 @@ class OrderdetailVoter extends ExtendedVoter
*/
protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
if (in_array($attribute, self::PART_PERMS, true)) {
return $this->resolver->inherit($user, 'parts', $attribute) ?? false;
@ -42,7 +42,7 @@ class OrderdetailVoter extends ExtendedVoter
return $this->resolver->inherit($user, 'parts_orderdetails', $attribute) ?? false;
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if (is_a($subject, Orderdetail::class, true)) {
return in_array($attribute, array_merge(

View file

@ -33,7 +33,7 @@ class PartLotVoter extends ExtendedVoter
*/
protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
if (in_array($attribute, self::PART_PERMS, true)) {
return $this->resolver->inherit($user, 'parts', $attribute) ?? false;
@ -42,7 +42,7 @@ class PartLotVoter extends ExtendedVoter
return $this->resolver->inherit($user, 'parts_lots', $attribute) ?? false;
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if (is_a($subject, PartLot::class, true)) {
return in_array($attribute, array_merge(

View file

@ -54,7 +54,7 @@ class PartVoter extends ExtendedVoter
{
public const READ = 'read';
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if (is_a($subject, Part::class, true)) {
//Check if a sub permission should be checked -> $attribute has format name.edit
@ -71,7 +71,7 @@ class PartVoter extends ExtendedVoter
return false;
}
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
//Check for sub permissions
if (false !== strpos($attribute, '.')) {

View file

@ -55,9 +55,9 @@ class PermissionVoter extends ExtendedVoter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
$attribute = ltrim($attribute, '@');
[$perm, $op] = explode('.', $attribute);
@ -68,12 +68,12 @@ class PermissionVoter extends ExtendedVoter
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
protected function supports($attribute, $subject)
protected function supports(string $attribute, $subject): bool
{
//Check if the attribute has the form @permission.operation
if (preg_match('#^@\\w+\\.\\w+$#', $attribute)) {

View file

@ -33,7 +33,7 @@ class PricedetailVoter extends ExtendedVoter
*/
protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
if (in_array($attribute, self::PART_PERMS, true)) {
return $this->resolver->inherit($user, 'parts', $attribute) ?? false;
@ -42,7 +42,7 @@ class PricedetailVoter extends ExtendedVoter
return $this->resolver->inherit($user, 'parts_prices', $attribute) ?? false;
}
protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
if (is_a($subject, Pricedetail::class, true)) {
return in_array($attribute, array_merge(

View file

@ -72,12 +72,12 @@ class StructureVoter extends ExtendedVoter
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
protected function supports($attribute, $subject)
protected function supports(string $attribute, $subject): bool
{
if (is_object($subject) || is_string($subject)) {
$permission_name = $this->instanceToPermissionName($subject);
@ -121,9 +121,9 @@ class StructureVoter extends ExtendedVoter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
$permission_name = $this->instanceToPermissionName($subject);
//Just resolve the permission

View file

@ -50,12 +50,12 @@ class UserVoter extends ExtendedVoter
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
protected function supports($attribute, $subject)
protected function supports(string $attribute, $subject): bool
{
if (is_a($subject, User::class, true)) {
return in_array($attribute, array_merge(
@ -72,9 +72,9 @@ class UserVoter extends ExtendedVoter
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user.
*
* @param string $attribute
* @param string $attribute
*/
protected function voteOnUser($attribute, $subject, User $user): bool
protected function voteOnUser(string $attribute, $subject, User $user): bool
{
//Check if the checked user is the user itself
if (($subject instanceof User) && $subject->getID() === $user->getID() &&

View file

@ -163,11 +163,11 @@ class AttachmentManager
* Returns a human readable version of the attachment file size.
* For external attachments, null is returned.
*
* @param int $decimals The number of decimals numbers that should be printed
* @param int $decimals The number of decimals numbers that should be printed
*
* @return string|null A string like 1.3M
*/
public function getHumanFileSize(Attachment $attachment, $decimals = 2): ?string
public function getHumanFileSize(Attachment $attachment, int $decimals = 2): ?string
{
$bytes = $this->getFileSize($attachment);

View file

@ -48,7 +48,7 @@ use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
final class CustomEnvVarProcessor implements EnvVarProcessorInterface
{
public function getEnv($prefix, $name, Closure $getEnv)
public function getEnv($prefix, $name, Closure $getEnv): bool
{
if ('validMailDSN' === $prefix) {
try {

View file

@ -228,9 +228,9 @@ class EntityImporter
* This functions corrects the parent setting based on the children value of the parent.
*
* @param iterable $entities the list of entities that should be fixed
* @param AbstractStructuralDBElement|null $parent the parent, to which the entity should be set
* @param AbstractStructuralDBElement|null $parent the parent, to which the entity should be set
*/
protected function correctParentEntites(iterable $entities, $parent = null): void
protected function correctParentEntites(iterable $entities, AbstractStructuralDBElement $parent = null): void
{
foreach ($entities as $entity) {
/** @var AbstractStructuralDBElement $entity */

View file

@ -62,10 +62,10 @@ class MoneyFormatter
*
* @param string|float $value the value that should be formatted
* @param Currency|null $currency The currency that should be used for formatting. If null the global one is used
* @param int $decimals the number of decimals that should be shown
* @param int $decimals the number of decimals that should be shown
* @param bool $show_all_digits if set to true, all digits are shown, even if they are null
*/
public function format($value, ?Currency $currency = null, $decimals = 5, bool $show_all_digits = false): string
public function format($value, ?Currency $currency = null, int $decimals = 5, bool $show_all_digits = false): string
{
$iso_code = $this->base_currency;
if (null !== $currency && !empty($currency->getIsoCode())) {

View file

@ -62,10 +62,10 @@ class StructuralElementRecursionHelper
* $func has the signature function(StructuralDBElement $element) : void
* @param int $max_depth The maximum depth for which should be recursivly called. So if this is set to 5, after the
* 5th level the execution is stopped.
* @param bool $call_from_bottom If set to true the bottom elements (elements with high level) will be called first.
* @param bool $call_from_bottom If set to true the bottom elements (elements with high level) will be called first.
* Set to false if you want to call the top elements first.
*/
public function execute(AbstractStructuralDBElement $element, callable $func, int $max_depth = -1, $call_from_bottom = true): void
public function execute(AbstractStructuralDBElement $element, callable $func, int $max_depth = -1, bool $call_from_bottom = true): void
{
//Cancel if we reached our maximal allowed level. Must be zero because -1 is infinity levels
if (0 === $max_depth) {

View file

@ -103,9 +103,9 @@ final class PermissionExtractor implements ExtractorInterface
/**
* Sets the prefix that should be used for new found messages.
*
* @param string $prefix The prefix
* @param string $prefix The prefix
*/
public function setPrefix($prefix)
public function setPrefix(string $prefix): string
{
return '';
}

View file

@ -93,7 +93,7 @@ class AppExtension extends AbstractExtension
$this->translator = $translator;
}
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('entityURL', [$this, 'generateEntityURL']),
@ -108,7 +108,7 @@ class AppExtension extends AbstractExtension
];
}
public function getTests()
public function getTests(): array
{
return [
new TwigTest('instanceof', static function ($var, $instance) {
@ -117,7 +117,7 @@ class AppExtension extends AbstractExtension
];
}
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('generateTreeData', [$this, 'treeData']),

View file

@ -26,7 +26,7 @@ use Twig\TwigFilter;
class BarcodeExtension extends AbstractExtension
{
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('barcodeSVG', static function (string $content, string $type = 'QRCODE') {

View file

@ -38,7 +38,7 @@ class LastUserExtension extends AbstractExtension
$this->repo = $em->getRepository(AbstractLogEntry::class);
}
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction('getLastEditingUser', [$this->repo, 'getLastEditingUser']),

View file

@ -35,7 +35,7 @@ class BigDecimalGreaterThanValidator extends AbstractComparisonValidator
/**
* {@inheritdoc}
*/
protected function compareValues($value1, $value2)
protected function compareValues($value1, $value2): bool
{
if ($value1 instanceof BigDecimal) {
$value1 = (string) $value1;
@ -51,7 +51,7 @@ class BigDecimalGreaterThanValidator extends AbstractComparisonValidator
/**
* {@inheritdoc}
*/
protected function getErrorCode()
protected function getErrorCode(): ?string
{
return GreaterThan::TOO_LOW_ERROR;
}

View file

@ -35,7 +35,7 @@ class BigDecimalGreaterThenOrEqualValidator extends AbstractComparisonValidator
/**
* {@inheritdoc}
*/
protected function compareValues($value1, $value2)
protected function compareValues($value1, $value2): bool
{
if ($value1 instanceof BigDecimal) {
$value1 = (string) $value1;
@ -51,7 +51,7 @@ class BigDecimalGreaterThenOrEqualValidator extends AbstractComparisonValidator
/**
* {@inheritdoc}
*/
protected function getErrorCode()
protected function getErrorCode(): ?string
{
return GreaterThanOrEqual::TOO_LOW_ERROR;
}

View file

@ -52,7 +52,7 @@ use Symfony\Component\Validator\Constraint;
*/
class ValidPartLot extends Constraint
{
public function getTargets()
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}

View file

@ -49,61 +49,63 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentPathResolverTest extends WebTestCase
{
public static $media_path;
public static $footprint_path;
protected static $projectDir_orig;
protected static $projectDir;
protected $media_path;
protected $footprint_path;
protected $projectDir_orig;
protected $projectDir;
/**
* @var AmountFormatter
*/
protected static $service;
protected $service;
public function __construct($name = null, array $data = [], $dataName = '')
public function setUp(): void
{
parent::__construct($name, $data, $dataName);
self::bootKernel();
self::$projectDir_orig = realpath(self::$kernel->getProjectDir());
self::$projectDir = str_replace('\\', '/', self::$projectDir_orig);
self::$media_path = self::$projectDir.'/public/media';
self::$footprint_path = self::$projectDir.'/public/img/footprints';
}
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
parent::setUp();
//Get an service instance.
self::bootKernel();
self::$service = self::$container->get(AttachmentPathResolver::class);
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
$this->service = self::getContainer()->get(AttachmentPathResolver::class);
}
public function testParameterToAbsolutePath(): void
{
//If null is passed, null must be returned
$this->assertNull(self::$service->parameterToAbsolutePath(null));
$this->assertNull($this->service->parameterToAbsolutePath(null));
//Absolute path should be returned like they are (we use projectDir here, because we know that this dir exists)
$this->assertSame(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir));
$this->assertSame($this->projectDir_orig, $this->service->parameterToAbsolutePath($this->projectDir));
//Relative pathes should be resolved
$expected = str_replace('\\', '/', self::$projectDir_orig.DIRECTORY_SEPARATOR.'src');
$this->assertSame($expected, self::$service->parameterToAbsolutePath('src'));
$this->assertSame($expected, self::$service->parameterToAbsolutePath('./src'));
$expected = str_replace('\\', '/', $this->projectDir_orig.DIRECTORY_SEPARATOR.'src');
$this->assertSame($expected, $this->service->parameterToAbsolutePath('src'));
$this->assertSame($expected, $this->service->parameterToAbsolutePath('./src'));
//Invalid pathes should return null
$this->assertNull(self::$service->parameterToAbsolutePath('/this/path/does/not/exist'));
$this->assertNull(self::$service->parameterToAbsolutePath('/./this/one/too'));
$this->assertNull($this->service->parameterToAbsolutePath('/this/path/does/not/exist'));
$this->assertNull($this->service->parameterToAbsolutePath('/./this/one/too'));
}
public function placeholderDataProvider(): array
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
return [
['%FOOTPRINTS%/test/test.jpg', self::$footprint_path.'/test/test.jpg'],
['%FOOTPRINTS%/test/', self::$footprint_path.'/test/'],
['%MEDIA%/test', self::$media_path.'/test'],
['%MEDIA%', self::$media_path],
['%FOOTPRINTS%', self::$footprint_path],
['%FOOTPRINTS%/test/test.jpg', $this->footprint_path.'/test/test.jpg'],
['%FOOTPRINTS%/test/', $this->footprint_path.'/test/'],
['%MEDIA%/test', $this->media_path.'/test'],
['%MEDIA%', $this->media_path],
['%FOOTPRINTS%', $this->footprint_path],
//Footprints 3D are disabled
['%FOOTPRINTS_3D%', null],
//Check that invalid pathes return null
@ -120,18 +122,25 @@ class AttachmentPathResolverTest extends WebTestCase
public function realPathDataProvider(): array
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
return [
[self::$media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'],
[self::$media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
[$this->media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'],
[$this->media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
['/etc/passwd', null],
['C:\\not\\existing.txt', null],
//More then one placeholder is not allowed
[self::$footprint_path.'/test/'.self::$footprint_path, null],
[$this->footprint_path.'/test/'.$this->footprint_path, null],
//Path must begin with path
['/not/root'.self::$footprint_path, null],
['/not/root'.$this->footprint_path, null],
];
}
@ -140,7 +149,7 @@ class AttachmentPathResolverTest extends WebTestCase
*/
public function testPlaceholderToRealPath($param, $expected): void
{
$this->assertSame($expected, self::$service->placeholderToRealPath($param));
$this->assertSame($expected, $this->service->placeholderToRealPath($param));
}
/**
@ -148,6 +157,6 @@ class AttachmentPathResolverTest extends WebTestCase
*/
public function testRealPathToPlaceholder($param, $expected, $old_method = false): void
{
$this->assertSame($expected, self::$service->realPathToPlaceholder($param, $old_method));
$this->assertSame($expected, $this->service->realPathToPlaceholder($param, $old_method));
}
}