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

ADS-4296 Language specific plugin configuration (new linting rules) #6

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
12 changes: 11 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

Expand All @@ -18,7 +20,7 @@
]);

$ecsConfig->skip([
NotOperatorWithSuccessorSpaceFixer::class
NotOperatorWithSuccessorSpaceFixer::class,
]);

$ecsConfig->sets([
Expand All @@ -35,4 +37,12 @@
'identical' => false,
'less_and_greater' => false,
]);

$ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [
'inline_short_lines' => false,
]);

$ecsConfig->ruleWithConfiguration(TrailingCommaInMultilineFixer::class, [
'elements' => ['arguments', 'arrays', 'match', 'parameters'],
]);
};
6 changes: 3 additions & 3 deletions src/Api/Controller/NostoCategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[Route(
defaults: [
'_routeScope' => ['api'],
]
],
)]
class NostoCategoriesController extends AbstractController
{
Expand All @@ -45,7 +45,7 @@ public function __construct(
defaults: [
'auth_required' => true,
],
methods: ["POST"]
methods: ["POST"],
)]
public function sync(Request $request, Context $context): JsonResponse
{
Expand All @@ -55,7 +55,7 @@ public function sync(Request $request, Context $context): JsonResponse
$criteria->getAssociation('seoUrls');
$criteria->addFilter(new EqualsFilter(
'active',
true
true,
));

$appToken = $this->configProvider->getAppToken(
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Controller/NostoConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#[Route(
defaults: [
'_routeScope' => ['api'],
]
],
)]
class NostoConfigController extends AbstractController
{
public function __construct(
private readonly NostoConfigService $nostoConfigService,
private readonly Connection $connection
private readonly Connection $connection,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Api/Controller/NostoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#[Route(
defaults: [
'_routeScope' => ['api'],
]
],
)]
class NostoController extends AbstractController
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct(NostoSyncRoute $nostoSyncRoute, TagAwareAdapterInter
#[Route(
path: "/api/_action/nosto-integration/schedule-full-product-sync",
name: "api.action.nosto_integration.schedule.full.product.sync",
methods: ["POST"]
methods: ["POST"],
)]
public function fullCatalogSyncAction(Request $request, Context $context): JsonResponse
{
Expand All @@ -64,7 +64,7 @@ public function fullCatalogSyncAction(Request $request, Context $context): JsonR
#[Route(
path: "/api/_action/nosto-integration/clear-cache",
name: "api.action.nosto_integration.clear.cache",
methods: ["POST"]
methods: ["POST"],
)]
public function clearCache(): JsonResponse
{
Expand All @@ -78,7 +78,7 @@ public function clearCache(): JsonResponse
options: [
"auth_required" => "false",
],
methods: ["POST"]
methods: ["POST"],
)]
public function validate(RequestDataBag $post): JsonResponse
{
Expand Down
11 changes: 6 additions & 5 deletions src/Api/Route/NostoSyncRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Nosto\NostoIntegration\Api\Route;

use Exception;
use Nosto\NostoIntegration\Async\FullCatalogSyncMessage;
use Nosto\Scheduler\Entity\Job\JobEntity;
use Nosto\Scheduler\Model\JobScheduler;
Expand All @@ -21,7 +22,7 @@
#[Route(
defaults: [
'_routeScope' => ['api'],
]
],
)]
class NostoSyncRoute
{
Expand All @@ -31,7 +32,7 @@ class NostoSyncRoute

public function __construct(
JobScheduler $jobScheduler,
EntityRepository $jobRepository
EntityRepository $jobRepository,
) {
$this->jobScheduler = $jobScheduler;
$this->jobRepository = $jobRepository;
Expand All @@ -40,7 +41,7 @@ public function __construct(
#[Route(
path: "/api/schedule-full-product-sync",
name: "api.nosto_integration_sync.full_sync",
methods: ["POST"]
methods: ["POST"],
)]
public function fullCatalogSync(Request $request, Context $context): JsonApiResponse
{
Expand All @@ -57,15 +58,15 @@ private function checkJobStatus(Context $context, string $type): void
new AndFilter([
new EqualsFilter('type', $type),
new EqualsAnyFilter('status', [JobEntity::TYPE_PENDING, JobEntity::TYPE_RUNNING]),
])
]),
);
/** @var JobEntity $job */
if ($job = $this->jobRepository->search($criteria, $context)->first()) {
$message = $job->getStatus() === JobEntity::TYPE_PENDING
? 'Job is already scheduled.'
: 'Job is already running.';

throw new \Exception($message);
throw new Exception($message);
}
}
}
6 changes: 3 additions & 3 deletions src/Async/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ abstract class AbstractMessage implements JobMessageInterface
public function __construct(
string $jobId,
?Context $context = null,
?string $name = null
?string $name = null,
) {
$this->jobId = $jobId;
$this->name = $name ?? static::$defaultName;
$this->setContext($context);
}

protected function setContext(?Context $context)
protected function setContext(?Context $context): void
{
// All values should be sent to nosto with the default currency and language
if ($context === null) {
Expand All @@ -48,7 +48,7 @@ protected function setContext(?Context $context)
$context->getCurrencyFactor(),
$context->considerInheritance(),
$context->getTaxState(),
$context->getRounding()
$context->getRounding(),
);
} else {
$this->context = $context;
Expand Down
2 changes: 1 addition & 1 deletion src/Async/EventsWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(EntityRepository $changelogRepository)
$this->changelogRepository = $changelogRepository;
}

public function writeEvent(string $name, string $id, Context $context, ?string $productNumber = null)
public function writeEvent(string $name, string $id, Context $context, ?string $productNumber = null): void
{
$this->changelogRepository->create([[
'entityType' => $name,
Expand Down
2 changes: 1 addition & 1 deletion src/Async/MarketingPermissionSyncMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
string $parentJobId,
array $newsletterRecipientIds,
?Context $context = null,
?string $name = null
?string $name = null,
) {
parent::__construct($jobId, $context, $name);
$this->newsletterRecipientIds = $newsletterRecipientIds;
Expand Down
2 changes: 1 addition & 1 deletion src/Async/OrderSyncMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
array $newOrderIds,
array $updatedOrderIds,
?Context $context,
?string $name = null
?string $name = null,
) {
parent::__construct($jobId, $context, $name);
$this->newOrderIds = $newOrderIds;
Expand Down
2 changes: 1 addition & 1 deletion src/Async/ProductSyncMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
string $parentJobId,
array $productIds,
?Context $context = null,
?string $name = null
?string $name = null,
) {
parent::__construct($jobId, $context, $name);
$this->productIds = $productIds;
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Storefront/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[Route(
defaults: [
'_routeScope' => ['storefront'],
]
],
)]
class CartController extends StorefrontController
{
Expand All @@ -30,7 +30,7 @@ public function __construct(RestorerServiceInterface $restorerService)
options: [
"seo" => "false",
],
methods: ["GET"]
methods: ["GET"],
)]
public function index(string $mappingId, SalesChannelContext $context): Response
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function prepare(Request $request, Criteria $criteria, SalesChannelContex
if (SearchHelper::shouldHandleRequest(
$context,
$this->configProvider,
SearchHelper::isNavigationPage($request)
SearchHelper::isNavigationPage($request),
)) {
if (SearchHelper::isSearchPage($request)) {
$this->searchService->doSearch($request, $criteria, $context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function load(
string $categoryId,
Request $request,
SalesChannelContext $context,
Criteria $criteria = null
Criteria $criteria = null,
): ProductListingRouteResponse {
$shouldHandleRequest = SearchHelper::shouldHandleRequest($context, $this->configProvider, true);

Expand All @@ -61,14 +61,14 @@ public function load(
$criteria->addFilter(
new ProductAvailableFilter(
$context->getSalesChannel()->getId(),
ProductVisibilityDefinition::VISIBILITY_ALL
)
ProductVisibilityDefinition::VISIBILITY_ALL,
),
);

/** @var CategoryEntity $category */
$category = $this->categoryRepository->search(
new Criteria([$categoryId]),
$context->getContext()
$context->getContext(),
)->first();

$streamId = $this->extendCriteria($context, $criteria, $category);
Expand Down Expand Up @@ -125,17 +125,17 @@ private function isRequestFromHomePage(Request $request): bool
private function extendCriteria(
SalesChannelContext $salesChannelContext,
Criteria $criteria,
CategoryEntity $category
CategoryEntity $category,
): ?string {
$supportsProductStreams = defined(
'\Shopware\Core\Content\Category\CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM'
'\Shopware\Core\Content\Category\CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM',
);
$isProductStream = $supportsProductStreams &&
$category->getProductAssignmentType() === CategoryDefinition::PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM;
if ($isProductStream && $category->getProductStreamId() !== null) {
$filters = $this->productStreamBuilder->buildFilters(
$category->getProductStreamId(),
$salesChannelContext->getContext()
$salesChannelContext->getContext(),
);

$criteria->addFilter(...$filters);
Expand All @@ -144,15 +144,15 @@ private function extendCriteria(
}

$criteria->addFilter(
new EqualsFilter('product.categoriesRo.id', $category->getId())
new EqualsFilter('product.categoriesRo.id', $category->getId()),
);

return null;
}

private function fetchProductsById(
Criteria $criteria,
SalesChannelContext $salesChannelContext
SalesChannelContext $salesChannelContext,
): EntitySearchResult {
if (empty($criteria->getIds())) {
return $this->createEmptySearchResult($criteria, $salesChannelContext->getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
private readonly ProductSearchBuilderInterface $searchBuilder,
private readonly SalesChannelRepository $salesChannelProductRepository,
private readonly CompositeListingProcessor $listingProcessor,
private readonly ConfigProvider $configProvider
private readonly ConfigProvider $configProvider,
) {
}

Expand All @@ -46,7 +46,7 @@ public function getDecorated(): AbstractProductSearchRoute
public function load(
Request $request,
SalesChannelContext $context,
Criteria $criteria
Criteria $criteria,
): ProductSearchRouteResponse {
if (!SearchHelper::shouldHandleRequest($context, $this->configProvider)) {
return $this->decorated->load($request, $context, $criteria);
Expand All @@ -65,8 +65,8 @@ public function load(
$criteria->addFilter(
new ProductAvailableFilter(
$context->getSalesChannel()->getId(),
ProductVisibilityDefinition::VISIBILITY_SEARCH
)
ProductVisibilityDefinition::VISIBILITY_SEARCH,
),
);

$this->searchBuilder->build($request, $criteria, $context);
Expand All @@ -86,7 +86,7 @@ public function load(
private function fetchProductsById(
Criteria $criteria,
SalesChannelContext $salesChannelContext,
?string $query
?string $query,
): EntitySearchResult {
if (empty($criteria->getIds())) {
return $this->createEmptySearchResult($criteria, $salesChannelContext->getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
EventDispatcherInterface $eventDispatcher,
EntityLoadedEventFactory $eventFactory,
EntityRepository $inner,
EventsWriter $eventsWriter
EventsWriter $eventsWriter,
) {
parent::__construct($definition, $reader, $versionManager, $searcher, $aggregator, $eventDispatcher, $eventFactory);
$this->inner = $inner;
Expand All @@ -61,8 +61,12 @@ public function searchIds(Criteria $criteria, Context $context): IdSearchResult
return $this->inner->searchIds($criteria, $context);
}

public function clone(string $id, Context $context, ?string $newId = null, ?CloneBehavior $behavior = null): EntityWrittenContainerEvent
{
public function clone(
string $id,
Context $context,
?string $newId = null,
?CloneBehavior $behavior = null,
): EntityWrittenContainerEvent {
return $this->inner->clone($id, $context, $newId, $behavior);
}

Expand Down Expand Up @@ -106,7 +110,12 @@ public function delete(array $ids, Context $context): EntityWrittenContainerEven
if ($event instanceof EntityDeletedEvent && $event->getEntityName() === ProductDefinition::ENTITY_NAME) {
foreach ($event->getIds() as $productId) {
if (!empty($orderNumberMapping[$productId])) {
$this->eventsWriter->writeEvent($event->getEntityName(), $productId, $event->getContext(), $orderNumberMapping[$productId]);
$this->eventsWriter->writeEvent(
$event->getEntityName(),
$productId,
$event->getContext(),
$orderNumberMapping[$productId],
);
}
}
}
Expand Down
Loading