Skip to content

Commit

Permalink
[Maintenance] Upgrade PHPStan packages
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Apr 21, 2021
1 parent bfb6805 commit 0e47a15
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 28 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ jobs:
run: symfony security:check

-
name: Run analysis
run: composer analyse
name: Validate composer.json
run: composer validate --ansi --strict

-
name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon -l max src/

-
name: Run PHPSpec
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpspec/phpspec": "^7.0",
"phpstan/phpstan": "0.12.29",
"phpstan/phpstan-webmozart-assert": "0.12.6",
"phpstan/phpstan": "0.12.84",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^9.5",
"sylius-labs/coding-standard": "^3.2",
"symfony/browser-kit": "^4.4 || ^5.2",
Expand All @@ -70,7 +70,7 @@
"scripts": {
"analyse": [
"@composer validate --strict",
"vendor/bin/phpstan.phar analyse -c phpstan.neon -l max src/"
"vendor/bin/phpstan analyse -c phpstan.neon -l max src/"
],
"fix": [
"vendor/bin/ecs check src/ spec/ --fix"
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ parameters:
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 $configuration of method Symfony\Component\DependencyInjection\Extension\Extension::processConfiguration() expects Symfony\Component\Config\Definition\ConfigurationInterface, Symfony\Component\Config\Definition\ConfigurationInterface|null given./'
8 changes: 7 additions & 1 deletion src/Action/Admin/OrderRefundsListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sylius\RefundPlugin\Action\Admin;

use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\RefundPlugin\Checker\OrderRefundingAvailabilityCheckerInterface;
Expand All @@ -14,6 +15,7 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Webmozart\Assert\Assert;

final class OrderRefundsListAction
{
Expand Down Expand Up @@ -64,10 +66,14 @@ public function __invoke(Request $request): Response
return $this->redirectToReferer($order, 'sylius_refund.order_should_be_paid');
}

/** @var ChannelInterface|null $channel */
$channel = $order->getChannel();
Assert::notNull($channel);

return new Response(
$this->twig->render('@SyliusRefundPlugin/orderRefunds.html.twig', [
'order' => $order,
'payment_methods' => $this->refundPaymentMethodsProvider->findForChannel($order->getChannel()),
'payment_methods' => $this->refundPaymentMethodsProvider->findForChannel($channel),
])
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/Checker/OrderFullyRefundedTotalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\RefundPlugin\Provider\OrderRefundedTotalProviderInterface;
use Webmozart\Assert\Assert;

final class OrderFullyRefundedTotalChecker implements OrderFullyRefundedTotalCheckerInterface
{
Expand All @@ -19,6 +20,10 @@ public function __construct(OrderRefundedTotalProviderInterface $orderRefundedTo

public function isOrderFullyRefunded(OrderInterface $order): bool
{
return $order->getTotal() === $this->orderRefundedTotalProvider->__invoke($order->getNumber());
/** @var string|null $orderNumber */
$orderNumber = $order->getNumber();
Assert::notNull($orderNumber);

return $order->getTotal() === $this->orderRefundedTotalProvider->__invoke($orderNumber);
}
}
7 changes: 6 additions & 1 deletion src/CommandHandler/RefundUnitsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Sylius\RefundPlugin\Refunder\RefunderInterface;
use Sylius\RefundPlugin\Validator\RefundUnitsCommandValidatorInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

final class RefundUnitsHandler
{
Expand Down Expand Up @@ -56,13 +57,17 @@ public function __invoke(RefundUnits $command): void
$refundedTotal += $this->orderUnitsRefunder->refundFromOrder($command->units(), $orderNumber);
$refundedTotal += $this->orderShipmentsRefunder->refundFromOrder($command->shipments(), $orderNumber);

/** @var string|null $currencyCode */
$currencyCode = $order->getCurrencyCode();
Assert::notNull($currencyCode);

$this->eventBus->dispatch(new UnitsRefunded(
$orderNumber,
$command->units(),
$command->shipments(),
$command->paymentMethodId(),
$refundedTotal,
$order->getCurrencyCode(),
$currencyCode,
$command->comment()
));
}
Expand Down
11 changes: 9 additions & 2 deletions src/CommandHandler/SendCreditMemoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sylius\RefundPlugin\CommandHandler;

use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Command\SendCreditMemo;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
Expand Down Expand Up @@ -39,8 +40,14 @@ public function __invoke(SendCreditMemo $command): void

$order = $creditMemo->getOrder();

Assert::notNull($order->getCustomer(), 'Credit memo order has no customer');
/** @var CustomerInterface|null $customer */
$customer = $order->getCustomer();
Assert::notNull($customer, 'Credit memo order has no customer');

$this->creditMemoEmailSender->send($creditMemo, $order->getCustomer()->getEmail());
/** @var string|null $recipient */
$recipient = $customer->getEmail();
Assert::notNull($recipient);

$this->creditMemoEmailSender->send($creditMemo, $recipient);
}
}
6 changes: 5 additions & 1 deletion src/Converter/OrderItemUnitLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ private function convertUnitRefundToLineItem(OrderItemUnitRefund $unitRefund): L
$taxAmount = (int) ($grossValue * $orderItemUnit->getTaxTotal() / $orderItemUnit->getTotal());
$netValue = $grossValue - $taxAmount;

/** @var string|null $productName */
$productName = $orderItem->getProductName();
Assert::notNull($productName);

return new LineItem(
$orderItem->getProductName(),
$productName,
1,
$netValue,
$grossValue,
Expand Down
6 changes: 5 additions & 1 deletion src/Converter/ShipmentLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ private function convertShipmentRefundToLineItem(ShipmentRefund $shipmentRefund)
$taxAmount = (int) ($grossValue * $taxAdjustmentAmount / $shipment->getAdjustmentsTotal());
$netValue = $grossValue - $taxAmount;

/** @var string|null $label */
$label = $shippingAdjustment->getLabel();
Assert::notNull($label);

return new LineItem(
$shippingAdjustment->getLabel(),
$label,
1,
$netValue,
$grossValue,
Expand Down
10 changes: 7 additions & 3 deletions src/DependencyInjection/SyliusRefundExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sylius\RefundPlugin\DependencyInjection;

use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -15,9 +16,12 @@ final class SyliusRefundExtension extends Extension implements PrependExtensionI
{
use PrependDoctrineMigrationsTrait;

public function load(array $config, ContainerBuilder $container): void
public function load(array $configs, ContainerBuilder $container): void
{
$this->processConfiguration($this->getConfiguration([], $container), $config);
/** @var ConfigurationInterface $configuration */
$configuration = $this->getConfiguration([], $container);

$this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

$loader->load('services.xml');
Expand All @@ -43,6 +47,6 @@ protected function getNamespacesOfMigrationsExecutedBefore(): array
return [
'Sylius\Bundle\CoreBundle\Migrations',
'Sylius\Bundle\AdminApiBundle\Migrations',
];
];
}
}
28 changes: 23 additions & 5 deletions src/Generator/CreditMemoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ public function generate(
Assert::allIsInstanceOf($units, OrderItemUnitRefund::class);
Assert::allIsInstanceOf($shipments, ShipmentRefund::class);

/** @var ChannelInterface $channel */
/** @var ChannelInterface|null $channel */
$channel = $order->getChannel();

Assert::notNull($channel);

/** @var string|null $currencyCode */
$currencyCode = $order->getCurrencyCode();
Assert::notNull($currencyCode);

/** @var string|null $localeCode */
$localeCode = $order->getLocaleCode();
Assert::notNull($localeCode);

/** @var AddressInterface|null $billingAddress */
$billingAddress = $order->getBillingAddress();
Assert::notNull($billingAddress);

$lineItems = array_merge(
$this->lineItemsConverter->convert($units),
$this->shipmentLineItemsConverter->convert($shipments)
Expand All @@ -79,20 +90,27 @@ public function generate(
$this->creditMemoNumberGenerator->generate(),
$order,
$total,
$order->getCurrencyCode(),
$order->getLocaleCode(),
$currencyCode,
$localeCode,
$channel,
$lineItems,
$this->taxItemsGenerator->generate($lineItems),
$comment,
$this->currentDateTimeImmutableProvider->now(),
$this->getFromAddress($order->getBillingAddress()),
$this->getFromAddress($billingAddress),
$this->getToAddress($channel->getShopBillingData())
);
}

private function getFromAddress(AddressInterface $address): CustomerBillingData
{
Assert::notNull($address->getFirstName());
Assert::notNull($address->getLastName());
Assert::notNull($address->getStreet());
Assert::notNull($address->getPostcode());
Assert::notNull($address->getCountryCode());
Assert::notNull($address->getCity());

return new CustomerBillingData(
$address->getFirstName(),
$address->getLastName(),
Expand Down
9 changes: 7 additions & 2 deletions src/Menu/OrderShowMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent;
use Sylius\RefundPlugin\Checker\OrderRefundingAvailabilityCheckerInterface;
use Webmozart\Assert\Assert;

final class OrderShowMenuListener
{
Expand All @@ -22,11 +23,15 @@ public function addRefundsButton(OrderShowMenuBuilderEvent $event): void
$menu = $event->getMenu();
$order = $event->getOrder();

if ($this->orderRefundsListAvailabilityChecker->__invoke($order->getNumber())) {
/** @var string|null $orderNumber */
$orderNumber = $order->getNumber();
Assert::notNull($orderNumber);

if ($this->orderRefundsListAvailabilityChecker->__invoke($orderNumber)) {
$menu
->addChild('refunds', [
'route' => 'sylius_refund_order_refunds_list',
'routeParameters' => ['orderNumber' => $order->getNumber()],
'routeParameters' => ['orderNumber' => $orderNumber],
])
->setLabel('sylius_refund.ui.refunds')
->setLabelAttribute('icon', 'reply all')
Expand Down
14 changes: 12 additions & 2 deletions src/TaxesApplicator/OrderItemUnitsTaxesApplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\TaxRateInterface;
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface;
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;
use Sylius\Component\Taxation\Calculator\CalculatorInterface;
use Sylius\Component\Taxation\Resolver\TaxRateResolverInterface;
use Sylius\RefundPlugin\Entity\AdjustmentInterface;
use Webmozart\Assert\Assert;

/**
* @internal
Expand Down Expand Up @@ -53,8 +55,12 @@ public function __construct(
public function apply(OrderInterface $order, ZoneInterface $zone): void
{
foreach ($order->getItems() as $item) {
/** @var ProductVariantInterface|null $variant */
$variant = $item->getVariant();
Assert::notNull($variant);

/** @var TaxRateInterface|null $taxRate */
$taxRate = $this->taxRateResolver->resolve($item->getVariant(), ['zone' => $zone]);
$taxRate = $this->taxRateResolver->resolve($variant, ['zone' => $zone]);
if (null === $taxRate) {
continue;
}
Expand All @@ -73,10 +79,14 @@ public function apply(OrderInterface $order, ZoneInterface $zone): void

private function addAdjustment(OrderItemUnitInterface $unit, int $taxAmount, TaxRateInterface $taxRate): void
{
/** @var string|null $label */
$label = $taxRate->getLabel();
Assert::notNull($label);

/** @var AdjustmentInterface $unitTaxAdjustment */
$unitTaxAdjustment = $this->adjustmentFactory->createWithData(
AdjustmentInterface::TAX_ADJUSTMENT,
$taxRate->getLabel(),
$label,
$taxAmount,
$taxRate->isIncludedInPrice()
);
Expand Down
13 changes: 11 additions & 2 deletions src/TaxesApplicator/OrderItemsTaxesApplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Component\Core\Distributor\IntegerDistributorInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\TaxRateInterface;
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface;
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;
Expand Down Expand Up @@ -66,8 +67,12 @@ public function apply(OrderInterface $order, ZoneInterface $zone): void
$quantity = $item->getQuantity();
Assert::notSame($quantity, 0, 'Cannot apply tax to order item with 0 quantity.');

/** @var ProductVariantInterface|null $variant */
$variant = $item->getVariant();
Assert::notNull($variant);

/** @var TaxRateInterface|null $taxRate */
$taxRate = $this->taxRateResolver->resolve($item->getVariant(), ['zone' => $zone]);
$taxRate = $this->taxRateResolver->resolve($variant, ['zone' => $zone]);
if (null === $taxRate) {
continue;
}
Expand All @@ -90,10 +95,14 @@ public function apply(OrderInterface $order, ZoneInterface $zone): void

private function addAdjustment(OrderItemUnitInterface $unit, int $taxAmount, TaxRateInterface $taxRate): void
{
/** @var string|null $label */
$label = $taxRate->getLabel();
Assert::notNull($label);

/** @var AdjustmentInterface $unitTaxAdjustment */
$unitTaxAdjustment = $this->adjustmentFactory->createWithData(
AdjustmentInterface::TAX_ADJUSTMENT,
$taxRate->getLabel(),
$label,
$taxAmount,
$taxRate->isIncludedInPrice()
);
Expand Down
6 changes: 5 additions & 1 deletion src/TaxesApplicator/OrderShipmentTaxesApplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ private function addAdjustment(
TaxRateInterface $taxRate,
ShippingMethodInterface $shippingMethod
): void {
/** @var string|null $label */
$label = $taxRate->getLabel();
Assert::notNull($label);

/** @var AdjustmentInterface $adjustment */
$adjustment = $this->adjustmentFactory->createWithData(
AdjustmentInterface::TAX_ADJUSTMENT,
$taxRate->getLabel(),
$label,
$taxAmount,
$taxRate->isIncludedInPrice()
);
Expand Down

0 comments on commit 0e47a15

Please sign in to comment.