diff --git a/phpstan.neon b/phpstan.neon index db118378..95eee3c0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -19,6 +19,10 @@ parameters: symfony: container_xml_path: '%rootDir%/../../../var/cache/dev/App_KernelDevDebugContainer.xml' + doctrine: + objectManagerLoader: tests/object-manager.php + allowNullablePropertyForRequiredField: true + checkUninitializedProperties: true checkFunctionNameCase: true @@ -48,8 +52,11 @@ parameters: ignoreErrors: # Ignore errors caused by complex mapping with AbstractStructuralDBElement - '#AbstractStructuralDBElement does not have a field named \$parent#' - - '#AbstractStructuralDBElement does not have a field named \$name#' + #- '#AbstractStructuralDBElement does not have a field named \$name#' # Ignore errors related to the use of the ParametersTrait in Part entity - '#expects .*PartParameter, .*AbstractParameter given.#' - - '#Part::getParameters\(\) should return .*AbstractParameter#' \ No newline at end of file + - '#Part::getParameters\(\) should return .*AbstractParameter#' + + # Ignore doctrine type mapping mismatch + - '#Property .* type mapping mismatch: property can contain .* but database expects .*#' \ No newline at end of file diff --git a/src/Controller/UserSettingsController.php b/src/Controller/UserSettingsController.php index c0d9f66d..a70efbff 100644 --- a/src/Controller/UserSettingsController.php +++ b/src/Controller/UserSettingsController.php @@ -411,6 +411,9 @@ class UserSettingsController extends AbstractController $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $token = new ApiToken(); + if (!$this->getUser() instanceof User) { + throw new RuntimeException('This controller only works only for Part-DB User objects!'); + } $token->setUser($this->getUser()); $secret = null; diff --git a/src/Entity/Attachments/MeasurementUnitAttachment.php b/src/Entity/Attachments/MeasurementUnitAttachment.php index 58467f86..7b7c4f83 100644 --- a/src/Entity/Attachments/MeasurementUnitAttachment.php +++ b/src/Entity/Attachments/MeasurementUnitAttachment.php @@ -36,9 +36,8 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; class MeasurementUnitAttachment extends Attachment { final public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class; - /** - * @var Manufacturer|null the element this attachment is associated with - */ + + #[ORM\ManyToOne(targetEntity: MeasurementUnit::class, inversedBy: 'attachments')] #[ORM\JoinColumn(name: 'element_id', nullable: false, onDelete: 'CASCADE')] protected ?AttachmentContainingDBElement $element = null; diff --git a/src/Security/ApiTokenAuthenticator.php b/src/Security/ApiTokenAuthenticator.php index 6d3dc09c..d274ca1a 100644 --- a/src/Security/ApiTokenAuthenticator.php +++ b/src/Security/ApiTokenAuthenticator.php @@ -118,12 +118,8 @@ class ApiTokenAuthenticator implements AuthenticatorInterface public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response { - if (null !== $this->translator) { - $errorMessage = $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), - 'security'); - } else { - $errorMessage = strtr($exception->getMessageKey(), $exception->getMessageData()); - } + $errorMessage = $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), + 'security'); return new Response( null, @@ -152,8 +148,9 @@ class ApiTokenAuthenticator implements AuthenticatorInterface return sprintf('Bearer %s', implode(',', $values)); } -public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response -{ - return null; -} + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return null; + } } \ No newline at end of file diff --git a/tests/object-manager.php b/tests/object-manager.php new file mode 100644 index 00000000..1e335268 --- /dev/null +++ b/tests/object-manager.php @@ -0,0 +1,32 @@ +. + */ + +declare(strict_types=1); + +use App\Kernel; +use Symfony\Component\Dotenv\Dotenv; + +require __DIR__ . '/../vendor/autoload.php'; + +(new Dotenv())->bootEnv(__DIR__ . '/../.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); +$kernel->boot(); +return $kernel->getContainer()->get('doctrine')->getManager(); \ No newline at end of file