From e8771ea118350706c0a145f51d88c988d2a1333a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 18 Jun 2023 00:00:58 +0200 Subject: [PATCH] Fixed some more phpstan issues --- phpstan.neon | 12 +++++++++++- src/Command/CheckRequirementsCommand.php | 8 ++++---- src/Command/User/ConvertToSAMLUserCommand.php | 4 ++-- src/Command/User/UserListCommand.php | 4 ++-- src/Command/User/UsersPermissionsCommand.php | 2 +- src/Controller/AdminPages/BaseAdminController.php | 2 +- src/Controller/GroupController.php | 2 +- src/Controller/LogController.php | 2 +- src/Controller/PartController.php | 2 +- src/Controller/RedirectController.php | 2 +- src/Controller/UserController.php | 6 +++--- src/Controller/UserSettingsController.php | 4 ++-- .../Adapters/CustomFetchJoinORMAdapter.php | 4 ++-- src/DataTables/Column/EntityColumn.php | 7 +++++-- src/DataTables/Column/IconLinkColumn.php | 7 +++++-- src/DataTables/Column/LocaleDateTimeColumn.php | 3 +++ src/DataTables/Column/LogEntryExtraColumn.php | 2 +- src/DataTables/Column/LogEntryTargetColumn.php | 5 ++++- src/DataTables/Column/MarkdownColumn.php | 2 +- src/DataTables/Column/PartAttachmentsColumn.php | 5 ++++- src/DataTables/Column/RevertLogColumn.php | 2 +- src/DataTables/Column/RowClassColumn.php | 5 ++++- src/DataTables/Column/SIUnitNumberColumn.php | 3 +++ src/DataTables/Column/SelectColumn.php | 5 ++++- src/DataTables/Column/TagsColumn.php | 6 +++++- .../Constraints/Part/ParameterConstraint.php | 12 +++--------- src/DataTables/LogDataTable.php | 2 +- src/Doctrine/Types/BigDecimalType.php | 5 ++--- src/Entity/Attachments/Attachment.php | 6 +++--- src/Entity/Attachments/CurrencyAttachment.php | 2 ++ src/Entity/Attachments/FootprintAttachment.php | 2 ++ src/Entity/Attachments/GroupAttachment.php | 1 + src/Entity/Attachments/LabelAttachment.php | 1 + src/Entity/Attachments/ManufacturerAttachment.php | 1 + .../Attachments/MeasurementUnitAttachment.php | 1 + src/Entity/Attachments/PartAttachment.php | 1 + src/Entity/Attachments/ProjectAttachment.php | 1 + src/Entity/Attachments/StorelocationAttachment.php | 1 + src/Entity/Attachments/SupplierAttachment.php | 1 + src/Entity/Attachments/UserAttachment.php | 1 + .../Base/AbstractPartsContainingDBElement.php | 7 +++++++ src/Entity/Base/AbstractStructuralDBElement.php | 4 ++-- src/Entity/Parts/Part.php | 2 ++ src/Entity/Parts/PartLot.php | 6 +++--- src/Entity/Parts/PartTraits/InstockTrait.php | 2 +- src/Entity/ProjectSystem/ProjectBOMEntry.php | 7 ++----- src/Entity/UserSystem/U2FKey.php | 14 +++++++------- src/Entity/UserSystem/User.php | 2 +- src/Entity/UserSystem/WebauthnKey.php | 4 +++- src/Helpers/Projects/ProjectBuildRequest.php | 4 +--- .../AbstractPartsContainingRepository.php | 4 ++++ src/Repository/AttachmentRepository.php | 5 +++++ src/Repository/DBElementRepository.php | 6 +++++- src/Repository/LabelProfileRepository.php | 4 ++++ src/Repository/LogEntryRepository.php | 7 ++++++- src/Repository/NamedDBElementRepository.php | 4 +++- src/Repository/ParameterRepository.php | 7 +++++++ src/Repository/PartRepository.php | 7 +++++++ src/Repository/StructuralDBElementRepository.php | 10 ++++++++-- src/Repository/UserRepository.php | 1 + src/Security/EnsureSAMLUserForSAMLLoginChecker.php | 2 +- src/Security/Voter/AttachmentVoter.php | 2 +- src/Security/Voter/LogEntryVoter.php | 2 +- src/Security/Voter/PartLotVoter.php | 2 +- src/Security/Voter/UserVoter.php | 2 +- .../Attachments/AttachmentSubmitHandler.php | 2 +- src/Services/Attachments/FileTypeFilterTools.php | 4 ++-- src/Services/ElementTypeNameGenerator.php | 6 +++--- src/Services/EntityURLGenerator.php | 2 +- src/Services/LabelSystem/BarcodeGenerator.php | 1 - .../LabelSystem/LabelExampleElementsGenerator.php | 1 - src/Services/LogSystem/LogTargetHelper.php | 2 +- src/Services/ProjectSystem/ProjectBuildHelper.php | 2 +- .../UserSystem/PermissionPresetsHelper.php | 10 ++-------- .../UserSystem/PermissionSchemaUpdater.php | 6 ++---- .../Constraints/UrlOrBuiltinValidator.php | 2 +- .../Constraints/ValidPermissionValidator.php | 2 -- 77 files changed, 192 insertions(+), 109 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index e35c6d07..ca71762a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,13 +21,23 @@ parameters: checkUninitializedProperties: true + checkFunctionNameCase: true + + checkAlwaysTrueInstanceof: false + checkAlwaysTrueCheckTypeFunctionCall: false + checkAlwaysTrueStrictComparison: false + reportAlwaysTrueInLastCondition: false + + reportMaybesInPropertyPhpDocTypes: false + reportMaybesInMethodSignatures: false + strictRules: disallowedLooseComparison: false booleansInConditions: false uselessCast: false requireParentConstructorCall: true disallowedConstructs: false - overwriteVariablesWithLoop: true + overwriteVariablesWithLoop: false closureUsesThis: false matchingInheritedMethodNames: true numericOperandsInArithmeticOperators: true diff --git a/src/Command/CheckRequirementsCommand.php b/src/Command/CheckRequirementsCommand.php index 139be0e4..cc557bd1 100644 --- a/src/Command/CheckRequirementsCommand.php +++ b/src/Command/CheckRequirementsCommand.php @@ -121,7 +121,7 @@ class CheckRequirementsCommand extends Command } $db_drivers_count = 0; - if(!in_array('pdo_mysql', $extensions)) { + if(!in_array('pdo_mysql', $extensions, true)) { $io->error('pdo_mysql is not installed. You will not be able to use MySQL databases.'); } else { if (!$only_issues) { @@ -130,7 +130,7 @@ class CheckRequirementsCommand extends Command $db_drivers_count++; } - if(!in_array('pdo_sqlite', $extensions)) { + if(!in_array('pdo_sqlite', $extensions, true)) { $io->error('pdo_sqlite is not installed. You will not be able to use SQLite. databases'); } else { if (!$only_issues) { @@ -146,13 +146,13 @@ class CheckRequirementsCommand extends Command $io->error('You have no database drivers installed. You have to install at least one database driver!'); } - if (!in_array('curl', $extensions)) { + if (!in_array('curl', $extensions, true)) { $io->warning('curl extension is not installed. Install curl extension for better performance'); } elseif (!$only_issues) { $io->success('PHP extension curl is installed.'); } - $gd_installed = in_array('gd', $extensions); + $gd_installed = in_array('gd', $extensions, true); if (!$gd_installed) { $io->error('GD is not installed. GD is required for image processing.'); } elseif (!$only_issues) { diff --git a/src/Command/User/ConvertToSAMLUserCommand.php b/src/Command/User/ConvertToSAMLUserCommand.php index b023a1ba..98892ecd 100644 --- a/src/Command/User/ConvertToSAMLUserCommand.php +++ b/src/Command/User/ConvertToSAMLUserCommand.php @@ -82,7 +82,7 @@ class ConvertToSAMLUserCommand extends Command $io->confirm('You are going to convert a SAML user to a local user. This means, that the user can only login via the login form. ' . 'The permissions and groups settings of the user will remain unchanged. Do you really want to continue?'); - $user->setSAMLUser(false); + $user->setSamlUser(false); $user->setPassword(SamlUserFactory::SAML_PASSWORD_PLACEHOLDER); $this->entityManager->flush(); @@ -97,7 +97,7 @@ class ConvertToSAMLUserCommand extends Command $io->confirm('You are going to convert a local user to a SAML user. This means, that the user can only login via SAML afterwards. The password in the DB will be removed. ' . 'The permissions and groups settings of the user will remain unchanged. Do you really want to continue?'); - $user->setSAMLUser(true); + $user->setSamlUser(true); $user->setPassword(SamlUserFactory::SAML_PASSWORD_PLACEHOLDER); $this->entityManager->flush(); diff --git a/src/Command/User/UserListCommand.php b/src/Command/User/UserListCommand.php index ca56c994..11d50fbf 100644 --- a/src/Command/User/UserListCommand.php +++ b/src/Command/User/UserListCommand.php @@ -79,13 +79,13 @@ class UserListCommand extends Command foreach ($users as $user) { $table->addRow([ - $user->getId(), + $user->getID(), $user->getUsername(), $user->getFullName(), $user->getEmail(), $user->getGroup() instanceof Group ? $user->getGroup()->getName() . ' (ID: ' . $user->getGroup()->getID() . ')' : 'No group', $user->isDisabled() ? 'Yes' : 'No', - $user->isSAMLUser() ? 'SAML' : 'Local', + $user->isSamlUser() ? 'SAML' : 'Local', ]); } diff --git a/src/Command/User/UsersPermissionsCommand.php b/src/Command/User/UsersPermissionsCommand.php index b4bcd99a..021853bb 100644 --- a/src/Command/User/UsersPermissionsCommand.php +++ b/src/Command/User/UsersPermissionsCommand.php @@ -73,7 +73,7 @@ class UsersPermissionsCommand extends Command return Command::FAILURE; } - $io->note(sprintf('Found user %s with ID %d', $user->getFullName(true), $user->getId())); + $io->note(sprintf('Found user %s with ID %d', $user->getFullName(true), $user->getID())); $edit_mapping = $this->renderPermissionTable($output, $user, $inherit); diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index cf856e8f..a00dc1a6 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -402,7 +402,7 @@ abstract class BaseAdminController extends AbstractController { $this->denyAccessUnlessGranted('delete', $entity); - if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('delete'.$entity->getID(), $request->request->get('_token'))) { $entityManager = $this->entityManager; diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 645ef8f9..718f0eba 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -59,7 +59,7 @@ class GroupController extends BaseAdminController //Handle permissions presets if ($request->request->has('permission_preset')) { $this->denyAccessUnlessGranted('edit_permissions', $entity); - if ($this->isCsrfTokenValid('group'.$entity->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('group'.$entity->getID(), $request->request->get('_token'))) { $preset = $request->request->get('permission_preset'); $permissionPresetsHelper->applyPreset($entity, $preset); diff --git a/src/Controller/LogController.php b/src/Controller/LogController.php index d4d4272a..d906d964 100644 --- a/src/Controller/LogController.php +++ b/src/Controller/LogController.php @@ -113,7 +113,7 @@ class LogController extends AbstractController { $this->denyAccessUnlessGranted('delete', $logEntry); - if ($this->isCsrfTokenValid('delete'.$logEntry->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('delete'.$logEntry->getID(), $request->request->get('_token'))) { //Remove part $entityManager->remove($logEntry); //Flush changes diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 2083c340..62dbaf4e 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -183,7 +183,7 @@ class PartController extends AbstractController { $this->denyAccessUnlessGranted('delete', $part); - if ($this->isCsrfTokenValid('delete'.$part->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('delete'.$part->getID(), $request->request->get('_token'))) { $this->commentHelper->setMessage($request->request->get('log_comment', null)); diff --git a/src/Controller/RedirectController.php b/src/Controller/RedirectController.php index 40c2c051..b0af0119 100644 --- a/src/Controller/RedirectController.php +++ b/src/Controller/RedirectController.php @@ -83,6 +83,6 @@ class RedirectController extends AbstractController } //Check if the mod_rewrite module is loaded - return in_array('mod_rewrite', apache_get_modules(), false); + return in_array('mod_rewrite', apache_get_modules(), true); } } diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 9eb8cd23..9332b6d3 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -88,7 +88,7 @@ class UserController extends BaseAdminController if ($request->request->has('reset_2fa')) { //Check if the admin has the needed permissions $this->denyAccessUnlessGranted('set_password', $entity); - if ($this->isCsrfTokenValid('reset_2fa'.$entity->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('reset_2fa'.$entity->getID(), $request->request->get('_token'))) { //Disable Google authenticator $entity->setGoogleAuthenticatorSecret(null); $entity->setBackupCodes([]); @@ -96,7 +96,7 @@ class UserController extends BaseAdminController foreach ($entity->getLegacyU2FKeys() as $key) { $em->remove($key); } - foreach ($entity->getWebAuthnKeys() as $key) { + foreach ($entity->getWebauthnKeys() as $key) { $em->remove($key); } //Invalidate trusted devices @@ -115,7 +115,7 @@ class UserController extends BaseAdminController //Handle permissions presets if ($request->request->has('permission_preset')) { $this->denyAccessUnlessGranted('edit_permissions', $entity); - if ($this->isCsrfTokenValid('reset_2fa'.$entity->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('reset_2fa'.$entity->getID(), $request->request->get('_token'))) { $preset = $request->request->get('permission_preset'); $permissionPresetsHelper->applyPreset($entity, $preset); diff --git a/src/Controller/UserSettingsController.php b/src/Controller/UserSettingsController.php index 2597cfce..3805ad09 100644 --- a/src/Controller/UserSettingsController.php +++ b/src/Controller/UserSettingsController.php @@ -112,7 +112,7 @@ class UserSettingsController extends AbstractController throw new RuntimeException('You can not remove U2F keys from SAML users!'); } - if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('delete'.$user->getID(), $request->request->get('_token'))) { //Handle U2F key removal if ($request->request->has('key_id')) { $key_id = $request->request->get('key_id'); @@ -186,7 +186,7 @@ class UserSettingsController extends AbstractController throw new RuntimeException('You can not remove U2F keys from SAML users!'); } - if ($this->isCsrfTokenValid('devices_reset'.$user->getId(), $request->request->get('_token'))) { + if ($this->isCsrfTokenValid('devices_reset'.$user->getID(), $request->request->get('_token'))) { $user->invalidateTrustedDeviceTokens(); $entityManager->flush(); $this->addFlash('success', 'tfa_trustedDevice.invalidate.success'); diff --git a/src/DataTables/Adapters/CustomFetchJoinORMAdapter.php b/src/DataTables/Adapters/CustomFetchJoinORMAdapter.php index 0c4d4349..b296c4fa 100644 --- a/src/DataTables/Adapters/CustomFetchJoinORMAdapter.php +++ b/src/DataTables/Adapters/CustomFetchJoinORMAdapter.php @@ -39,7 +39,7 @@ use Omines\DataTablesBundle\Adapter\Doctrine\FetchJoinORMAdapter; */ class CustomFetchJoinORMAdapter extends FetchJoinORMAdapter { - public function getCount(QueryBuilder $queryBuilder, $identifier): ?int + public function getCount(QueryBuilder $queryBuilder, $identifier): int { $qb_without_group_by = clone $queryBuilder; @@ -50,6 +50,6 @@ class CustomFetchJoinORMAdapter extends FetchJoinORMAdapter $paginator = new Paginator($qb_without_group_by); - return $paginator->count(); + return $paginator->count() ?? 0; } } diff --git a/src/DataTables/Column/EntityColumn.php b/src/DataTables/Column/EntityColumn.php index 1636827a..35bdf547 100644 --- a/src/DataTables/Column/EntityColumn.php +++ b/src/DataTables/Column/EntityColumn.php @@ -41,13 +41,16 @@ class EntityColumn extends AbstractColumn * @param mixed $value The single value of the column * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { /** @var AbstractNamedDBElement $value */ return $value; } - public function configureOptions(OptionsResolver $resolver): self + /** + * @return $this + */ + public function configureOptions(OptionsResolver $resolver): static { parent::configureOptions($resolver); diff --git a/src/DataTables/Column/IconLinkColumn.php b/src/DataTables/Column/IconLinkColumn.php index d1034e56..6704cb4a 100644 --- a/src/DataTables/Column/IconLinkColumn.php +++ b/src/DataTables/Column/IconLinkColumn.php @@ -50,12 +50,15 @@ class IconLinkColumn extends AbstractColumn * @param $value * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } - public function configureOptions(OptionsResolver $resolver): self + /** + * @return $this + */ + public function configureOptions(OptionsResolver $resolver): static { parent::configureOptions($resolver); $resolver->setDefaults([ diff --git a/src/DataTables/Column/LocaleDateTimeColumn.php b/src/DataTables/Column/LocaleDateTimeColumn.php index 922f7eb3..ce8cccda 100644 --- a/src/DataTables/Column/LocaleDateTimeColumn.php +++ b/src/DataTables/Column/LocaleDateTimeColumn.php @@ -79,6 +79,9 @@ class LocaleDateTimeColumn extends AbstractColumn ); } + /** + * @return $this + */ protected function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); diff --git a/src/DataTables/Column/LogEntryExtraColumn.php b/src/DataTables/Column/LogEntryExtraColumn.php index 7ac5ccd0..e0281e42 100644 --- a/src/DataTables/Column/LogEntryExtraColumn.php +++ b/src/DataTables/Column/LogEntryExtraColumn.php @@ -36,7 +36,7 @@ class LogEntryExtraColumn extends AbstractColumn * @param $value * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } diff --git a/src/DataTables/Column/LogEntryTargetColumn.php b/src/DataTables/Column/LogEntryTargetColumn.php index 8a4e7fc5..272ff732 100644 --- a/src/DataTables/Column/LogEntryTargetColumn.php +++ b/src/DataTables/Column/LogEntryTargetColumn.php @@ -52,11 +52,14 @@ class LogEntryTargetColumn extends AbstractColumn * @param $value * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } + /** + * @return $this + */ public function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); diff --git a/src/DataTables/Column/MarkdownColumn.php b/src/DataTables/Column/MarkdownColumn.php index 23b89b49..9120c4c5 100644 --- a/src/DataTables/Column/MarkdownColumn.php +++ b/src/DataTables/Column/MarkdownColumn.php @@ -37,7 +37,7 @@ class MarkdownColumn extends AbstractColumn * @param mixed $value The single value of the column * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $this->markdown->markForRendering($value, true); } diff --git a/src/DataTables/Column/PartAttachmentsColumn.php b/src/DataTables/Column/PartAttachmentsColumn.php index a5715d17..0787a1e0 100644 --- a/src/DataTables/Column/PartAttachmentsColumn.php +++ b/src/DataTables/Column/PartAttachmentsColumn.php @@ -43,7 +43,7 @@ class PartAttachmentsColumn extends AbstractColumn * @param mixed $value The single value of the column * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } @@ -79,6 +79,9 @@ class PartAttachmentsColumn extends AbstractColumn return $tmp; } + /** + * @return $this + */ public function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); diff --git a/src/DataTables/Column/RevertLogColumn.php b/src/DataTables/Column/RevertLogColumn.php index a4d8eb3e..6ad365c1 100644 --- a/src/DataTables/Column/RevertLogColumn.php +++ b/src/DataTables/Column/RevertLogColumn.php @@ -59,7 +59,7 @@ class RevertLogColumn extends AbstractColumn * @param $value * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } diff --git a/src/DataTables/Column/RowClassColumn.php b/src/DataTables/Column/RowClassColumn.php index 1bfbecee..9b7aa0a0 100644 --- a/src/DataTables/Column/RowClassColumn.php +++ b/src/DataTables/Column/RowClassColumn.php @@ -29,6 +29,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class RowClassColumn extends AbstractColumn { + /** + * @return $this + */ public function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); @@ -44,7 +47,7 @@ class RowClassColumn extends AbstractColumn return $this; } - public function initialize(string $name, int $index, array $options, DataTable $dataTable) + public function initialize(string $name, int $index, array $options, DataTable $dataTable): void { //The field name is always "$$rowClass" as this is the name the frontend controller expects parent::initialize('$$rowClass', $index, $options, $dataTable); // TODO: Change the autogenerated stub diff --git a/src/DataTables/Column/SIUnitNumberColumn.php b/src/DataTables/Column/SIUnitNumberColumn.php index eec033dc..be50505d 100644 --- a/src/DataTables/Column/SIUnitNumberColumn.php +++ b/src/DataTables/Column/SIUnitNumberColumn.php @@ -32,6 +32,9 @@ class SIUnitNumberColumn extends AbstractColumn { } + /** + * @return $this + */ public function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); diff --git a/src/DataTables/Column/SelectColumn.php b/src/DataTables/Column/SelectColumn.php index 18d4193d..82003a62 100644 --- a/src/DataTables/Column/SelectColumn.php +++ b/src/DataTables/Column/SelectColumn.php @@ -30,6 +30,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class SelectColumn extends AbstractColumn { + /** + * @return $this + */ public function configureOptions(OptionsResolver $resolver): self { parent::configureOptions($resolver); @@ -48,7 +51,7 @@ class SelectColumn extends AbstractColumn /** * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { return $value; } diff --git a/src/DataTables/Column/TagsColumn.php b/src/DataTables/Column/TagsColumn.php index 9314e499..49ed89c7 100644 --- a/src/DataTables/Column/TagsColumn.php +++ b/src/DataTables/Column/TagsColumn.php @@ -37,7 +37,7 @@ class TagsColumn extends AbstractColumn * @param mixed $value The single value of the column * @return mixed */ - public function normalize($value) + public function normalize($value): mixed { if (empty($value)) { return []; @@ -48,6 +48,10 @@ class TagsColumn extends AbstractColumn public function render($tags, $context): string { + if (!is_iterable($tags)) { + throw new \LogicException('TagsColumn::render() expects an iterable'); + } + $html = ''; $count = 10; foreach ($tags as $tag) { diff --git a/src/DataTables/Filters/Constraints/Part/ParameterConstraint.php b/src/DataTables/Filters/Constraints/Part/ParameterConstraint.php index 00eba1c2..e68dd989 100644 --- a/src/DataTables/Filters/Constraints/Part/ParameterConstraint.php +++ b/src/DataTables/Filters/Constraints/Part/ParameterConstraint.php @@ -29,19 +29,13 @@ use Doctrine\ORM\QueryBuilder; class ParameterConstraint extends AbstractConstraint { - /** @var string */ - protected string $name; + protected string $name = ''; - /** @var string */ - protected string $symbol; + protected string $symbol = ''; - /** @var string */ - protected string $unit; + protected string $unit = ''; - /** @var TextConstraint */ protected TextConstraint $value_text; - - /** @var ParameterValueConstraint */ protected ParameterValueConstraint $value; /** @var string The alias to use for the subquery */ diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 3070e237..7b6ba834 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -123,7 +123,7 @@ class LogDataTable implements DataTableTypeInterface 'label' => 'log.timestamp', 'timeFormat' => 'medium', 'render' => fn(string $value, AbstractLogEntry $context): string => sprintf('%s', - $this->urlGenerator->generate('log_details', ['id' => $context->getId()]), + $this->urlGenerator->generate('log_details', ['id' => $context->getID()]), $value ) ]); diff --git a/src/Doctrine/Types/BigDecimalType.php b/src/Doctrine/Types/BigDecimalType.php index ccc1b491..a9f796dd 100644 --- a/src/Doctrine/Types/BigDecimalType.php +++ b/src/Doctrine/Types/BigDecimalType.php @@ -36,15 +36,14 @@ class BigDecimalType extends Type return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration); } - /** - * @param string|null $value - */ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?BigNumber { if (null === $value) { return null; } + + return BigDecimal::of($value); } diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 270e3c5b..eb931609 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -242,7 +242,8 @@ abstract class Attachment extends AbstractNamedDBElement /** * Get the element, associated with this Attachment (for example a "Part" object). * - * @return AttachmentContainingDBElement the associated Element + * @return AttachmentContainingDBElement|null the associated Element + * @phpstan-return T|null */ public function getElement(): ?AttachmentContainingDBElement { @@ -360,7 +361,6 @@ abstract class Attachment extends AbstractNamedDBElement /** * Sets the element that is associated with this attachment. - * * @return $this */ public function setElement(AttachmentContainingDBElement $element): self @@ -437,7 +437,7 @@ abstract class Attachment extends AbstractNamedDBElement $tmp = explode('/', $path); //Builtins must have a %PLACEHOLDER% construction - return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false); + return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, true); } /** diff --git a/src/Entity/Attachments/CurrencyAttachment.php b/src/Entity/Attachments/CurrencyAttachment.php index 419be619..292da013 100644 --- a/src/Entity/Attachments/CurrencyAttachment.php +++ b/src/Entity/Attachments/CurrencyAttachment.php @@ -28,12 +28,14 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a currency element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] class CurrencyAttachment extends Attachment { final public const ALLOWED_ELEMENT_CLASS = Currency::class; + /** * @var Currency|null the element this attachment is associated with */ diff --git a/src/Entity/Attachments/FootprintAttachment.php b/src/Entity/Attachments/FootprintAttachment.php index 3ac5ec8e..4d9b7caa 100644 --- a/src/Entity/Attachments/FootprintAttachment.php +++ b/src/Entity/Attachments/FootprintAttachment.php @@ -28,12 +28,14 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a footprint element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] class FootprintAttachment extends Attachment { final public const ALLOWED_ELEMENT_CLASS = Footprint::class; + /** * @var Footprint|null the element this attachment is associated with */ diff --git a/src/Entity/Attachments/GroupAttachment.php b/src/Entity/Attachments/GroupAttachment.php index a6558dfa..269e5b7d 100644 --- a/src/Entity/Attachments/GroupAttachment.php +++ b/src/Entity/Attachments/GroupAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a Group element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/LabelAttachment.php b/src/Entity/Attachments/LabelAttachment.php index 7616194c..5bf18969 100644 --- a/src/Entity/Attachments/LabelAttachment.php +++ b/src/Entity/Attachments/LabelAttachment.php @@ -47,6 +47,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * A attachment attached to a user element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/ManufacturerAttachment.php b/src/Entity/Attachments/ManufacturerAttachment.php index 65ac461c..cdbd7807 100644 --- a/src/Entity/Attachments/ManufacturerAttachment.php +++ b/src/Entity/Attachments/ManufacturerAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a manufacturer element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/MeasurementUnitAttachment.php b/src/Entity/Attachments/MeasurementUnitAttachment.php index d79b40a7..58467f86 100644 --- a/src/Entity/Attachments/MeasurementUnitAttachment.php +++ b/src/Entity/Attachments/MeasurementUnitAttachment.php @@ -29,6 +29,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a measurement unit element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/PartAttachment.php b/src/Entity/Attachments/PartAttachment.php index 54f12180..f9ca43b3 100644 --- a/src/Entity/Attachments/PartAttachment.php +++ b/src/Entity/Attachments/PartAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * A attachment attached to a part element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/ProjectAttachment.php b/src/Entity/Attachments/ProjectAttachment.php index 76c77bc2..84b0ac4c 100644 --- a/src/Entity/Attachments/ProjectAttachment.php +++ b/src/Entity/Attachments/ProjectAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * A attachment attached to a device element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/StorelocationAttachment.php b/src/Entity/Attachments/StorelocationAttachment.php index 3831630c..7772269d 100644 --- a/src/Entity/Attachments/StorelocationAttachment.php +++ b/src/Entity/Attachments/StorelocationAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a measurement unit element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/SupplierAttachment.php b/src/Entity/Attachments/SupplierAttachment.php index deba7480..7afa8282 100644 --- a/src/Entity/Attachments/SupplierAttachment.php +++ b/src/Entity/Attachments/SupplierAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * A attachment attached to a supplier element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Attachments/UserAttachment.php b/src/Entity/Attachments/UserAttachment.php index 8d8c2e04..fef36eb5 100644 --- a/src/Entity/Attachments/UserAttachment.php +++ b/src/Entity/Attachments/UserAttachment.php @@ -28,6 +28,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * An attachment attached to a user element. + * @extends Attachment */ #[UniqueEntity(['name', 'attachment_type', 'element'])] #[ORM\Entity] diff --git a/src/Entity/Base/AbstractPartsContainingDBElement.php b/src/Entity/Base/AbstractPartsContainingDBElement.php index 108d3bbd..5d25283e 100644 --- a/src/Entity/Base/AbstractPartsContainingDBElement.php +++ b/src/Entity/Base/AbstractPartsContainingDBElement.php @@ -27,6 +27,7 @@ use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\ParametersTrait; use App\Repository\AbstractPartsContainingRepository; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; @@ -41,4 +42,10 @@ abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElem { #[Groups(['full'])] protected Collection $parameters; + + public function __construct() + { + parent::__construct(); + $this->parameters = new ArrayCollection(); + } } diff --git a/src/Entity/Base/AbstractStructuralDBElement.php b/src/Entity/Base/AbstractStructuralDBElement.php index 6f8378ca..a7474330 100644 --- a/src/Entity/Base/AbstractStructuralDBElement.php +++ b/src/Entity/Base/AbstractStructuralDBElement.php @@ -195,7 +195,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement */ public function isRoot(): bool { - return !$this->parent instanceof \App\Entity\Base\AbstractStructuralDBElement; + return $this->parent === null; } /****************************************************************************** @@ -207,7 +207,7 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement /** * Get the parent of this element. * - * @return AbstractStructuralDBElement|null The parent element. Null if this element, does not have a parent. + * @return static|null The parent element. Null if this element, does not have a parent. */ public function getParent(): ?self { diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 04432f89..63f4dce4 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -50,6 +50,8 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; * The class properties are split over various traits in directory PartTraits. * Otherwise, this class would be too big, to be maintained. * @see \App\Tests\Entity\Parts\PartTest + * @extends AttachmentContainingDBElement + * @template-use ParametersTrait */ #[UniqueEntity(fields: ['ipn'], message: 'part.ipn.must_be_unique')] #[ORM\Entity(repositoryClass: PartRepository::class)] diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 04cc726d..f52f8984 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -107,12 +107,12 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named protected bool $needs_refill = false; /** - * @var Part The part that is stored in this lot + * @var Part|null The part that is stored in this lot */ #[Assert\NotNull] #[ORM\ManyToOne(targetEntity: Part::class, inversedBy: 'partLots')] #[ORM\JoinColumn(name: 'id_part', nullable: false, onDelete: 'CASCADE')] - protected Part $part; + protected ?Part $part = null; /** * @var User|null The owner of this part lot @@ -226,7 +226,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named /** * Return the part that is stored in this part lot. */ - public function getPart(): Part + public function getPart(): ?Part { return $this->part; } diff --git a/src/Entity/Parts/PartTraits/InstockTrait.php b/src/Entity/Parts/PartTraits/InstockTrait.php index 23168fd3..18295720 100644 --- a/src/Entity/Parts/PartTraits/InstockTrait.php +++ b/src/Entity/Parts/PartTraits/InstockTrait.php @@ -188,7 +188,7 @@ trait InstockTrait $sum = 0; foreach ($this->getPartLots() as $lot) { //Don't use the in stock value, if it is unknown - if ($lot->isInstockUnknown() || $lot->isExpired() ?? false) { + if ($lot->isInstockUnknown() || ($lot->isExpired() ?? false)) { continue; } diff --git a/src/Entity/ProjectSystem/ProjectBOMEntry.php b/src/Entity/ProjectSystem/ProjectBOMEntry.php index af8b48c1..af974b5f 100644 --- a/src/Entity/ProjectSystem/ProjectBOMEntry.php +++ b/src/Entity/ProjectSystem/ProjectBOMEntry.php @@ -47,12 +47,9 @@ class ProjectBOMEntry extends AbstractDBElement { use TimestampTrait; - /** - * @var float - */ #[Assert\Positive] #[ORM\Column(type: Types::FLOAT, name: 'quantity')] - protected float $quantity; + protected float $quantity = 1.0; /** * @var string A comma separated list of the names, where this parts should be placed @@ -71,7 +68,7 @@ class ProjectBOMEntry extends AbstractDBElement * @var string An optional comment for this BOM entry */ #[ORM\Column(type: Types::TEXT)] - protected string $comment; + protected string $comment = ''; /** * @var Project|null diff --git a/src/Entity/UserSystem/U2FKey.php b/src/Entity/UserSystem/U2FKey.php index 5cf5b7da..b74cd8db 100644 --- a/src/Entity/UserSystem/U2FKey.php +++ b/src/Entity/UserSystem/U2FKey.php @@ -43,25 +43,25 @@ class U2FKey implements LegacyU2FKeyInterface * @var string **/ #[ORM\Column(type: Types::STRING, length: 128)] - public string $keyHandle; + public string $keyHandle = ''; /** * @var string **/ #[ORM\Column(type: Types::STRING)] - public string $publicKey; + public string $publicKey = ''; /** * @var string **/ #[ORM\Column(type: Types::TEXT)] - public string $certificate; + public string $certificate = ''; /** - * @var int + * @var string **/ #[ORM\Column(type: Types::STRING)] - public int $counter; + public string $counter = '0'; #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] @@ -72,7 +72,7 @@ class U2FKey implements LegacyU2FKeyInterface * @var string **/ #[ORM\Column(type: Types::STRING)] - protected string $name; + protected string $name = ''; #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'u2fKeys')] protected ?User $user = null; @@ -114,7 +114,7 @@ class U2FKey implements LegacyU2FKeyInterface return $this; } - public function getCounter(): int + public function getCounter(): string { return $this->counter; } diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index da6a240f..aecff6a6 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -900,7 +900,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe { return new PublicKeyCredentialUserEntity( $this->getUsername(), - (string) $this->getId(), + (string) $this->getID(), $this->getFullName(), ); } diff --git a/src/Entity/UserSystem/WebauthnKey.php b/src/Entity/UserSystem/WebauthnKey.php index 3acc6ba8..ee467bc3 100644 --- a/src/Entity/UserSystem/WebauthnKey.php +++ b/src/Entity/UserSystem/WebauthnKey.php @@ -25,6 +25,7 @@ namespace App\Entity\UserSystem; use Doctrine\DBAL\Types\Types; use App\Entity\Base\TimestampTrait; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints\NotBlank; use Webauthn\PublicKeyCredentialSource as BasePublicKeyCredentialSource; #[ORM\Entity] @@ -40,7 +41,8 @@ class WebauthnKey extends BasePublicKeyCredentialSource protected int $id; #[ORM\Column(type: Types::STRING)] - protected string $name; + #[NotBlank] + protected string $name = ''; #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'webauthn_keys')] protected ?User $user = null; diff --git a/src/Helpers/Projects/ProjectBuildRequest.php b/src/Helpers/Projects/ProjectBuildRequest.php index c1c3c66f..36035744 100644 --- a/src/Helpers/Projects/ProjectBuildRequest.php +++ b/src/Helpers/Projects/ProjectBuildRequest.php @@ -174,10 +174,8 @@ final class ProjectBuildRequest { if ($lot instanceof PartLot) { $lot_id = $lot->getID(); - } elseif (is_int($lot)) { + } else { // Then it must be an int $lot_id = $lot; - } else { - throw new \InvalidArgumentException('The given lot must be an instance of PartLot or an ID of a PartLot!'); } if (! array_key_exists($lot_id, $this->withdraw_amounts)) { diff --git a/src/Repository/AbstractPartsContainingRepository.php b/src/Repository/AbstractPartsContainingRepository.php index cbfdee6a..3a389610 100644 --- a/src/Repository/AbstractPartsContainingRepository.php +++ b/src/Repository/AbstractPartsContainingRepository.php @@ -27,6 +27,10 @@ use App\Entity\Base\PartsContainingRepositoryInterface; use App\Entity\Parts\Part; use InvalidArgumentException; +/** + * @template TEntityClass of AbstractPartsContainingDBElement + * @extends StructuralDBElementRepository + */ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepository implements PartsContainingRepositoryInterface { /** @var int The maximum number of levels for which we can recurse before throwing an error */ diff --git a/src/Repository/AttachmentRepository.php b/src/Repository/AttachmentRepository.php index 69842352..240ab058 100644 --- a/src/Repository/AttachmentRepository.php +++ b/src/Repository/AttachmentRepository.php @@ -41,9 +41,14 @@ declare(strict_types=1); namespace App\Repository; +use App\Entity\Attachments\Attachment; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; +/** + * @template TEntityClass of Attachment + * @extends DBElementRepository + */ class AttachmentRepository extends DBElementRepository { /** diff --git a/src/Repository/DBElementRepository.php b/src/Repository/DBElementRepository.php index 3c626df0..fd410e3d 100644 --- a/src/Repository/DBElementRepository.php +++ b/src/Repository/DBElementRepository.php @@ -45,6 +45,10 @@ use App\Entity\Base\AbstractDBElement; use Doctrine\ORM\EntityRepository; use ReflectionClass; +/** + * @template TEntityClass of AbstractDBElement + * @extends EntityRepository + */ class DBElementRepository extends EntityRepository { /** @@ -53,7 +57,7 @@ class DBElementRepository extends EntityRepository * * @param AbstractDBElement $element The element whose ID should be changed * @phpstan-param TEntityClass $element - * @param int $new_id The new ID + * @param int $new_id The new ID */ public function changeID(AbstractDBElement $element, int $new_id): void { diff --git a/src/Repository/LabelProfileRepository.php b/src/Repository/LabelProfileRepository.php index 1f8ac4fe..9fa5d3cc 100644 --- a/src/Repository/LabelProfileRepository.php +++ b/src/Repository/LabelProfileRepository.php @@ -47,6 +47,10 @@ use App\Entity\LabelSystem\LabelSupportedElement; use App\Helpers\Trees\TreeViewNode; use InvalidArgumentException; +/** + * @template TEntityClass of LabelProfile + * @extends NamedDBElementRepository + */ class LabelProfileRepository extends NamedDBElementRepository { /** diff --git a/src/Repository/LogEntryRepository.php b/src/Repository/LogEntryRepository.php index 770e6cd6..b50c5204 100644 --- a/src/Repository/LogEntryRepository.php +++ b/src/Repository/LogEntryRepository.php @@ -32,6 +32,10 @@ use App\Entity\UserSystem\User; use DateTime; use RuntimeException; +/** + * @template TEntityClass of AbstractLogEntry + * @extends DBElementRepository + */ class LogEntryRepository extends DBElementRepository { public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array @@ -60,7 +64,8 @@ class LogEntryRepository extends DBElementRepository */ public function getElementHistory(AbstractDBElement $element, string $order = 'DESC', ?int $limit = null, ?int $offset = null): array { - return $this->findBy(['element' => $element], ['timestamp' => $order], $limit, $offset); + //@phpstan-ignore-next-line Target is parsed dynamically in findBy + return $this->findBy(['target' => $element], ['timestamp' => $order], $limit, $offset); } /** diff --git a/src/Repository/NamedDBElementRepository.php b/src/Repository/NamedDBElementRepository.php index 2168d92d..772cc164 100644 --- a/src/Repository/NamedDBElementRepository.php +++ b/src/Repository/NamedDBElementRepository.php @@ -27,7 +27,8 @@ use App\Entity\UserSystem\User; use App\Helpers\Trees\TreeViewNode; /** - * @see \App\Tests\Repository\NamedDBElementRepositoryTest + * @template TEntityClass of AbstractNamedDBElement + * @extends DBElementRepository */ class NamedDBElementRepository extends DBElementRepository { @@ -66,6 +67,7 @@ class NamedDBElementRepository extends DBElementRepository /** * Returns the list of all nodes to use in a select box. * @return AbstractNamedDBElement[] + * @phpstan-return array */ public function toNodesList(): array { diff --git a/src/Repository/ParameterRepository.php b/src/Repository/ParameterRepository.php index 7c978bad..a837435e 100644 --- a/src/Repository/ParameterRepository.php +++ b/src/Repository/ParameterRepository.php @@ -22,12 +22,19 @@ declare(strict_types=1); */ namespace App\Repository; +use App\Entity\Parameters\AbstractParameter; + +/** + * @template TEntityClass of AbstractParameter + * @extends DBElementRepository + */ class ParameterRepository extends DBElementRepository { /** * Find parameters using a parameter name * @param string $name The name to search for * @param bool $exact True, if only exact names should match. False, if the name just needs to be contained in the parameter name + * @phpstan-return array */ public function autocompleteParamName(string $name, bool $exact = false, int $max_results = 50): array { diff --git a/src/Repository/PartRepository.php b/src/Repository/PartRepository.php index fff8461a..3ab3ed31 100644 --- a/src/Repository/PartRepository.php +++ b/src/Repository/PartRepository.php @@ -22,11 +22,15 @@ declare(strict_types=1); namespace App\Repository; +use App\Entity\Parts\Part; use App\Entity\Parts\PartLot; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; use Doctrine\ORM\QueryBuilder; +/** + * @extends NamedDBElementRepository + */ class PartRepository extends NamedDBElementRepository { /** @@ -67,6 +71,9 @@ class PartRepository extends NamedDBElementRepository return (int) ($query->getSingleScalarResult() ?? 0); } + /** + * @return Part[] + */ public function autocompleteSearch(string $query, int $max_limits = 50): array { $qb = $this->createQueryBuilder('part'); diff --git a/src/Repository/StructuralDBElementRepository.php b/src/Repository/StructuralDBElementRepository.php index 04da15ac..c1882bda 100644 --- a/src/Repository/StructuralDBElementRepository.php +++ b/src/Repository/StructuralDBElementRepository.php @@ -29,6 +29,8 @@ use RecursiveIteratorIterator; /** * @see \App\Tests\Repository\StructuralDBElementRepositoryTest + * @template TEntityClass of AbstractStructuralDBElement + * @extends NamedDBElementRepository */ class StructuralDBElementRepository extends NamedDBElementRepository { @@ -52,7 +54,8 @@ class StructuralDBElementRepository extends NamedDBElementRepository * Gets a tree of TreeViewNode elements. The root elements has $parent as parent. * The treeview is generic, that means the href are null and ID values are set. * - * @param AbstractStructuralDBElement|null $parent the parent the root elements should have + * @param AbstractStructuralDBElement|null $parent the parent the root elements should have + * @phpstan-param TEntityClass|null $parent * * @return TreeViewNode[] */ @@ -78,8 +81,9 @@ class StructuralDBElementRepository extends NamedDBElementRepository * Gets a flattened hierarchical tree. Useful for generating option lists. * * @param AbstractStructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root - * + * @phpstan-param TEntityClass|null $parent * @return AbstractStructuralDBElement[] a flattened list containing the tree elements + * @phpstan-return array */ public function toNodesList(?AbstractStructuralDBElement $parent = null): array { @@ -104,6 +108,7 @@ class StructuralDBElementRepository extends NamedDBElementRepository * This function will try to use existing elements, if they are already in the database. If not, they will be created. * An array of the created elements will be returned, with the last element being the deepest element. * @return AbstractStructuralDBElement[] + * @phpstan-return array */ public function getNewEntityFromPath(string $path, string $separator = '->'): array { @@ -156,6 +161,7 @@ class StructuralDBElementRepository extends NamedDBElementRepository * An array of the created elements will be returned, with the last element being the deepest element. * If no element was found, an empty array will be returned. * @return AbstractStructuralDBElement[] + * @phpstan-return array */ public function getEntityByPath(string $path, string $separator = '->'): array { diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 95426775..f1e738d0 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -33,6 +33,7 @@ use Symfony\Component\Security\Core\User\UserInterface; * @method User|null findOneBy(array $criteria, array $orderBy = null) * @method User[] findAll() * @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + * @extends NamedDBElementRepository */ final class UserRepository extends NamedDBElementRepository implements PasswordUpgraderInterface { diff --git a/src/Security/EnsureSAMLUserForSAMLLoginChecker.php b/src/Security/EnsureSAMLUserForSAMLLoginChecker.php index f230cf71..7b540984 100644 --- a/src/Security/EnsureSAMLUserForSAMLLoginChecker.php +++ b/src/Security/EnsureSAMLUserForSAMLLoginChecker.php @@ -52,7 +52,7 @@ class EnsureSAMLUserForSAMLLoginChecker implements EventSubscriberInterface //If we are using SAML, we need to check that the user is a SAML user. if ($token instanceof SamlToken) { - if ($user instanceof User && !$user->isSAMLUser()) { + if ($user instanceof User && !$user->isSamlUser()) { throw new CustomUserMessageAccountStatusException($this->translator->trans('saml.error.cannot_login_local_user_per_saml', [], 'security')); } } elseif ($user instanceof User && $user->isSamlUser()) { diff --git a/src/Security/Voter/AttachmentVoter.php b/src/Security/Voter/AttachmentVoter.php index b482a1f3..0b32188c 100644 --- a/src/Security/Voter/AttachmentVoter.php +++ b/src/Security/Voter/AttachmentVoter.php @@ -110,7 +110,7 @@ class AttachmentVoter extends ExtendedVoter $param = 'parts'; } else { - throw new RuntimeException('Encountered unknown Parameter type: ' . (is_object($subject) ? $subject::class : $subject)); + throw new RuntimeException('Encountered unknown Parameter type: ' . $subject); } return $this->resolver->inherit($user, $param, $this->mapOperation($attribute)) ?? false; diff --git a/src/Security/Voter/LogEntryVoter.php b/src/Security/Voter/LogEntryVoter.php index 4ffecc5a..20c34863 100644 --- a/src/Security/Voter/LogEntryVoter.php +++ b/src/Security/Voter/LogEntryVoter.php @@ -63,7 +63,7 @@ class LogEntryVoter extends ExtendedVoter //To view details of a element related log entry, the user needs to be able to view the history of this entity type $targetClass = $subject->getTargetClass(); if (null !== $targetClass) { - return $this->security->isGranted('show_history', $targetClass) ?? false; + return $this->security->isGranted('show_history', $targetClass); } //In other cases, this behaves like the read permission diff --git a/src/Security/Voter/PartLotVoter.php b/src/Security/Voter/PartLotVoter.php index fbdb5ad1..c9ddb89e 100644 --- a/src/Security/Voter/PartLotVoter.php +++ b/src/Security/Voter/PartLotVoter.php @@ -63,7 +63,7 @@ class PartLotVoter extends ExtendedVoter throw new \RuntimeException('This voter can only handle PartLot objects!'); } - if (in_array($attribute, ['withdraw', 'add', 'move'])) + if (in_array($attribute, ['withdraw', 'add', 'move'], true)) { $base_permission = $this->resolver->inherit($user, 'parts_stock', $attribute) ?? false; diff --git a/src/Security/Voter/UserVoter.php b/src/Security/Voter/UserVoter.php index 5e34b8cc..e98e1701 100644 --- a/src/Security/Voter/UserVoter.php +++ b/src/Security/Voter/UserVoter.php @@ -44,7 +44,7 @@ class UserVoter extends ExtendedVoter $this->resolver->listOperationsForPermission('self'), ['info'] ), - false + true ); } diff --git a/src/Services/Attachments/AttachmentSubmitHandler.php b/src/Services/Attachments/AttachmentSubmitHandler.php index d422649e..b8b15907 100644 --- a/src/Services/Attachments/AttachmentSubmitHandler.php +++ b/src/Services/Attachments/AttachmentSubmitHandler.php @@ -220,7 +220,7 @@ class AttachmentSubmitHandler //Check if the extension is blacklisted and replace the file extension with txt if needed - if(in_array($ext, self::BLACKLISTED_EXTENSIONS)) { + if(in_array($ext, self::BLACKLISTED_EXTENSIONS, true)) { $new_path = $this->generateAttachmentPath($attachment, $attachment->isSecure()) .DIRECTORY_SEPARATOR.$this->generateAttachmentFilename($attachment, 'txt'); diff --git a/src/Services/Attachments/FileTypeFilterTools.php b/src/Services/Attachments/FileTypeFilterTools.php index cb815797..3380adb7 100644 --- a/src/Services/Attachments/FileTypeFilterTools.php +++ b/src/Services/Attachments/FileTypeFilterTools.php @@ -69,7 +69,7 @@ class FileTypeFilterTools $element = trim($element); if (!preg_match('#^\.\w+$#', $element) // .ext is allowed && !preg_match('#^[-\w.]+/[-\w.]+#', $element) //Explicit MIME type is allowed - && !in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, false)) { //image/* is allowed + && !in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, true)) { //image/* is allowed return false; } } @@ -173,6 +173,6 @@ class FileTypeFilterTools { $extension = strtolower($extension); - return $filter === '' || in_array($extension, $this->resolveFileExtensions($filter), false); + return $filter === '' || in_array($extension, $this->resolveFileExtensions($filter), true); } } diff --git a/src/Services/ElementTypeNameGenerator.php b/src/Services/ElementTypeNameGenerator.php index f907712b..f32677eb 100644 --- a/src/Services/ElementTypeNameGenerator.php +++ b/src/Services/ElementTypeNameGenerator.php @@ -95,7 +95,7 @@ class ElementTypeNameGenerator * * @throws EntityNotSupportedException when the passed entity is not supported */ - public function getLocalizedTypeLabel($entity): string + public function getLocalizedTypeLabel(object|string $entity): string { $class = is_string($entity) ? $entity : $entity::class; @@ -105,8 +105,8 @@ class ElementTypeNameGenerator } //Otherwise iterate over array and check for inheritance (needed when the proxy element from doctrine are passed) - foreach ($this->mapping as $class => $translation) { - if (is_a($entity, $class, true)) { + foreach ($this->mapping as $class_to_check => $translation) { + if (is_a($entity, $class_to_check, true)) { return $translation; } } diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 487bed39..2f4e0c0b 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -172,7 +172,7 @@ class EntityURLGenerator return $entity->getURL(); } - return $this->attachmentURLGenerator->getDownloadURL($entity) ?? ''; + return $this->attachmentURLGenerator->getDownloadURL($entity); } //Otherwise throw an error diff --git a/src/Services/LabelSystem/BarcodeGenerator.php b/src/Services/LabelSystem/BarcodeGenerator.php index 03eca1f6..f955955a 100644 --- a/src/Services/LabelSystem/BarcodeGenerator.php +++ b/src/Services/LabelSystem/BarcodeGenerator.php @@ -99,7 +99,6 @@ final class BarcodeGenerator BarcodeType::CODE39 => 'C39', BarcodeType::CODE93 => 'C93', BarcodeType::CODE128 => 'C128A', - default => throw new InvalidArgumentException('Unknown label type!'), }; if ($type === null) { diff --git a/src/Services/LabelSystem/LabelExampleElementsGenerator.php b/src/Services/LabelSystem/LabelExampleElementsGenerator.php index a5e194b2..d7c76c73 100644 --- a/src/Services/LabelSystem/LabelExampleElementsGenerator.php +++ b/src/Services/LabelSystem/LabelExampleElementsGenerator.php @@ -62,7 +62,6 @@ final class LabelExampleElementsGenerator LabelSupportedElement::PART => $this->getExamplePart(), LabelSupportedElement::PART_LOT => $this->getExamplePartLot(), LabelSupportedElement::STORELOCATION => $this->getStorelocation(), - default => throw new InvalidArgumentException('Unknown $type.'), }; } diff --git a/src/Services/LogSystem/LogTargetHelper.php b/src/Services/LogSystem/LogTargetHelper.php index 540f2b45..0a10a023 100644 --- a/src/Services/LogSystem/LogTargetHelper.php +++ b/src/Services/LogSystem/LogTargetHelper.php @@ -75,7 +75,7 @@ class LogTargetHelper if (!$target instanceof AbstractDBElement) { if ($context->hasTarget()) { return $this->elementTypeNameGenerator->formatElementDeletedHTML($context->getTargetClass(), - $context->getTargetId()); + $context->getTargetID()); } //If no target is set, we can't do anything return ''; diff --git a/src/Services/ProjectSystem/ProjectBuildHelper.php b/src/Services/ProjectSystem/ProjectBuildHelper.php index 1d0b4549..269c7e4c 100644 --- a/src/Services/ProjectSystem/ProjectBuildHelper.php +++ b/src/Services/ProjectSystem/ProjectBuildHelper.php @@ -64,7 +64,7 @@ class ProjectBuildHelper public function getMaximumBuildableCount(Project $project): int { $maximum_buildable_count = PHP_INT_MAX; - foreach ($project->getBOMEntries() as $bom_entry) { + foreach ($project->getBomEntries() as $bom_entry) { //Skip BOM entries without a part (as we can not determine that) if (!$bom_entry->isPartBomEntry()) { continue; diff --git a/src/Services/UserSystem/PermissionPresetsHelper.php b/src/Services/UserSystem/PermissionPresetsHelper.php index ecc56699..15a29b13 100644 --- a/src/Services/UserSystem/PermissionPresetsHelper.php +++ b/src/Services/UserSystem/PermissionPresetsHelper.php @@ -172,19 +172,13 @@ class PermissionPresetsHelper return $perm_holder; } - /** - * @phpstan-api - */ - private function AllForbid(HasPermissionsInterface $perm_holder): HasPermissionsInterface + private function allForbid(HasPermissionsInterface $perm_holder): HasPermissionsInterface { $this->permissionResolver->setAllPermissions($perm_holder, PermissionData::DISALLOW); return $perm_holder; } - /** - * @phpstan-api - */ - private function AllAllow(HasPermissionsInterface $perm_holder): HasPermissionsInterface + private function allAllow(HasPermissionsInterface $perm_holder): HasPermissionsInterface { $this->permissionResolver->setAllPermissions($perm_holder, PermissionData::ALLOW); return $perm_holder; diff --git a/src/Services/UserSystem/PermissionSchemaUpdater.php b/src/Services/UserSystem/PermissionSchemaUpdater.php index 29ce332d..5fb08182 100644 --- a/src/Services/UserSystem/PermissionSchemaUpdater.php +++ b/src/Services/UserSystem/PermissionSchemaUpdater.php @@ -65,8 +65,6 @@ class PermissionSchemaUpdater $reflectionClass = new \ReflectionClass(self::class); try { $method = $reflectionClass->getMethod('upgradeSchemaToVersion'.($n + 1)); - //Set the method accessible, so we can call it (needed for PHP < 8.1) - $method->setAccessible(true); $method->invoke($this, $holder); } catch (\ReflectionException $e) { throw new \RuntimeException('Could not find update method for schema version '.($n + 1), $e->getCode(), $e); @@ -114,7 +112,7 @@ class PermissionSchemaUpdater return $updated; } - private function upgradeSchemaToVersion1(HasPermissionsInterface $holder): void + private function upgradeSchemaToVersion1(HasPermissionsInterface $holder): void //@phpstan-ignore-line This is called via reflection { //Use the part edit permission to set the preset value for the new part stock permission if ( @@ -131,7 +129,7 @@ class PermissionSchemaUpdater } } - private function upgradeSchemaToVersion2(HasPermissionsInterface $holder): void + private function upgradeSchemaToVersion2(HasPermissionsInterface $holder): void //@phpstan-ignore-line This is called via reflection { //If the projects permissions are not defined yet, rename devices permission to projects (just copy its data over) if (!$holder->getPermissions()->isAnyOperationOfPermissionSet('projects')) { diff --git a/src/Validator/Constraints/UrlOrBuiltinValidator.php b/src/Validator/Constraints/UrlOrBuiltinValidator.php index b8ad3b6a..af498d2a 100644 --- a/src/Validator/Constraints/UrlOrBuiltinValidator.php +++ b/src/Validator/Constraints/UrlOrBuiltinValidator.php @@ -57,7 +57,7 @@ class UrlOrBuiltinValidator extends UrlValidator //After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode $tmp = explode('/', $value); //Builtins must have a %PLACEHOLDER% construction - if (in_array($tmp[0], $constraint->allowed_placeholders, false)) { + if (in_array($tmp[0], $constraint->allowed_placeholders, true)) { return; } diff --git a/src/Validator/Constraints/ValidPermissionValidator.php b/src/Validator/Constraints/ValidPermissionValidator.php index 7bc6c4e7..c0004e6c 100644 --- a/src/Validator/Constraints/ValidPermissionValidator.php +++ b/src/Validator/Constraints/ValidPermissionValidator.php @@ -30,8 +30,6 @@ use Symfony\Component\Validator\ConstraintValidator; class ValidPermissionValidator extends ConstraintValidator { - protected array $perm_structure; - public function __construct(protected PermissionManager $resolver) { }