Skip to content

Commit

Permalink
Merge pull request Sylius#9540 from pamil/1.1-phpstan-fixes
Browse files Browse the repository at this point in the history
PHPStan 0.10 upgrade & road to level 2 checks
  • Loading branch information
pamil authored Jul 3, 2018
2 parents ccb39c5 + 21ceb5e commit 2cc6a20
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Cart/Context/ShopBasedCartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
use Sylius\Component\Core\Context\ShopperContextInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Currency\Context\CurrencyNotFoundException;
use Sylius\Component\Locale\Context\LocaleNotFoundException;
use Sylius\Component\Order\Context\CartContextInterface;
use Sylius\Component\Order\Context\CartNotFoundException;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Webmozart\Assert\Assert;

final class ShopBasedCartContext implements CartContextInterface
{
Expand Down Expand Up @@ -53,14 +55,15 @@ public function __construct(CartContextInterface $cartContext, ShopperContextInt
/**
* {@inheritdoc}
*/
public function getCart(): OrderInterface
public function getCart(): BaseOrderInterface
{
if (null !== $this->cart) {
return $this->cart;
}

/** @var OrderInterface $cart */
$cart = $this->cartContext->getCart();
Assert::isInstanceOf($cart, OrderInterface::class);

try {
/** @var ChannelInterface $channel */
Expand Down
2 changes: 2 additions & 0 deletions Factory/PaymentMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Component\Core\Factory;

use Payum\Core\Model\GatewayConfigInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

Expand Down Expand Up @@ -51,6 +52,7 @@ public function createNew(): PaymentMethodInterface
*/
public function createWithGateway(string $gatewayFactory): PaymentMethodInterface
{
/** @var GatewayConfigInterface $gatewayConfig */
$gatewayConfig = $this->gatewayConfigFactory->createNew();
$gatewayConfig->setFactoryName($gatewayFactory);

Expand Down
11 changes: 11 additions & 0 deletions Model/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\Collections\Collection;
use Sylius\Component\Channel\Model\ChannelAwareInterface;
use Sylius\Component\Channel\Model\ChannelInterface as BaseChannelInterface;
use Sylius\Component\Customer\Model\CustomerAwareInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Payment\Model\PaymentsSubjectInterface;
Expand Down Expand Up @@ -198,4 +199,14 @@ public function getCustomerIp(): ?string;
* @param string|null $customerIp
*/
public function setCustomerIp(?string $customerIp): void;

/**
* @return Collection|OrderItemInterface[]
*/
public function getItems(): Collection;

/**
* @return ChannelInterface|null
*/
public function getChannel(): ?BaseChannelInterface;
}
5 changes: 5 additions & 0 deletions Model/PaymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
namespace Sylius\Component\Core\Model;

use Sylius\Component\Order\Model\OrderAwareInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface;

interface PaymentInterface extends BasePaymentInterface, OrderAwareInterface
{
/**
* @return OrderInterface|null
*/
public function getOrder(): ?BaseOrderInterface;
}
5 changes: 5 additions & 0 deletions Model/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
namespace Sylius\Component\Core\Model;

use Sylius\Component\Order\Model\OrderAwareInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Shipping\Model\ShipmentInterface as BaseShipmentInterface;

interface ShipmentInterface extends BaseShipmentInterface, OrderAwareInterface
{
/**
* @return OrderInterface|null
*/
public function getOrder(): ?BaseOrderInterface;
}
1 change: 1 addition & 0 deletions OrderProcessing/ShippingChargesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function process(BaseOrderInterface $order): void
try {
$shippingCharge = $this->shippingChargesCalculator->calculate($shipment);

/** @var AdjustmentInterface $adjustment */
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
$adjustment->setAmount($shippingCharge);
Expand Down
6 changes: 5 additions & 1 deletion Promotion/Action/DiscountPromotionActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ abstract protected function isConfigurationValid(array $configuration): void;
*/
public function revert(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): void
{
/** @var OrderInterface $subject */
Assert::isInstanceOf($subject, OrderInterface::class);

if (!$this->isSubjectValid($subject)) {
return;
}
Expand All @@ -55,7 +58,8 @@ public function revert(PromotionSubjectInterface $subject, array $configuration,
*/
protected function isSubjectValid(PromotionSubjectInterface $subject): bool
{
Assert::implementsInterface($subject, OrderInterface::class);
/** @var OrderInterface $subject */
Assert::isInstanceOf($subject, OrderInterface::class);

return 0 !== $subject->countItems();
}
Expand Down
4 changes: 4 additions & 0 deletions Promotion/Action/FixedDiscountPromotionActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Component\Core\Promotion\Action;

use Sylius\Component\Core\Distributor\ProportionalIntegerDistributorInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Promotion\Applicator\UnitsPromotionAdjustmentsApplicatorInterface;
use Sylius\Component\Promotion\Model\PromotionInterface;
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
Expand Down Expand Up @@ -50,6 +51,9 @@ public function __construct(
*/
public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): bool
{
/** @var OrderInterface $subject */
Assert::isInstanceOf($subject, OrderInterface::class);

if (!$this->isSubjectValid($subject)) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions Promotion/Action/PercentageDiscountPromotionActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sylius\Component\Promotion\Action\PromotionActionCommandInterface;
use Sylius\Component\Promotion\Model\PromotionInterface;
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
use Webmozart\Assert\Assert;

final class PercentageDiscountPromotionActionCommand extends DiscountPromotionActionCommand implements PromotionActionCommandInterface
{
Expand Down Expand Up @@ -52,6 +53,8 @@ public function __construct(
public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): bool
{
/** @var OrderInterface $subject */
Assert::isInstanceOf($subject, OrderInterface::class);

if (!$this->isSubjectValid($subject)) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions Resolver/ChannelBasedPaymentMethodsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepos
*/
public function getSupportedMethods(BasePaymentInterface $payment): array
{
/** @var PaymentInterface $payment */
Assert::isInstanceOf($payment, PaymentInterface::class);
Assert::true($this->supports($payment), 'This payment method is not support by resolver');

return $this->paymentMethodRepository->findEnabledForChannel($payment->getOrder()->getChannel());
Expand Down
10 changes: 5 additions & 5 deletions Resolver/DefaultPaymentMethodResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace Sylius\Component\Core\Resolver;

use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\PaymentInterface as CorePaymentInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\Component\Payment\Exception\UnresolvedDefaultPaymentMethodException;
use Sylius\Component\Payment\Model\PaymentInterface;
use Sylius\Component\Payment\Model\PaymentInterface as BasePaymentInterface;
use Sylius\Component\Payment\Model\PaymentMethodInterface;
use Sylius\Component\Payment\Resolver\DefaultPaymentMethodResolverInterface;
use Webmozart\Assert\Assert;
Expand All @@ -42,10 +42,10 @@ public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepos
*
* @throws UnresolvedDefaultPaymentMethodException
*/
public function getDefaultPaymentMethod(PaymentInterface $subject): PaymentMethodInterface
public function getDefaultPaymentMethod(BasePaymentInterface $subject): PaymentMethodInterface
{
/** @var CorePaymentInterface $subject */
Assert::isInstanceOf($subject, CorePaymentInterface::class);
/** @var PaymentInterface $subject */
Assert::isInstanceOf($subject, PaymentInterface::class);

/** @var ChannelInterface $channel */
$channel = $subject->getOrder()->getChannel();
Expand Down
2 changes: 2 additions & 0 deletions Resolver/ZoneAndChannelBasedShippingMethodsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function __construct(
public function getSupportedMethods(ShippingSubjectInterface $subject): array
{
/** @var ShipmentInterface $subject */
Assert::isInstanceOf($subject, ShipmentInterface::class);
Assert::true($this->supports($subject));

/** @var OrderInterface $order */
$order = $subject->getOrder();

Expand Down
1 change: 1 addition & 0 deletions Shipping/Calculator/PerUnitRateCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class PerUnitRateCalculator implements CalculatorInterface
*/
public function calculate(BaseShipmentInterface $subject, array $configuration): int
{
/** @var ShipmentInterface $subject */
Assert::isInstanceOf($subject, ShipmentInterface::class);

$channelCode = $subject->getOrder()->getChannel()->getCode();
Expand Down
9 changes: 7 additions & 2 deletions StateResolver/OrderPaymentStateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
use Doctrine\Common\Collections\Collection;
use SM\Factory\FactoryInterface;
use SM\StateMachine\StateMachineInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderPaymentTransitions;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Order\StateResolver\StateResolverInterface;
use Webmozart\Assert\Assert;

final class OrderPaymentStateResolver implements StateResolverInterface
{
Expand All @@ -39,8 +41,11 @@ public function __construct(FactoryInterface $stateMachineFactory)
/**
* {@inheritdoc}
*/
public function resolve(OrderInterface $order): void
public function resolve(BaseOrderInterface $order): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

$stateMachine = $this->stateMachineFactory->get($order, OrderPaymentTransitions::GRAPH);
$targetTransition = $this->getTargetTransition($order);

Expand Down
4 changes: 4 additions & 0 deletions StateResolver/OrderShippingStateResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sylius\Component\Core\OrderShippingTransitions;
use Sylius\Component\Order\Model\OrderInterface as BaseOrderInterface;
use Sylius\Component\Order\StateResolver\StateResolverInterface;
use Webmozart\Assert\Assert;

final class OrderShippingStateResolver implements StateResolverInterface
{
Expand All @@ -42,6 +43,9 @@ public function __construct(FactoryInterface $stateMachineFactory)
*/
public function resolve(BaseOrderInterface $order): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

if (OrderShippingStates::STATE_SHIPPED === $order->getShippingState()) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions Test/Services/DefaultChannelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private function provideCurrency(?string $currencyCode): CurrencyInterface
$currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);

if (null === $currency) {
/** @var CurrencyInterface $currency */
$currency = $this->currencyFactory->createNew();
$currency->setCode($currencyCode);

Expand All @@ -147,6 +148,7 @@ private function provideLocale(): LocaleInterface
$locale = $this->localeRepository->findOneBy(['code' => $this->defaultLocaleCode]);

if (null === $locale) {
/** @var LocaleInterface $locale */
$locale = $this->localeFactory->createNew();
$locale->setCode($this->defaultLocaleCode);

Expand Down
2 changes: 2 additions & 0 deletions Test/Services/DefaultUnitedStatesChannelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private function provideCurrency(?string $currencyCode = null): CurrencyInterfac
$currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);

if (null === $currency) {
/** @var CurrencyInterface $currency */
$currency = $this->currencyFactory->createNew();
$currency->setCode($currencyCode);

Expand All @@ -211,6 +212,7 @@ private function provideLocale(): LocaleInterface
$locale = $this->localeRepository->findOneBy(['code' => $this->defaultLocaleCode]);

if (null === $locale) {
/** @var LocaleInterface $locale */
$locale = $this->localeFactory->createNew();
$locale->setCode($this->defaultLocaleCode);

Expand Down
2 changes: 1 addition & 1 deletion Test/Services/EmailChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function isMessageTo(\Swift_Message $message, string $recipient): bool
/**
* @param string $recipient
*
* @throws /InvalidArgumentException
* @throws \InvalidArgumentException
*/
private function assertRecipientIsValid(string $recipient): void
{
Expand Down

0 comments on commit 2cc6a20

Please sign in to comment.