Skip to content

Commit

Permalink
NEXT-34339 - Update PHPStan to 1.10.60
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Mar 12, 2024
1 parent e6cab97 commit 58eebdd
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 88 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"phpdocumentor/reflection-docblock": "^5.3.0",
"phpdocumentor/type-resolver": "^1.7.1",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "1.10.59",
"phpstan/phpstan": "1.10.60",
"phpstan/phpstan-deprecation-rules": "1.1.4",
"phpstan/phpstan-phpunit": "1.3.16",
"phpstan/phpstan-symfony": "1.3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -106,12 +107,16 @@ private function addDefaultSorting(Request $request, CmsSlotEntity $slot, SalesC
return;
}

// if we have no specific order given at this point, set the order to be the highest's priority available sorting
// if we have no specific order given at this point, set the order to the highest priority available sorting
if ($request->get('availableSortings')) {
$availableSortings = $request->get('availableSortings');
arsort($availableSortings, \SORT_DESC | \SORT_NUMERIC);
$sortingId = array_key_first($availableSortings);
if (!\is_string($sortingId) || !Uuid::isValid($sortingId)) {
return;
}

$criteria = new Criteria([array_key_first($availableSortings)]);
$criteria = new Criteria([$sortingId]);

$request->request->set('order', $this->sortingRepository->search($criteria, $context->getContext())->first()?->get('key'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function reset(): void
/**
* The `change()` function allows a complete overwrite of the product quantity prices
*
* @param array{to: int|null, price: PriceCollection}[] $changes
* @param list<array{to: int|null, price: PriceCollection}> $changes
*
* @example pricing-cases/product-pricing.twig 40 5 Overwrite the product prices with a new quantity price graduation
*/
Expand All @@ -65,7 +65,9 @@ public function change(array $changes): void
unset($mapped[null]);

\ksort($mapped, \SORT_NUMERIC);
$max = \max(\array_keys($mapped));
$arrayKeys = \array_keys($mapped);
\assert(!empty($arrayKeys));
$max = \max($arrayKeys);

$mapped[$max + 1] = $last;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ private function getOrderData(string $orderId, ?string $mediaId = null): array
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddress' => [
'salutationId' => $salutation,
'firstName' => 'Floy',
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Framework/Api/Sync/SyncFkResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function resolve(string $key, string $entity, array $payload): array
}

/**
* @param array<int, array<string|int, mixed>> $payload
* @param array<int, array<string, mixed>> $payload
*
* @return array<string, array<FkReference>>
*/
Expand Down Expand Up @@ -116,14 +116,14 @@ private function collect(string $entity, array &$payload, string $pointer): arra

$resolver = (string) $value['resolver'];

$row[$fieldName] = $reference = new FkReference(
$reference = new FkReference(
implode('/', [$current, $fieldName]),
$definition->getEntityName(),
$field->getPropertyName(),
$value['value'],
$value['nullOnMissing'] ?? false
);

$row[$fieldName] = $reference;
$map[$resolver][] = $reference;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function process(ContainerBuilder $container): void
{
$rateLimiter = $container->getDefinition(RateLimiter::class);

/** @var array<string, array<string, string>> $rateLimiterConfig */
$rateLimiterConfig = $container->getParameter('shopware.api.rate_limiter');

foreach ($rateLimiterConfig as $name => $config) {
Expand All @@ -48,7 +47,7 @@ public function process(ContainerBuilder $container): void
}

/**
* @param array<string, array<string, int|string>|bool|string|int> $config
* @param array<string, mixed> $config
*/
private function setConfigDefaults(array &$config): void
{
Expand Down
3 changes: 0 additions & 3 deletions src/Core/Framework/Struct/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ public function getElements(): array
return $this->elements;
}

/**
* @return list<TElement>
*/
public function jsonSerialize(): array
{
return array_values($this->elements);
Expand Down
18 changes: 10 additions & 8 deletions src/Core/System/SalesChannel/Validation/SalesChannelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

/**
* @internal
*
* @phpstan-type Mapping array<string, array{current_default: string, new_default: string, inserts: list<string>, updateId: string, deletions: list<string>, state: list<string>}>
*/
#[Package('buyers-experience')]
class SalesChannelValidator implements EventSubscriberInterface
Expand Down Expand Up @@ -74,12 +76,12 @@ public function handleSalesChannelLanguageIds(PreWriteValidationEvent $event): v
* 'current_default' => 'en',
* 'new_default' => 'de',
* 'inserts' => ['de', 'en'],
* 'updates' => ['de', 'de'],
* 'updateId' => 'de',
* 'deletions' => ['gb'],
* 'state' => ['en', 'gb']
* ]
*
* @return array<string, array<string, list<string>>>
* @return Mapping
*/
private function extractMapping(PreWriteValidationEvent $event): array
{
Expand All @@ -100,7 +102,7 @@ private function extractMapping(PreWriteValidationEvent $event): array
}

/**
* @param array<string, array<string, list<string>>> $mapping
* @param Mapping $mapping
*/
private function handleSalesChannelMapping(array &$mapping, WriteCommand $command): void
{
Expand All @@ -110,7 +112,7 @@ private function handleSalesChannelMapping(array &$mapping, WriteCommand $comman

if ($command instanceof UpdateCommand) {
$id = Uuid::fromBytesToHex($command->getPrimaryKey()['id']);
$mapping[$id]['updates'] = Uuid::fromBytesToHex($command->getPayload()['language_id']);
$mapping[$id]['updateId'] = Uuid::fromBytesToHex($command->getPayload()['language_id']);

return;
}
Expand All @@ -134,7 +136,7 @@ private function isSupportedSalesChannelType(WriteCommand $command): bool
}

/**
* @param array<string, list<string>> $mapping
* @param Mapping $mapping
*/
private function handleSalesChannelLanguageMapping(array &$mapping, WriteCommand $command): void
{
Expand Down Expand Up @@ -180,8 +182,8 @@ private function validateLanguages(array $mapping, PreWriteValidationEvent $even
$deletions[$id] = $channel['current_default'];
}

if (isset($channel['updates']) && !$this->validUpdateCase($channel)) {
$updates[$id] = $channel['updates'];
if (isset($channel['updateId']) && !$this->validUpdateCase($channel)) {
$updates[$id] = $channel['updateId'];
}
}

Expand All @@ -205,7 +207,7 @@ private function validInsertCase(array $channel): bool
*/
private function validUpdateCase(array $channel): bool
{
$updateId = $channel['updates'];
$updateId = $channel['updateId'];

return \in_array($updateId, $channel['state'], true)
|| empty($channel['new_default']) && $updateId === $channel['current_default']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function customFieldIsDeleted(EntityDeletedEvent $event): void

/**
* @param array<array<string, string>> $snippetSets
* @param array<string, mixed> $snippets
* @param list<array<string, mixed>> $snippets
*/
private function setInsertSnippets(EntityWriteResult $writeResult, array $snippetSets, array &$snippets): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private function createOrderWithPartiallyReturnedDeliveryState(): string
'id' => $orderDeliveryId,
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'stateId' => $returnedPartially,
'shippingOrderAddress' => [
'salutationId' => $this->getValidSalutationId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ private function createOrderForCustomer(array $customer): string
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddressId' => $customer['defaultShippingAddressId'],
'positions' => [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ private function createOrderForCustomer(array $customer): string
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddressId' => $customer['defaultShippingAddressId'],
'positions' => [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/Core/Checkout/Order/OrderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ private function getOrderData(string $orderId, Context $context): array
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddress' => [
'salutationId' => $salutation,
'firstName' => 'Floy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ private function getOrderData(string $orderId, string $customerId, string $email
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddress' => [
'salutationId' => $salutation,
'firstName' => 'Floy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ private function getOrderData(string $orderId, Context $context): array
'stateId' => $this->getContainer()->get(InitialStateIdLoader::class)->get(OrderDeliveryStates::STATE_MACHINE),
'shippingMethodId' => $this->getValidShippingMethodId(),
'shippingCosts' => new CalculatedPrice(10, 10, new CalculatedTaxCollection(), new TaxRuleCollection()),
'shippingDateEarliest' => date(\DATE_ISO8601),
'shippingDateLatest' => date(\DATE_ISO8601),
'shippingDateEarliest' => date(\DATE_ATOM),
'shippingDateLatest' => date(\DATE_ATOM),
'shippingOrderAddress' => [
'salutationId' => $salutation,
'firstName' => 'Floy',
Expand Down
Loading

0 comments on commit 58eebdd

Please sign in to comment.