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

PHPStan 0.10 upgrade & road to level 2 checks #9540

Merged
merged 7 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix constraint class related ambiguities in validators
  • Loading branch information
pamil committed Jul 1, 2018
commit 66deb99829d7dfc379eadf4cb0d88b6b5f3d07c2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function validate($value, Constraint $constraint): void
);
}

/** @var ProvinceAddressConstraint $constraint */
Assert::isInstanceOf($constraint, ProvinceAddressConstraint::class);

$propertyPath = $this->context->getPropertyPath();

foreach (iterator_to_array($this->context->getViolations()) as $violation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function validate($attribute, Constraint $constraint): void
{
/** @var AttributeInterface $attribute */
Assert::isInstanceOf($attribute, AttributeInterface::class);

/** @var ValidSelectAttributeConfiguration $constraint */
Assert::isInstanceOf($constraint, ValidSelectAttributeConfiguration::class);

if (SelectAttributeType::TYPE !== $attribute->getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function validate($attribute, Constraint $constraint): void
{
/** @var AttributeInterface $attribute */
Assert::isInstanceOf($attribute, AttributeInterface::class);

/** @var ValidTextAttributeConfiguration $constraint */
Assert::isInstanceOf($constraint, ValidTextAttributeConfiguration::class);

if (TextAttributeType::TYPE !== $attribute->getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ final class HasAllVariantPricesDefinedValidator extends ConstraintValidator
*/
public function validate($product, Constraint $constraint): void
{
/** @var ProductInterface $product */
Assert::isInstanceOf($product, ProductInterface::class);

/** @var HasAllVariantPricesDefined $constraint */
Assert::isInstanceOf($constraint, HasAllVariantPricesDefined::class);

if ($product->isSimple()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ final class OrderPaymentMethodEligibilityValidator extends ConstraintValidator
*/
public function validate($order, Constraint $constraint): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

/** @var OrderPaymentMethodEligibility $constraint */
Assert::isInstanceOf($constraint, OrderPaymentMethodEligibility::class);

$payments = $order->getPayments();

foreach ($payments as $payment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ final class OrderProductEligibilityValidator extends ConstraintValidator
*/
public function validate($order, Constraint $constraint): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

/** @var OrderProductEligibility $constraint */
Assert::isInstanceOf($constraint, OrderProductEligibility::class);

/** @var OrderItemInterface[] $orderItems */
$orderItems = $order->getItems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ public function __construct(ShippingMethodEligibilityCheckerInterface $methodEli
*/
public function validate($order, Constraint $constraint): void
{
/** @var OrderInterface $order */
Assert::isInstanceOf($order, OrderInterface::class);

/** @var OrderShippingMethodEligibility $constraint */
Assert::isInstanceOf($constraint, OrderShippingMethodEligibility::class);

$shipments = $order->getShipments();
if ($shipments->isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Webmozart\Assert\Assert;

final class RegisteredUserValidator extends ConstraintValidator
{
Expand All @@ -37,6 +38,9 @@ public function __construct(RepositoryInterface $customerRepository)
*/
public function validate($customer, Constraint $constraint): void
{
/** @var RegisteredUser $constraint */
Assert::isInstanceOf($constraint, RegisteredUser::class);

$existingCustomer = $this->customerRepository->findOneBy(['email' => $customer->getEmail()]);
if (null !== $existingCustomer && null !== $existingCustomer->getUser()) {
$this->context->buildViolation($constraint->message)->atPath('email')->addViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Webmozart\Assert\Assert;

class UniqueReviewerEmailValidator extends ConstraintValidator
{
Expand Down Expand Up @@ -60,6 +61,9 @@ public function __construct(
*/
public function validate($review, Constraint $constraint): void
{
/** @var UniqueReviewerEmail $constraint */
Assert::isInstanceOf($constraint, UniqueReviewerEmail::class);

/** @var ReviewerInterface|null $customer */
$customer = $review->getAuthor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Webmozart\Assert\Assert;

class DifferentSourceTargetCurrencyValidator extends ConstraintValidator
{
Expand All @@ -25,6 +26,9 @@ class DifferentSourceTargetCurrencyValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
/** @var DifferentSourceTargetCurrency $constraint */
Assert::isInstanceOf($constraint, DifferentSourceTargetCurrency::class);

if (!$value instanceof ExchangeRateInterface) {
throw new UnexpectedTypeException($value, ExchangeRateInterface::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Webmozart\Assert\Assert;

class UniqueCurrencyPairValidator extends ConstraintValidator
{
Expand All @@ -40,6 +41,9 @@ public function __construct(ExchangeRateRepositoryInterface $exchangeRateReposit
*/
public function validate($value, Constraint $constraint)
{
/** @var UniqueCurrencyPair $constraint */
Assert::isInstanceOf($constraint, UniqueCurrencyPair::class);

if (!$value instanceof ExchangeRateInterface) {
throw new UnexpectedTypeException($value, ExchangeRateInterface::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

namespace Sylius\Bundle\ProductBundle\Validator;

use Sylius\Bundle\ProductBundle\Validator\Constraint\ProductVariantCombination;
use Sylius\Component\Product\Checker\ProductVariantsParityCheckerInterface;
use Sylius\Component\Product\Model\ProductVariantInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Webmozart\Assert\Assert;

final class ProductVariantCombinationValidator extends ConstraintValidator
{
Expand All @@ -39,6 +41,9 @@ public function __construct(ProductVariantsParityCheckerInterface $variantsParit
*/
public function validate($value, Constraint $constraint): void
{
/** @var ProductVariantCombination $constraint */
Assert::isInstanceOf($constraint, ProductVariantCombination::class);

if (!$value instanceof ProductVariantInterface) {
throw new UnexpectedTypeException($value, ProductVariantInterface::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

namespace Sylius\Bundle\ProductBundle\Validator;

use Sylius\Bundle\ProductBundle\Validator\Constraint\UniqueSimpleProductCode;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductVariantInterface;
use Sylius\Component\Product\Repository\ProductVariantRepositoryInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Webmozart\Assert\Assert;

final class UniqueSimpleProductCodeValidator extends ConstraintValidator
{
Expand All @@ -39,6 +42,9 @@ public function __construct(ProductVariantRepositoryInterface $productVariantRep
*/
public function validate($value, Constraint $constraint): void
{
/** @var UniqueSimpleProductCode $constraint */
Assert::isInstanceOf($constraint, UniqueSimpleProductCode::class);

if (!$value instanceof ProductInterface) {
throw new UnexpectedTypeException($value, ProductInterface::class);
}
Expand All @@ -47,6 +53,7 @@ public function validate($value, Constraint $constraint): void
return;
}

/** @var ProductVariantInterface $existingProductVariant */
$existingProductVariant = $this->productVariantRepository->findOneBy(['code' => $value->getCode()]);

if (null !== $existingProductVariant && $existingProductVariant->getProduct()->getId() !== $value->getId()) {
Expand Down