Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix qodana issues #38

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude:
- translations
- .php_cs.dist
- doc
- templates
- .github
- .php-cs-fixer.dist.php
- .qodana-profile.xml
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Response/Content/OneOfAssetJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct()
type: 'object',
oneOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Assets),
}, Schemas::ASSETS),
);
}
}
2 changes: 1 addition & 1 deletion src/Attributes/Response/Error/BadRequestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
content: new JsonContent(
oneOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Errors),
}, Schemas::ERRORS),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Response/Error/MethodNotAllowedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
content: new JsonContent(
oneOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Errors),
}, Schemas::ERRORS),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Response/Error/UnauthorizedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
content: new JsonContent(
oneOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Errors),
}, Schemas::ERRORS),
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
content: new JsonContent(
oneOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Errors),
}, Schemas::ERRORS),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Response/Property/AnyOfAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct()
items: new Items(
anyOf: array_map(static function ($class) {
return new Schema(ref: $class);
}, Schemas::Assets)
}, Schemas::ASSETS)
)
);
}
Expand Down
20 changes: 16 additions & 4 deletions src/Config/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@
/**
* @internal
*/
#[Tag(name: Tags::Assets->name, description: 'Asset operations to get/update/create/delete assets')]
#[Tag(name: Tags::Authorization->name, description: 'Login via username and password to get a token or refresh the token')]
#[Tag(name: Tags::DataObjects->name, description: 'DataObject operations to get/update/create/delete data objects')]
#[Tag(name: Tags::Translation->name, description: 'Get translations either for a single key or multiple keys')]
#[Tag(
name: Tags::Assets->name,
description: 'Asset operations to get/update/create/delete assets'
)]
#[Tag(
name: Tags::Authorization->name,
description: 'Login via username and password to get a token or refresh the token'
)]
#[Tag(
name: Tags::DataObjects->name,
description: 'DataObject operations to get/update/create/delete data objects'
)]
#[Tag(
name: Tags::Translation->name,
description: 'Get translations either for a single key or multiple keys'
)]
enum Tags
{
case Assets;
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Api/TranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
final class TranslationController extends AbstractApiController
{
private const PATH = '/translations';
private const ROUTE = '/translations';

public function __construct(
SerializerInterface $serializer,
Expand All @@ -46,10 +46,10 @@ public function __construct(
parent::__construct($serializer);
}

#[Route(self::PATH, name: 'pimcore_studio_api_translations', methods: ['POST'])]
#[Route(self::ROUTE, name: 'pimcore_studio_api_translations', methods: ['POST'])]
//#[IsGranted(self::VOTER_PUBLIC_STUDIO_API, 'translation')]
#[POST(
path: self::API_PATH . self::PATH,
path: self::API_PATH . self::ROUTE,
operationId: 'getTranslations',
description: 'Get translations for given keys and locale',
summary: 'Get translations',
Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/CorsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function onKernelRequest(RequestEvent $event): void
}

// perform preflight checks
if ('OPTIONS' === $request->getMethod()) {
if ($request->getMethod() === 'OPTIONS') {
$response = new Response();

$response->headers->set('Access-Control-Allow-Credentials', 'true');
Expand Down
24 changes: 24 additions & 0 deletions src/Exception/ClassDefinitionNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Exception;

/**
* @internal
*/
final class ClassDefinitionNotFoundException extends AbstractApiException
{
}
4 changes: 4 additions & 0 deletions src/Filter/DataObject/ClassNameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Bundle\StudioApiBundle\Filter\DataObject;

use Exception;
use Pimcore\Bundle\StudioApiBundle\Filter\FilterInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\DataObjectParametersInterface;
use Pimcore\Bundle\StudioApiBundle\Request\Query\Filter\ParametersInterface;
Expand All @@ -27,6 +28,9 @@
*/
final class ClassNameFilter implements FilterInterface
{
/**
* @throws Exception
*/
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface
{
if(
Expand Down
3 changes: 3 additions & 0 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function install(): void
parent::install();
}

/**
* @throws SchemaException
*/
private function createTranslationTable(Schema $schema): void
{
$translationsDomainTableName = 'translations_' . TranslatorService::DOMAIN;
Expand Down
6 changes: 5 additions & 1 deletion src/Response/Asset/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class Document extends Asset
public function __construct(
#[Property(description: 'Page count', type: 'integer', example: 2)]
private readonly ?int $pageCount,
#[Property(description: 'Path to image thumbnail', type: 'integer', example: '/path/to/document/imagethumbnail.jpg')]
#[Property(
description: 'Path to image thumbnail',
type: 'integer',
example: '/path/to/document/imagethumbnail.jpg'
)]
private readonly ?string $imageThumbnailPath,
string $iconName,
bool $hasChildren,
Expand Down
6 changes: 5 additions & 1 deletion src/Response/Asset/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public function __construct(
private readonly ?int $width,
#[Property(description: 'Height', type: 'integer', example: 1080)]
private readonly ?int $height,
#[Property(description: 'Path to Image Thumbnail', type: 'string', example: '/path/to/video/imagethumbnail.jpg')]
#[Property(
description: 'Path to Image Thumbnail',
type: 'string',
example: '/path/to/video/imagethumbnail.jpg'
)]
private readonly?string $imageThumbnailPath,
string $iconName,
bool $hasChildren,
Expand Down
4 changes: 2 additions & 2 deletions src/Response/Schemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
final readonly class Schemas
{
public const Assets = [
public const ASSETS = [
Image::class,
Document::class,
Audio::class,
Expand All @@ -43,7 +43,7 @@
Unknown::class,
];

public const Errors = [
public const ERRORS = [
Error::class,
DevError::class,
];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/GenericData/V1/DataObjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\ElementKeySearch;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\ClassDefinitionResolverInterface;
use Pimcore\Bundle\StudioApiBundle\Exception\ClassDefinitionNotFoundException;

final class DataObjectQuery implements QueryInterface
{
Expand Down Expand Up @@ -86,7 +87,9 @@ public function excludeFolders(): self
public function setClassDefinitionName(string $classDefinitionId): self
{
$classDefinition = $this->classDefinitionResolver->getByName($classDefinitionId);

if($classDefinition === null) {
throw new ClassDefinitionNotFoundException(400, 'Class definition not found');
}
$this->search->setClassDefinition($classDefinition);

return $this;
Expand Down
1 change: 1 addition & 0 deletions src/Service/OpenApiServiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* Pimcore
Expand Down
Loading