From 3f94ce11750a388e90b7e518b14c6f97a0452227 Mon Sep 17 00:00:00 2001 From: Alex Zamponi <562324+alexz707@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:40:14 +0100 Subject: [PATCH] Fix qodana --- src/Dto/Asset.php | 8 +++++++- src/Dto/Asset/Image.php | 13 +++++++++++-- src/Dto/Asset/Permissions.php | 18 +++++++++--------- src/Dto/Version.php | 4 ++-- src/State/ResetPasswordProcessor.php | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/Dto/Asset.php b/src/Dto/Asset.php index ba8aaf6ca..10eb65035 100644 --- a/src/Dto/Asset.php +++ b/src/Dto/Asset.php @@ -14,6 +14,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Dto; use ApiPlatform\Metadata\ApiProperty; +use Exception; use Pimcore\Bundle\StudioApiBundle\Dto\Asset\Permissions; use Pimcore\Model\Asset as ModelAsset; use Pimcore\Model\Dependency; @@ -21,7 +22,7 @@ class Asset { - public function __construct(private ModelAsset $asset, private Permissions $permission) + public function __construct(private readonly ModelAsset $asset, private readonly Permissions $permission) { } @@ -180,6 +181,11 @@ public function getFrontendFullPath(): string return $this->asset->getFrontendFullPath(); } + /** + * @param User|null $user + * @return array + * @throws Exception + */ public function getUserPermissions(?User $user = null): array { return $this->asset->getUserPermissions($user); diff --git a/src/Dto/Asset/Image.php b/src/Dto/Asset/Image.php index 6924438cb..38832208d 100644 --- a/src/Dto/Asset/Image.php +++ b/src/Dto/Asset/Image.php @@ -13,6 +13,7 @@ namespace Pimcore\Bundle\StudioApiBundle\Dto\Asset; +use Exception; use Pimcore\Bundle\StudioApiBundle\Dto\Asset; use Pimcore\Model\Asset\Image as ModelImage; use Pimcore\Model\Asset\Image\ThumbnailInterface; @@ -34,8 +35,10 @@ public function getLowQualityPreviewDataUri(): ?string return $this->asset->getLowQualityPreviewDataUri(); } - public function getThumbnail(array|string|ModelImage\Thumbnail\Config|null $config = null, bool $deferred = true): ThumbnailInterface - { + public function getThumbnail( + array|string|ModelImage\Thumbnail\Config|null $config = null, + bool $deferred = true + ): ThumbnailInterface { return $this->asset->getThumbnail($config, $deferred); } @@ -44,6 +47,12 @@ public function getFormat(): string return $this->asset->getFormat(); } + /** + * @param string|null $path + * @param bool $force + * @return array|null + * @throws Exception + */ public function getDimensions(string $path = null, bool $force = false): ?array { return $this->asset->getDimensions($path, $force); diff --git a/src/Dto/Asset/Permissions.php b/src/Dto/Asset/Permissions.php index 2eab8e350..af9f165e8 100644 --- a/src/Dto/Asset/Permissions.php +++ b/src/Dto/Asset/Permissions.php @@ -17,15 +17,15 @@ class Permissions { //TODO: remove or change default permissions public function __construct( - private bool $list = true, - private bool $view = true, - private bool $publish = true, - private bool $delete = true, - private bool $rename = true, - private bool $create = true, - private bool $settings = true, - private bool $versions = true, - private bool $properties = true + private readonly bool $list = true, + private readonly bool $view = true, + private readonly bool $publish = true, + private readonly bool $delete = true, + private readonly bool $rename = true, + private readonly bool $create = true, + private readonly bool $settings = true, + private readonly bool $versions = true, + private readonly bool $properties = true ) { } diff --git a/src/Dto/Version.php b/src/Dto/Version.php index 77e07b48c..55c6b6976 100644 --- a/src/Dto/Version.php +++ b/src/Dto/Version.php @@ -20,7 +20,7 @@ class Version { - public function __construct(private ModelVersion $version) + public function __construct(private readonly ModelVersion $version) { } @@ -72,7 +72,7 @@ public function getData(): mixed { $data = $this->version->getData(); if ($data instanceof Image) { - return new \Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image($data, new Permissions()); + return new Asset\Image($data, new Permissions()); } return $data; diff --git a/src/State/ResetPasswordProcessor.php b/src/State/ResetPasswordProcessor.php index dc9473f79..b0b1073e8 100644 --- a/src/State/ResetPasswordProcessor.php +++ b/src/State/ResetPasswordProcessor.php @@ -61,7 +61,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables = $currentRequest = $this->requestStack->getCurrentRequest(); $limiter = $this->resetPasswordLimiter->create($currentRequest->getClientIp()); - if (false === $limiter->consume()->isAccepted()) { + if ($limiter->consume()->isAccepted() === false) { throw new InvalidValueException('Rate limit exceeded'); }