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 304185b + 04cc862 commit dd5af4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Validator/ProductVariantCombinationValidator.php
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
7 changes: 7 additions & 0 deletions Validator/UniqueSimpleProductCodeValidator.php
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

0 comments on commit dd5af4b

Please sign in to comment.