Lower PHPStan level 2 errors from 222 to 15

This commit is contained in:
Kamil Kokot 2018-07-03 18:22:06 +02:00
parent e28562e00b
commit 261c614f0e
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
63 changed files with 249 additions and 171 deletions

View file

@ -29,6 +29,8 @@ parameters:
- '/Call to an undefined method Faker\\Generator::/'
- '/Access to an undefined property Faker\\Generator::/'
- '/Method Mockery\\MockInterface::shouldReceive\(\) invoked with 1 parameter, 0 required/'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface/'
- '/Call to an undefined method Mockery\\ExpectationInterface|Mockery\\HigherOrderMessage::/'
# These packages aren't in require-dev of the global package
- '/Class Doctrine\\Bundle\\MongoDBBundle/'

View file

@ -15,9 +15,9 @@ namespace Sylius\Behat\Context\Api\Admin;
use Behat\Behat\Context\Context;
use Sylius\Component\Core\Model\ProductInterface;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Client;
use Webmozart\Assert\Assert;
final class ManagingProductVariantsContext implements Context

View file

@ -15,9 +15,9 @@ namespace Sylius\Behat\Context\Api\Admin;
use Behat\Behat\Context\Context;
use Sylius\Component\Core\Model\TaxonInterface;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Client;
use Webmozart\Assert\Assert;
final class ManagingTaxonsContext implements Context

View file

@ -57,7 +57,9 @@ final class AdminUserContext implements Context
*/
public function thereIsAnAdministratorIdentifiedBy($email, $password = 'sylius')
{
/** @var AdminUserInterface $adminUser */
$adminUser = $this->userFactory->create(['email' => $email, 'password' => $password, 'enabled' => true]);
$this->userRepository->add($adminUser);
$this->sharedStorage->set('administrator', $adminUser);
}
@ -67,6 +69,7 @@ final class AdminUserContext implements Context
*/
public function thereIsAnAdministratorWithName($username)
{
/** @var AdminUserInterface $adminUser */
$adminUser = $this->userFactory->create(['username' => $username]);
$adminUser->setUsername($username);

View file

@ -17,7 +17,9 @@ use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
@ -190,6 +192,8 @@ final class CustomerContext implements Context
public function thereIsUserIdentifiedByWithAsShippingCountry($email, CountryInterface $country)
{
$customer = $this->createCustomerWithUserAccount($email, 'password123', true, 'John', 'Doe');
/** @var AddressInterface $address */
$address = $this->addressFactory->createNew();
$address->setCountryCode($country->getCode());
$address->setCity('Berlin');
@ -252,7 +256,9 @@ final class CustomerContext implements Context
$lastName = null,
$role = null
) {
/** @var ShopUserInterface $user */
$user = $this->userFactory->createNew();
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();

View file

@ -778,6 +778,7 @@ final class OrderContext implements Context
$customers = [];
for ($i = 0; $i < $count; ++$i) {
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail(sprintf('john%s@doe.com', uniqid()));
$customer->setFirstname('John');
@ -791,14 +792,9 @@ final class OrderContext implements Context
return $customers;
}
/**
* @param string $price
*
* @return int
*/
private function getPriceFromString($price)
private function getPriceFromString(string $price): int
{
return (int) round(str_replace(['€', '£', '$'], '', $price) * 100, 2);
return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
}
/**
@ -847,6 +843,7 @@ final class OrderContext implements Context
*/
private function addVariantWithPriceToOrder(OrderInterface $order, ProductVariantInterface $variant, $price)
{
/** @var OrderItemInterface $item */
$item = $this->orderItemFactory->createNew();
$item->setVariant($variant);
$item->setUnitPrice($price);

View file

@ -198,10 +198,10 @@ final class ProductAssociationContext implements Context
*/
private function addProductAssociationTypeTranslation(
ProductAssociationTypeInterface $productAssociationType,
$name,
$locale
string $name,
string $locale
) {
/** @var ProductAssociationTypeTranslationInterface|TranslationInterface $translation */
/** @var ProductAssociationTypeTranslationInterface $translation */
$translation = $this->productAssociationTypeTranslationFactory->createNew();
$translation->setLocale($locale);
$translation->setName($name);

View file

@ -792,14 +792,9 @@ final class ProductContext implements Context
$this->objectManager->flush();
}
/**
* @param string $price
*
* @return int
*/
private function getPriceFromString($price)
private function getPriceFromString(string $price): int
{
return (int) round($price * 100, 2);
return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
}
/**
@ -934,9 +929,10 @@ final class ProductContext implements Context
*/
private function addProductTranslation(ProductInterface $product, $name, $locale)
{
/** @var ProductTranslationInterface|TranslationInterface $translation */
/** @var ProductTranslationInterface $translation */
$translation = $product->getTranslation($locale);
if ($translation->getLocale() !== $locale) {
/** @var ProductTranslationInterface $translation */
$translation = $this->productTranslationFactory->createNew();
}
@ -954,7 +950,7 @@ final class ProductContext implements Context
*/
private function addProductVariantTranslation(ProductVariantInterface $productVariant, $name, $locale)
{
/** @var ProductVariantTranslationInterface|TranslationInterface $translation */
/** @var ProductVariantTranslationInterface $translation */
$translation = $this->productVariantTranslationFactory->createNew();
$translation->setLocale($locale);
$translation->setName($name);

View file

@ -677,6 +677,7 @@ final class PromotionContext implements Context
$discount,
CustomerGroupInterface $customerGroup
) {
/** @var PromotionRuleInterface $rule */
$rule = $this->ruleFactory->createNew();
$rule->setType(CustomerGroupRuleChecker::TYPE);
$rule->setConfiguration(['group_code' => $customerGroup->getCode()]);

View file

@ -184,7 +184,7 @@ final class TaxonomyContext implements Context
$taxon = $this->taxonFactory->createNew();
$taxon->setCode(StringInflector::nameToCode($names['en_US']));
foreach ($names as $locale => $name) {
/** @var TranslationInterface|TaxonTranslationInterface $taxonTranslation */
/** @var TaxonTranslationInterface $taxonTranslation */
$taxonTranslation = $this->taxonTranslationFactory->createNew();
$taxonTranslation->setLocale($locale);
$taxonTranslation->setName($name);

View file

@ -60,6 +60,7 @@ final class CustomerContext implements Context
/** @var CustomerInterface $customer */
$customer = $this->customerRepository->findOneBy(['email' => $email]);
if (null === $customer) {
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($email);

View file

@ -20,21 +20,23 @@ final class LexicalContext implements Context
/**
* @Transform /^"(\-)?(?:€|£|¥|\$)((?:\d+\.)?\d+)"$/
*/
public function getPriceFromString($sign, $price)
public function getPriceFromString(string $sign, string $price): int
{
$this->validatePriceString($price);
$price = (int) round((float) $price * 100, 2);
if ('-' === $sign) {
$price *= -1;
}
return (int) round($price * 100, 2);
return $price;
}
/**
* @Transform /^"((?:\d+\.)?\d+)%"$/
*/
public function getPercentageFromString($percentage)
public function getPercentageFromString(string $percentage): float
{
return ((int) $percentage) / 100;
}
@ -44,7 +46,7 @@ final class LexicalContext implements Context
*
* @throws \InvalidArgumentException
*/
private function validatePriceString($price)
private function validatePriceString(string $price): void
{
if (!(bool) preg_match('/^\d+(?:\.\d{1,2})?$/', $price)) {
throw new \InvalidArgumentException('Price string should not have more than 2 decimal digits.');

View file

@ -151,17 +151,6 @@ final class ManagingPaymentMethodsContext implements Context
$this->notificationChecker->checkNotification('Cannot delete, the payment method is in use.', NotificationType::failure());
}
/**
* @When I choose :gatewayName gateway
*/
public function iChooseGateway($gatewayName)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
$currentPage->chooseGateway($gatewayName);
}
/**
* @Then this payment method :element should be :value
*/

View file

@ -193,6 +193,7 @@ final class ManagingProductAttributesContext implements Context
*/
public function theTypeFieldShouldBeDisabled()
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
Assert::true($currentPage->isTypeDisabled());

View file

@ -142,6 +142,7 @@ final class ManagingProductOptionsContext implements Context
*/
public function iAddTheOptionValueWithCodeAndValue($value, $code)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
$currentPage->addOptionValue($code, $value);

View file

@ -115,14 +115,6 @@ final class ManagingProductVariantsContext implements Context
$this->createPage->nameItIn($name, $language);
}
/**
* @When I rename it to :name
*/
public function iRenameItTo($name)
{
$this->updatePage->nameIt($name);
}
/**
* @When I add it
* @When I try to add it
@ -418,14 +410,6 @@ final class ManagingProductVariantsContext implements Context
$this->updatePage->saveChanges();
}
/**
* @When I remove its name
*/
public function iRemoveItsNameFromTranslation()
{
$this->updatePage->nameIt('');
}
/**
* @Then /^inventory of (this variant) should not be tracked$/
*/

View file

@ -144,6 +144,7 @@ final class ManagingProductsContext implements Context
*/
public function iSpecifyItsCodeAs($code = null)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->specifyCode($code);
@ -987,7 +988,7 @@ final class ManagingProductsContext implements Context
}
/**
* @return SymfonyPageInterface|IndexPageInterface|IndexPerTaxonPageInterface|CreateSimpleProductPageInterface|CreateConfigurableProductPageInterface|UpdateSimpleProductPageInterface|UpdateConfigurableProductPageInterface
* @return IndexPageInterface|IndexPerTaxonPageInterface|CreateSimpleProductPageInterface|CreateConfigurableProductPageInterface|UpdateSimpleProductPageInterface|UpdateConfigurableProductPageInterface
*/
private function resolveCurrentPage()
{

View file

@ -350,6 +350,7 @@ final class ManagingPromotionsContext implements Context
*/
public function iSetItsUsageLimitTo($usageLimit)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
$currentPage->fillUsageLimit($usageLimit);

View file

@ -15,8 +15,8 @@ namespace Sylius\Behat\Context\Ui\Admin;
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface;
use Sylius\Behat\Page\Admin\ShippingCategory\CreatePageInterface;
use Sylius\Behat\Page\Admin\ShippingCategory\UpdatePageInterface;
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
use Webmozart\Assert\Assert;

View file

@ -408,7 +408,7 @@ final class ManagingTaxonsContext implements Context
}
/**
* @return SymfonyPageInterface|CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface
* @return CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface
*/
private function resolveCurrentPage()
{

View file

@ -170,11 +170,10 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatElementIsRequired($element)
{
$this->assertFieldValidationMessage(
$this->profileUpdatePage,
Assert::true($this->profileUpdatePage->checkValidationMessageFor(
StringInflector::nameToCode($element),
sprintf('Please enter your %s.', $element)
);
));
}
/**
@ -182,11 +181,10 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatElementIsInvalid($element)
{
$this->assertFieldValidationMessage(
$this->profileUpdatePage,
Assert::true($this->profileUpdatePage->checkValidationMessageFor(
StringInflector::nameToCode($element),
sprintf('This %s is invalid.', $element)
);
));
}
/**
@ -194,7 +192,7 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed()
{
$this->assertFieldValidationMessage($this->profileUpdatePage, 'email', 'This email is already used.');
Assert::true($this->profileUpdatePage->checkValidationMessageFor('email', 'This email is already used.'));
}
/**
@ -252,11 +250,10 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne()
{
$this->assertFieldValidationMessage(
$this->changePasswordPage,
Assert::true($this->changePasswordPage->checkValidationMessageFor(
'current_password',
'Provided password is different than the current one.'
);
));
}
/**
@ -264,11 +261,10 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch()
{
$this->assertFieldValidationMessage(
$this->changePasswordPage,
Assert::true($this->changePasswordPage->checkValidationMessageFor(
'new_password',
'The entered passwords don\'t match'
);
));
}
/**
@ -276,11 +272,10 @@ final class AccountContext implements Context
*/
public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong()
{
$this->assertFieldValidationMessage(
$this->changePasswordPage,
Assert::true($this->changePasswordPage->checkValidationMessageFor(
'new_password',
'Password must be at least 4 characters long.'
);
));
}
/**
@ -452,14 +447,4 @@ final class AccountContext implements Context
{
$this->loginPage->tryToOpen();
}
/**
* @param PageInterface $page
* @param string $element
* @param string $expectedMessage
*/
private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage)
{
Assert::true($page->checkValidationMessageFor($element, $expectedMessage));
}
}

View file

@ -423,13 +423,8 @@ final class CartContext implements Context
Assert::same($this->summaryPage->getCartTotal(), $total);
}
/**
* @param string $price
*
* @return int
*/
private function getPriceFromString($price)
private function getPriceFromString(string $price): int
{
return (int) round(str_replace(['€', '£', '$'], '', $price) * 100, 2);
return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
}
}

View file

@ -95,11 +95,7 @@ final class ContactContext implements Context
*/
public function iShouldBeNotifiedThatElementIsRequired($element)
{
$this->assertFieldValidationMessage(
$this->contactPage,
$element,
sprintf('Please enter your %s.', $element)
);
Assert::same($this->contactPage->getValidationMessageFor($element), sprintf('Please enter your %s.', $element));
}
/**
@ -107,11 +103,7 @@ final class ContactContext implements Context
*/
public function iShouldBeNotifiedThatEmailIsInvalid()
{
$this->assertFieldValidationMessage(
$this->contactPage,
'email',
'This email is invalid.'
);
Assert::same($this->contactPage->getValidationMessageFor('email'), 'This email is invalid.');
}
/**
@ -124,14 +116,4 @@ final class ContactContext implements Context
NotificationType::failure()
);
}
/**
* @param PageInterface $page
* @param string $element
* @param string $expectedMessage
*/
private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage)
{
Assert::same($page->getValidationMessageFor($element), $expectedMessage);
}
}

View file

@ -17,6 +17,7 @@ use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Customer\ShowPageInterface;
use Sylius\Behat\Page\Shop\HomePageInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Webmozart\Assert\Assert;
@ -73,6 +74,7 @@ final class UserContext implements Context
*/
public function iDeleteAccount($email)
{
/** @var ShopUserInterface $user */
$user = $this->userRepository->findOneByEmail($email);
$this->sharedStorage->set('deleted_user', $user);

View file

@ -64,6 +64,11 @@ interface CreatePageInterface extends BaseCreatePageInterface
*/
public function hasCheckedCreateOption();
/**
* @return bool
*/
public function hasCreateOption();
/**
* @return bool
*/

View file

@ -27,4 +27,12 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
* @param AddressInterface $address
*/
public function specifyBillingAddress(AddressInterface $address);
/**
* @param string $element
* @param string $message
*
* @return bool
*/
public function checkValidationMessageFor($element, $message);
}

View file

@ -29,6 +29,7 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
*/
public function specifyPrice($price);
public function disableTracking();
public function enableTracking();

View file

@ -17,6 +17,16 @@ use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInteface;
interface CreatePageInterface extends BaseCreatePageInteface
{
/**
* @param string $code
*/
public function specifyCode($code);
/**
* @param string $name
*/
public function nameIt($name);
/**
* @param string $description
*/

View file

@ -15,7 +15,6 @@ namespace Sylius\Behat\Page\Admin\ShippingCategory;
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface;
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{

View file

@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Behat\Page\Admin\ShippingCategory;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInteface;
interface UpdatePageInterface extends BaseUpdatePageInteface
{
/**
* @return bool
*/
public function isCodeDisabled();
}

View file

@ -133,7 +133,7 @@ abstract class Page implements PageInterface
/**
* @param string $name
*
* @return NodeElement
* @return string
*/
protected function getParameter($name)
{

View file

@ -318,13 +318,8 @@ class SummaryPage extends SymfonyPage implements SummaryPageInterface
return false;
}
/**
* @param string $price
*
* @return int
*/
private function getPriceFromString($price)
private function getPriceFromString(string $price): int
{
return (int) round(str_replace(['€', '£', '$'], '', $price) * 100, 2);
return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
}
}

View file

@ -401,12 +401,7 @@ class CompletePage extends SymfonyPage implements CompletePageInterface
return strtoupper(Intl::getRegionBundle()->getCountryName($countryCode, 'en'));
}
/**
* @param string $price
*
* @return int
*/
private function getPriceFromString($price): int
private function getPriceFromString(string $price): int
{
return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2);
}

View file

@ -13,7 +13,9 @@ declare(strict_types=1);
namespace Sylius\Behat\Page\Shop\Product;
interface IndexPageInterface
use Sylius\Behat\Page\PageInterface;
interface IndexPageInterface extends PageInterface
{
/**
* @return int

View file

@ -46,13 +46,17 @@ final class CountryChoiceTypeTest extends TypeTestCase
{
$this->countryRepository = $this->prophesize(RepositoryInterface::class);
$this->france = $this->prophesize(CountryInterface::class);
$this->france->getCode()->willReturn('FR');
$this->france->getName()->willReturn('France');
/** @var ProphecyInterface|CountryInterface $france */
$france = $this->prophesize(CountryInterface::class);
$france->getCode()->willReturn('FR');
$france->getName()->willReturn('France');
$this->france = $france;
$this->poland = $this->prophesize(CountryInterface::class);
$this->poland->getCode()->willReturn('PL');
$this->poland->getName()->willReturn('Poland');
/** @var ProphecyInterface|CountryInterface $poland */
$poland = $this->prophesize(CountryInterface::class);
$poland->getCode()->willReturn('PL');
$poland->getName()->willReturn('Poland');
$this->poland = $poland;
parent::setUp();
}

View file

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Sylius\Bundle\AddressingBundle\Validator\Constraints;
use Sylius\Component\Addressing\Model\AddressInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ProvinceInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -76,7 +78,11 @@ class ProvinceAddressConstraintValidator extends ConstraintValidator
protected function isProvinceValid(AddressInterface $address): bool
{
$countryCode = $address->getCountryCode();
if (null === $country = $this->countryRepository->findOneBy(['code' => $countryCode])) {
/** @var CountryInterface|null $country */
$country = $this->countryRepository->findOneBy(['code' => $countryCode]);
if (null === $country) {
return true;
}
@ -88,7 +94,10 @@ class ProvinceAddressConstraintValidator extends ConstraintValidator
return false;
}
if (null === $province = $this->provinceRepository->findOneBy(['code' => $address->getProvinceCode()])) {
/** @var ProvinceInterface|null $province */
$province = $this->provinceRepository->findOneBy(['code' => $address->getProvinceCode()]);
if (null === $province) {
return false;
}

View file

@ -18,6 +18,7 @@ use GuzzleHttp\Exception\ConnectException;
use Http\Message\MessageFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ProphecyInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
@ -28,12 +29,12 @@ use Symfony\Component\HttpFoundation\Request;
final class NotificationControllerTest extends TestCase
{
/**
* @var ClientInterface
* @var ProphecyInterface|ClientInterface
*/
private $client;
/**
* @var MessageFactory
* @var ProphecyInterface|MessageFactory
*/
private $messageFactory;
@ -52,7 +53,7 @@ final class NotificationControllerTest extends TestCase
*/
public function it_returns_an_empty_json_response_upon_client_exception(): void
{
$this->messageFactory->createRequest(Argument::cetera())
$this->messageFactory->createRequest(Argument::any(), Argument::cetera())
->willReturn($this->prophesize(RequestInterface::class)->reveal())
;
@ -71,13 +72,15 @@ final class NotificationControllerTest extends TestCase
{
$content = json_encode(['version' => '9001']);
$this->messageFactory->createRequest(Argument::cetera())
$this->messageFactory->createRequest(Argument::any(), Argument::cetera())
->willReturn($this->prophesize(RequestInterface::class)->reveal())
;
/** @var ProphecyInterface|StreamInterface $stream */
$stream = $this->prophesize(StreamInterface::class);
$stream->getContents()->willReturn($content);
/** @var ProphecyInterface|ResponseInterface $externalResponse */
$externalResponse = $this->prophesize(ResponseInterface::class);
$externalResponse->getBody()->willReturn($stream->reveal());

View file

@ -71,6 +71,7 @@ final class LoadMetadataSubscriber implements EventSubscriber
ClassMetadataInfo $metadata,
ClassMetadataFactory $metadataFactory
): void {
/** @var ClassMetadataInfo $targetEntityMetadata */
$targetEntityMetadata = $metadataFactory->getMetadataFor($subjectClass);
$subjectMapping = [
'fieldName' => 'subject',
@ -97,6 +98,7 @@ final class LoadMetadataSubscriber implements EventSubscriber
ClassMetadataInfo $metadata,
ClassMetadataFactory $metadataFactory
): void {
/** @var ClassMetadataInfo $attributeMetadata */
$attributeMetadata = $metadataFactory->getMetadataFor($attributeClass);
$attributeMapping = [
'fieldName' => 'attribute',

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Command;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Bundle\CoreBundle\Installer\Executor\CommandExecutor;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\ProgressBar;
@ -59,7 +60,7 @@ abstract class AbstractInstallCommand extends ContainerAwareCommand
*/
protected function getEnvironment(): string
{
return $this->get('kernel')->getEnvironment();
return (string) $this->getContainer()->getParameter('kernel.environment');
}
/**
@ -67,7 +68,7 @@ abstract class AbstractInstallCommand extends ContainerAwareCommand
*/
protected function isDebug(): bool
{
return $this->get('kernel')->isDebug();
return (bool) $this->getContainer()->getParameter('kernel.debug');
}
/**
@ -126,7 +127,9 @@ abstract class AbstractInstallCommand extends ContainerAwareCommand
// PDO does not always close the connection after Doctrine commands.
// See https://github.com/symfony/symfony/issues/11750.
$this->get('doctrine')->getManager()->getConnection()->close();
/** @var EntityManagerInterface $entityManager */
$entityManager = $this->getContainer()->get('doctrine')->getManager();
$entityManager->getConnection()->close();
$progress->advance();
}
@ -140,7 +143,7 @@ abstract class AbstractInstallCommand extends ContainerAwareCommand
*/
protected function ensureDirectoryExistsAndIsWritable(string $directory, OutputInterface $output): void
{
$checker = $this->get('sylius.installer.checker.command_directory');
$checker = $this->getContainer()->get('sylius.installer.checker.command_directory');
$checker->setCommandName($this->getName());
$checker->ensureDirectoryExists($directory, $output);

View file

@ -39,7 +39,7 @@ EOT
*/
protected function execute(InputInterface $input, OutputInterface $output): void
{
$fulfilled = $this->get('sylius.installer.checker.sylius_requirements')->check($input, $output);
$fulfilled = $this->getContainer()->get('sylius.installer.checker.sylius_requirements')->check($input, $output);
if (!$fulfilled) {
throw new RuntimeException(

View file

@ -46,6 +46,7 @@ EOT
));
$commands = $this
->getContainer()
->get('sylius.commands_provider.database_setup')
->getCommands($input, $output, $this->getHelper('question'))
;

View file

@ -47,9 +47,9 @@ EOT
*/
protected function execute(InputInterface $input, OutputInterface $output): void
{
$currency = $this->get('sylius.setup.currency')->setup($input, $output, $this->getHelper('question'));
$locale = $this->get('sylius.setup.locale')->setup($input, $output);
$this->get('sylius.setup.channel')->setup($locale, $currency);
$currency = $this->getContainer()->get('sylius.setup.currency')->setup($input, $output, $this->getHelper('question'));
$locale = $this->getContainer()->get('sylius.setup.locale')->setup($input, $output);
$this->getContainer()->get('sylius.setup.channel')->setup($locale, $currency);
$this->setupAdministratorUser($input, $output, $locale->getCode());
}
@ -63,8 +63,8 @@ EOT
$outputStyle = new SymfonyStyle($input, $output);
$outputStyle->writeln('Create your administrator account.');
$userManager = $this->get('sylius.manager.admin_user');
$userFactory = $this->get('sylius.factory.admin_user');
$userManager = $this->getContainer()->get('sylius.manager.admin_user');
$userFactory = $this->getContainer()->get('sylius.factory.admin_user');
try {
$user = $this->configureNewUser($userFactory->createNew(), $input, $output);
@ -123,7 +123,7 @@ EOT
return (new Question('E-mail: '))
->setValidator(function ($value) {
/** @var ConstraintViolationListInterface $errors */
$errors = $this->get('validator')->validate((string) $value, [new Email(), new NotBlank()]);
$errors = $this->getContainer()->get('validator')->validate((string) $value, [new Email(), new NotBlank()]);
foreach ($errors as $error) {
throw new \DomainException($error->getMessage());
}
@ -191,7 +191,7 @@ EOT
* @param InputInterface $input
* @param OutputInterface $output
*
* @return mixed
* @return string
*/
private function getAdministratorPassword(InputInterface $input, OutputInterface $output): string
{
@ -221,7 +221,7 @@ EOT
{
return function ($value) {
/** @var ConstraintViolationListInterface $errors */
$errors = $this->get('validator')->validate($value, [new NotBlank()]);
$errors = $this->getContainer()->get('validator')->validate($value, [new NotBlank()]);
foreach ($errors as $error) {
throw new \DomainException($error->getMessage());
}
@ -251,6 +251,6 @@ EOT
*/
private function getAdminUserRepository(): UserRepositoryInterface
{
return $this->get('sylius.repository.admin_user');
return $this->getContainer()->get('sylius.repository.admin_user');
}
}

View file

@ -96,8 +96,9 @@ abstract class AbstractResourceFixture implements FixtureInterface
final public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$optionsNode = $treeBuilder->root($this->getName());
/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $treeBuilder->root($this->getName());
$optionsNode->children()->integerNode('random')->min(0)->defaultValue(0);
/** @var ArrayNodeDefinition $resourcesNode */

View file

@ -20,6 +20,7 @@ use Sylius\Component\Core\Checker\OrderPaymentMethodSelectionRequirementCheckerI
use Sylius\Component\Core\Checker\OrderShippingMethodSelectionRequirementCheckerInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface;
@ -225,6 +226,7 @@ class OrderFixture extends AbstractFixture
$products = $this->productRepository->findAll();
for ($i = 0; $i < $numberOfItems; ++$i) {
/** @var OrderItemInterface $item */
$item = $this->orderItemFactory->createNew();
$product = $this->faker->randomElement($products);

View file

@ -82,6 +82,7 @@ final class ProductTaxonToTaxonTransformer implements DataTransformerInterface
$productTaxon = $this->productTaxonRepository->findOneBy(['taxon' => $taxon, 'product' => $this->product]);
if (null === $productTaxon) {
/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $this->productTaxonFactory->createNew();
$productTaxon->setProduct($this->product);
$productTaxon->setTaxon($taxon);

View file

@ -13,7 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Form\EventSubscriber;
use Sylius\Component\Customer\Model\CustomerInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
@ -62,6 +62,8 @@ final class CustomerRegistrationFormSubscriber implements EventSubscriberInterfa
if (!isset($rawData['email']) || empty($rawData['email'])) {
return;
}
/** @var CustomerInterface|null $existingCustomer */
$existingCustomer = $this->customerRepository->findOneBy(['email' => $rawData['email']]);
if (null === $existingCustomer || null !== $existingCustomer->getUser()) {
return;

View file

@ -79,6 +79,7 @@ final class CustomerGuestType extends AbstractResourceType
return;
}
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($data['email']);

View file

@ -15,6 +15,7 @@ namespace Sylius\Bundle\CoreBundle\Installer\Provider;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -152,7 +153,7 @@ final class DatabaseSetupCommandsProvider implements DatabaseSetupCommandsProvid
*/
private function getDatabaseName(): string
{
return $this->doctrineRegistry->getManager()->getConnection()->getDatabase();
return $this->getEntityManager()->getConnection()->getDatabase();
}
/**
@ -160,6 +161,11 @@ final class DatabaseSetupCommandsProvider implements DatabaseSetupCommandsProvid
*/
private function getSchemaManager(): AbstractSchemaManager
{
return $this->doctrineRegistry->getManager()->getConnection()->getSchemaManager();
return $this->getEntityManager()->getConnection()->getSchemaManager();
}
private function getEntityManager(): EntityManagerInterface
{
return $this->doctrineRegistry->getManager();
}
}

View file

@ -61,7 +61,7 @@ final class ExtensionsRequirements extends RequirementCollection
))
->add(new Requirement(
$translator->trans('sylius.installer.extensions.pcre', []),
defined('PCRE_VERSION') ? ((float) PCRE_VERSION) > 8.0 : false,
defined('PCRE_VERSION') ? ((float) substr(PCRE_VERSION, 0, strpos(PCRE_VERSION, ' '))) > 8.0 : false,
true,
$translator->trans('sylius.installer.extensions.help', ['%extension%' => 'PCRE (>=8.0)'])
))

View file

@ -27,6 +27,7 @@ use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
use Sylius\Component\User\Model\UserOAuthInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Webmozart\Assert\Assert;
/**
* Loading and ad-hoc creation of a user by an OAuth sign-in provider account.
@ -184,17 +185,20 @@ class UserProvider extends BaseUserProvider implements AccountConnectorInterface
* @param UserInterface $user
* @param UserResponseInterface $response
*
* @return UserInterface
* @return SyliusUserInterface
*/
private function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response): UserInterface
private function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response): SyliusUserInterface
{
/** @var SyliusUserInterface $user */
Assert::isInstanceOf($user, SyliusUserInterface::class);
/** @var UserOAuthInterface $oauth */
$oauth = $this->oauthFactory->createNew();
$oauth->setIdentifier($response->getUsername());
$oauth->setProvider($response->getResourceOwner()->getName());
$oauth->setAccessToken($response->getAccessToken());
$oauth->setRefreshToken($response->getRefreshToken());
/** @var SyliusUserInterface $user */
$user->addOAuthAccount($oauth);
$this->userManager->persist($user);

View file

@ -16,8 +16,8 @@ namespace Sylius\Bundle\CoreBundle\Order\NumberGenerator;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Bundle\OrderBundle\NumberGenerator\OrderNumberGeneratorInterface;
use Sylius\Component\Core\Model\OrderSequenceInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Model\OrderSequenceInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
@ -108,6 +108,7 @@ final class SequentialOrderNumberGenerator implements OrderNumberGeneratorInterf
return $sequence;
}
/** @var OrderSequenceInterface $sequence */
$sequence = $this->sequenceFactory->createNew();
$this->sequenceManager->persist($sequence);

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Tests\Form\Type\Taxon;
use Doctrine\Common\Collections\ArrayCollection;
use Prophecy\Prophecy\ObjectProphecy;
use Sylius\Bundle\CoreBundle\Form\Type\Taxon\ProductTaxonAutocompleteChoiceType;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType;
use Sylius\Component\Core\Model\ProductInterface;
@ -29,17 +30,17 @@ use Symfony\Component\Form\Test\TypeTestCase;
final class ProductTaxonAutocompleteChoiceTypeTest extends TypeTestCase
{
/**
* @var ServiceRegistryInterface
* @var ObjectProphecy|ServiceRegistryInterface
*/
private $resourceRepositoryRegistry;
/**
* @var FactoryInterface
* @var ObjectProphecy|FactoryInterface
*/
private $productTaxonFactory;
/**
* @var RepositoryInterface
* @var ObjectProphecy|RepositoryInterface
*/
private $productTaxonRepository;
@ -73,6 +74,7 @@ final class ProductTaxonAutocompleteChoiceTypeTest extends TypeTestCase
$taxon = $this->prophesize(TaxonInterface::class);
$product = $this->prophesize(ProductInterface::class);
/** @var ObjectProphecy|TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->prophesize(TaxonRepositoryInterface::class);
$this->resourceRepositoryRegistry->get('sylius.taxon')->willReturn($taxonRepository);
@ -102,6 +104,8 @@ final class ProductTaxonAutocompleteChoiceTypeTest extends TypeTestCase
$taxon = $this->prophesize(TaxonInterface::class);
$product = $this->prophesize(ProductInterface::class);
$productTaxon = $this->prophesize(ProductTaxonInterface::class);
/** @var ObjectProphecy|TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->prophesize(TaxonRepositoryInterface::class);
$this->resourceRepositoryRegistry->get('sylius.taxon')->willReturn($taxonRepository);
@ -126,6 +130,8 @@ final class ProductTaxonAutocompleteChoiceTypeTest extends TypeTestCase
{
$taxon = $this->prophesize(TaxonInterface::class);
$product = $this->prophesize(ProductInterface::class);
/** @var ObjectProphecy|TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->prophesize(TaxonRepositoryInterface::class);
$this->resourceRepositoryRegistry->get('sylius.taxon')->willReturn($taxonRepository);
@ -155,6 +161,7 @@ final class ProductTaxonAutocompleteChoiceTypeTest extends TypeTestCase
$product = $this->prophesize(ProductInterface::class);
$productTaxon = $this->prophesize(ProductTaxonInterface::class);
/** @var ObjectProphecy|TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->prophesize(TaxonRepositoryInterface::class);
$this->resourceRepositoryRegistry->get('sylius.taxon')->willReturn($taxonRepository);

View file

@ -45,6 +45,7 @@ final class RegisteredUserValidator extends ConstraintValidator
/** @var RegisteredUser $constraint */
Assert::isInstanceOf($constraint, RegisteredUser::class);
/** @var CustomerInterface|null $existingCustomer */
$existingCustomer = $this->customerRepository->findOneBy(['email' => $customer->getEmail()]);
if (null !== $existingCustomer && null !== $existingCustomer->getUser()) {
$this->context->buildViolation($constraint->message)->atPath('email')->addViolation();

View file

@ -16,6 +16,8 @@ namespace Sylius\Bundle\PayumBundle\Controller;
use FOS\RestBundle\View\View;
use Payum\Core\Model\GatewayConfigInterface;
use Payum\Core\Payum;
use Payum\Core\Request\Generic;
use Payum\Core\Request\GetStatusInterface;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Security\TokenInterface;
@ -24,12 +26,14 @@ use Sylius\Bundle\PayumBundle\Factory\ResolveNextRouteFactoryInterface;
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Order\Repository\OrderRepositoryInterface;
use Sylius\Component\Payment\Model\PaymentInterface;
use Sylius\Component\Resource\Metadata\MetadataInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\RouterInterface;
@ -124,15 +128,19 @@ final class PayumController
$token = $this->getHttpRequestVerifier()->verify($request);
/** @var Generic|GetStatusInterface $status */
$status = $this->getStatusRequestFactory->createNewWithModel($token);
$this->payum->getGateway($token->getGatewayName())->execute($status);
$resolveNextRoute = $this->resolveNextRouteRequestFactory->createNewWithModel($status->getFirstModel());
$this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
$this->getHttpRequestVerifier()->invalidate($token);
if (PaymentInterface::STATE_NEW !== $status->getValue()) {
$request->getSession()->getBag('flashes')->add('info', sprintf('sylius.payment.%s', $status->getValue()));
/** @var FlashBagInterface $flashBag */
$flashBag = $request->getSession()->getBag('flashes');
$flashBag->add('info', sprintf('sylius.payment.%s', $status->getValue()));
}
return $this->viewHandler->handle(
@ -153,8 +161,11 @@ final class PayumController
private function provideTokenBasedOnPayment(PaymentInterface $payment, array $redirectOptions): TokenInterface
{
/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $payment->getMethod();
/** @var GatewayConfigInterface $gatewayConfig */
$gatewayConfig = $payment->getMethod()->getGatewayConfig();
$gatewayConfig = $paymentMethod->getGatewayConfig();
if (isset($gatewayConfig->getConfig()['use_authorize']) && $gatewayConfig->getConfig()['use_authorize'] == true) {
$token = $this->getTokenFactory()->createAuthorizeToken(

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Form\Type;
use Sylius\Bundle\ResourceBundle\Form\Builder\DefaultFormBuilderInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Resource\Metadata\RegistryInterface;
use Symfony\Component\Form\AbstractType;
@ -46,6 +47,8 @@ final class DefaultResourceType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$metadata = $this->metadataRegistry->getByClass($options['data_class']);
/** @var DefaultFormBuilderInterface $formBuilder */
$formBuilder = $this->formBuilderRegistry->get($metadata->getDriver());
$formBuilder->build($metadata, $builder, $options);

View file

@ -14,9 +14,11 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Grid\Renderer;
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface;
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;
use Webmozart\Assert\Assert;
final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface
{
@ -55,6 +57,9 @@ final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterfac
*/
public function renderBulkAction(GridViewInterface $gridView, Action $bulkAction, $data = null): string
{
/** @var ResourceGridView $gridView */
Assert::isInstanceOf($gridView, ResourceGridView::class);
$type = $bulkAction->getType();
if (!isset($this->bulkActionTemplates[$type])) {
throw new \InvalidArgumentException(sprintf('Missing template for bulk action type "%s".', $type));

View file

@ -14,11 +14,13 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Grid\Renderer;
use Sylius\Bundle\ResourceBundle\Grid\Parser\OptionsParserInterface;
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
use Sylius\Component\Grid\Definition\Action;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\Definition\Filter;
use Sylius\Component\Grid\Renderer\GridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;
use Webmozart\Assert\Assert;
final class TwigGridRenderer implements GridRendererInterface
{
@ -81,6 +83,9 @@ final class TwigGridRenderer implements GridRendererInterface
*/
public function renderAction(GridViewInterface $gridView, Action $action, $data = null): string
{
/** @var ResourceGridView $gridView */
Assert::isInstanceOf($gridView, ResourceGridView::class);
$type = $action->getType();
if (!isset($this->actionTemplates[$type])) {
throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type));

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Routing;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
@ -24,6 +25,8 @@ final class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('routing');
$rootNode

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Tests\Command;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sylius\Bundle\ResourceBundle\Command\DebugResourceCommand;
use Sylius\Component\Resource\Metadata\Metadata;
use Sylius\Component\Resource\Metadata\MetadataInterface;
@ -23,7 +24,7 @@ use Symfony\Component\Console\Tester\CommandTester;
final class DebugResourceCommandTest extends TestCase
{
/**
* @var RegistryInterface
* @var ObjectProphecy|RegistryInterface
*/
private $registry;

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Tests\Form\Type;
use Doctrine\Common\Collections\ArrayCollection;
use Prophecy\Prophecy\ObjectProphecy;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
@ -26,7 +27,7 @@ use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
{
/**
* @var ServiceRegistryInterface
* @var ObjectProphecy|ServiceRegistryInterface
*/
private $resourceRepositoryRegistry;
@ -51,6 +52,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_returns_resource_from_its_code(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$resource = $this->prophesize(ResourceInterface::class);
@ -73,6 +75,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_returns_resource_from_its_id(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$resource = $this->prophesize(ResourceInterface::class);
@ -95,6 +98,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_returns_different_resource_from_its_identifier(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$resource = $this->prophesize(ResourceInterface::class);
@ -117,6 +121,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_has_identifier_as_view_value(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$resource = $this->prophesize(ResourceInterface::class);
@ -139,6 +144,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_has_different_view_based_on_passed_configuration(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$resource = $this->prophesize(ResourceInterface::class);
@ -162,6 +168,7 @@ final class ResourceAutocompleteChoiceTypeTest extends TypeTestCase
*/
public function it_returns_collection_of_resources_from_identifiers(): void
{
/** @var ObjectProphecy|RepositoryInterface $resourceRepository */
$resourceRepository = $this->prophesize(RepositoryInterface::class);
$mug = $this->prophesize(ResourceInterface::class);
$book = $this->prophesize(ResourceInterface::class);

View file

@ -25,8 +25,9 @@ final class ThemeConfiguration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNodeDefinition = $treeBuilder->root('sylius_theme');
/** @var ArrayNodeDefinition $rootNodeDefinition */
$rootNodeDefinition = $treeBuilder->root('sylius_theme');
$rootNodeDefinition->ignoreExtraKeys();
$this->addRequiredNameField($rootNodeDefinition);

View file

@ -30,7 +30,7 @@ use Webmozart\Assert\Assert;
class Order extends BaseOrder implements OrderInterface
{
/**
* @var BaseCustomerInterface
* @var CustomerInterface
*/
protected $customer;
@ -126,6 +126,8 @@ class Order extends BaseOrder implements OrderInterface
*/
public function setCustomer(?BaseCustomerInterface $customer): void
{
Assert::isInstanceOf($customer, CustomerInterface::class);
$this->customer = $customer;
}
@ -270,6 +272,8 @@ class Order extends BaseOrder implements OrderInterface
public function addPayment(BasePaymentInterface $payment): void
{
/** @var PaymentInterface $payment */
Assert::isInstanceOf($payment, PaymentInterface::class);
if (!$this->hasPayment($payment)) {
$this->payments->add($payment);
$payment->setOrder($this);
@ -282,6 +286,8 @@ class Order extends BaseOrder implements OrderInterface
public function removePayment(BasePaymentInterface $payment): void
{
/** @var PaymentInterface $payment */
Assert::isInstanceOf($payment, PaymentInterface::class);
if ($this->hasPayment($payment)) {
$this->payments->removeElement($payment);
$payment->setOrder(null);

View file

@ -18,13 +18,13 @@ use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PromotionInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\OrderCheckoutStates;
use Sylius\Component\Core\OrderShippingStates;
use Sylius\Component\Customer\Model\CustomerInterface;
use Sylius\Component\Order\Model\Order as BaseOrder;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Promotion\Model\PromotionCouponInterface;