Skip to content

Commit

Permalink
Fix qodana
Browse files Browse the repository at this point in the history
  • Loading branch information
alexz707 committed Feb 8, 2024
1 parent 72a4795 commit 3f94ce1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
8 changes: 7 additions & 1 deletion src/Dto/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
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;
use Pimcore\Model\User;

class Asset
{
public function __construct(private ModelAsset $asset, private Permissions $permission)
public function __construct(private readonly ModelAsset $asset, private readonly Permissions $permission)
{
}

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/Dto/Asset/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/Dto/Asset/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Dto/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class Version
{
public function __construct(private ModelVersion $version)
public function __construct(private readonly ModelVersion $version)
{
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/State/ResetPasswordProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
$currentRequest = $this->requestStack->getCurrentRequest();
$limiter = $this->resetPasswordLimiter->create($currentRequest->getClientIp());

Check warning on line 62 in src/State/ResetPasswordProcessor.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Null reference

\[EA\] Null pointer exception may occur here.

if (false === $limiter->consume()->isAccepted()) {
if ($limiter->consume()->isAccepted() === false) {
throw new InvalidValueException('Rate limit exceeded');
}

Expand Down

0 comments on commit 3f94ce1

Please sign in to comment.