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

Making phpstan level higher #550

Merged
merged 1 commit into from
Sep 21, 2019
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
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
5 changes: 4 additions & 1 deletion src/Shipping/ShippingCostEstimator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public function estimate(

$shippingMethod = $shippingMethods[0];

$calculatorName = $shippingMethod->getCalculator();
Assert::notNull($calculatorName);

/** @var CalculatorInterface $calculator */
$calculator = $this->calculators->get($shippingMethod->getCalculator());
$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