Skip to content

Commit

Permalink
Making phpstan level higher
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Sep 21, 2019
1 parent 493ef8e commit f7f6bbb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: 4
level: 6
excludes_analyse:
# Makes PHPStan crash
- src/DependencyInjection/Configuration.php

ignoreErrors:
- /^Access to an undefined property Symfony\\Component\\Validator\\Constraint::\$message\.$/
- '/^Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.$/'
- '/Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\)/'
- '/Sylius\\Component\\Core\\Model\\(\w+), Sylius\\Component\\\w+\\Model\\\1 given\./'
6 changes: 5 additions & 1 deletion src/Controller/Customer/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sylius\ShopApiPlugin\View\ValidationErrorView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Webmozart\Assert\Assert;

final class CustomerController extends ResourceController
{
Expand All @@ -24,8 +25,11 @@ public function createAction(Request $request): Response
/** @var ViewHandlerInterface $viewHandler */
$viewHandler = $this->get('fos_rest.view_handler');

$validationResults = $response->getContent();
Assert::string($validationResults);

return $viewHandler
->handle(View::create($this->createValidationMessage($response->getContent()), Response::HTTP_BAD_REQUEST))
->handle(View::create($this->createValidationMessage($validationResults), Response::HTTP_BAD_REQUEST))
;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Factory/Checkout/PaymentViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\ShopApiPlugin\Factory\PriceViewFactoryInterface;
use Sylius\ShopApiPlugin\View\Cart\PaymentView;
use Webmozart\Assert\Assert;

final class PaymentViewFactory implements PaymentViewFactoryInterface
{
Expand Down Expand Up @@ -36,7 +37,10 @@ public function create(PaymentInterface $payment, string $locale): PaymentView
$paymentView = new $this->paymentViewClass();

$paymentView->state = $payment->getState();
$paymentView->method = $this->paymentMethodViewFactory->create($payment->getMethod(), $locale);
$paymentMethod = $payment->getMethod();
Assert::notNull($paymentMethod);

$paymentView->method = $this->paymentMethodViewFactory->create($paymentMethod, $locale);
$paymentView->price = $this->priceViewFactory->create($payment->getAmount(), $payment->getCurrencyCode());

return $paymentView;
Expand Down
6 changes: 5 additions & 1 deletion src/Factory/Checkout/ShippingMethodViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sylius\Component\Shipping\Calculator\CalculatorInterface;
use Sylius\ShopApiPlugin\Factory\PriceViewFactoryInterface;
use Sylius\ShopApiPlugin\View\Cart\ShippingMethodView;
use Webmozart\Assert\Assert;

final class ShippingMethodViewFactory implements ShippingMethodViewFactoryInterface
{
Expand All @@ -35,7 +36,10 @@ public function __construct(
/** {@inheritdoc} */
public function create(ShipmentInterface $shipment, string $locale, string $currency): ShippingMethodView
{
return $this->createWithShippingMethod($shipment, $shipment->getMethod(), $locale, $currency);
$shippingMethod = $shipment->getMethod();
Assert::notNull($shippingMethod);

return $this->createWithShippingMethod($shipment, $shippingMethod, $locale, $currency);
}

/** {@inheritdoc} */
Expand Down
4 changes: 3 additions & 1 deletion src/Shipping/ShippingCostEstimator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public function estimate(
$shippingMethod = $shippingMethods[0];

/** @var CalculatorInterface $calculator */
$calculator = $this->calculators->get($shippingMethod->getCalculator());
$calculatorName = $shippingMethod->getCalculator();
Assert::notNull($calculatorName);
$calculator = $this->calculators->get($calculatorName);

$value = $calculator->calculate($shipment, $shippingMethod->getConfiguration());
$currencyCode = $cart->getCurrencyCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function getByProductCode(string $productCode, string $channelCode, Pagin
$channel = $this->getChannel($channelCode);

$product = $this->productRepository->findOneByCode($productCode);
Assert::notNull($product);
Assert::true($product->hasChannel($channel));

$reviews = $this->productReviewRepository->findBy(['reviewSubject' => $product->getId(), 'status' => ReviewInterface::STATUS_ACCEPTED]);
Expand Down

0 comments on commit f7f6bbb

Please sign in to comment.