Skip to content

Commit

Permalink
[Psalm] fixes and refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Sep 24, 2021
1 parent fd01548 commit 7ff79f4
Show file tree
Hide file tree
Showing 78 changed files with 295 additions and 511 deletions.
1 change: 0 additions & 1 deletion config/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pimcore:
general:
timezone: Europe/Berlin
path_variable: ''
domain: pimcore-test.dev
redirect_to_maindomain: false
language: en
valid_languages: 'en,de'
Expand Down
14 changes: 7 additions & 7 deletions src/CoreShop/Behat/Context/Domain/LinkGeneratorContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface;
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;

final class LinkGeneratorContext implements Context
{
private SharedStorageInterface $sharedStorage;
private LinkGeneratorInterface $linkGenerator;
private RouterInterface $router;

public function __construct(SharedStorageInterface $sharedStorage, LinkGeneratorInterface $linkGenerator)
public function __construct(SharedStorageInterface $sharedStorage, RouterInterface $router)
{
$this->sharedStorage = $sharedStorage;
$this->linkGenerator = $linkGenerator;
$this->router = $router;
}

/**
* @Then /^the generated url for (object) should be "([^"]+)"/
*/
public function theGeneratedUrlForObjectShouldBe(Concrete $object, $url): void
{
$generatedUrl = $this->linkGenerator->generate($object, null, ['_locale' => 'en']);
$generatedUrl = $object->getClass()->getLinkGenerator()->generate($object, ['_locale' => 'en']);

Assert::eq(
$generatedUrl,
Expand All @@ -54,7 +54,7 @@ public function theGeneratedUrlForObjectShouldBe(Concrete $object, $url): void
*/
public function theGeneratedUrlForObjectWithRouteShouldBe(Concrete $object, $routeName, $url): void
{
$generatedUrl = $this->linkGenerator->generate($object, $routeName, ['_locale' => 'en']);
$generatedUrl = $object->getClass()->getLinkGenerator()->generate($object, ['_locale' => 'en', 'route' => $routeName]);

Assert::eq(
$generatedUrl,
Expand All @@ -72,7 +72,7 @@ public function theGeneratedUrlForObjectWithRouteShouldBe(Concrete $object, $rou
*/
public function theGeneratedUrlForRouteShouldBe($route, $url): void
{
$generatedUrl = $this->linkGenerator->generate(null, $route, ['_locale' => 'en']);
$generatedUrl = $this->router->generate($route, ['_locale' => 'en']);

Assert::eq(
$generatedUrl,
Expand Down
37 changes: 29 additions & 8 deletions src/CoreShop/Behat/Context/Ui/Frontend/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,25 @@
use CoreShop\Behat\Service\NotificationType;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface;
use CoreShop\Component\Product\Model\ProductUnitInterface;
use Pimcore\Model\DataObject\Concrete;
use Webmozart\Assert\Assert;

final class CartContext implements Context
{
private SharedStorageInterface $sharedStorage;
private LinkGeneratorInterface $linkGenerator;
private NotificationCheckerInterface $notificationChecker;
private CartPageInterface $cartPage;
private ProductPageInterface $productPage;

public function __construct(
SharedStorageInterface $sharedStorage,
LinkGeneratorInterface $linkGenerator,
NotificationCheckerInterface $notificationChecker,
CartPageInterface $cartPage,
ProductPageInterface $productPage
)
{
$this->sharedStorage = $sharedStorage;
$this->linkGenerator = $linkGenerator;
$this->notificationChecker = $notificationChecker;
$this->cartPage = $cartPage;
$this->productPage = $productPage;
Expand Down Expand Up @@ -73,7 +70,13 @@ public function iShouldBeNotifiedThatMyCartIsEmpty(): void
*/
public function iAddProductToTheCart(ProductInterface $product): void
{
$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);
$this->productPage->addToCart();

$this->sharedStorage->set('product', $product);
Expand All @@ -84,7 +87,13 @@ public function iAddProductToTheCart(ProductInterface $product): void
*/
public function iAddQuantityProductToTheCart($quantity, ProductInterface $product): void
{
$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);
$this->productPage->addToCartWithQuantity($quantity);
}

Expand All @@ -96,7 +105,13 @@ public function iAddProductInUnitToTheCart(ProductInterface $product, ProductUni
{
$unitDefinition = $this->findUnitDefinition($product, $unit);

$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);
$this->productPage->addToCartInUnit($unitDefinition);

$this->sharedStorage->set('product', $product);
Expand All @@ -110,7 +125,13 @@ public function iAddQuantityProductInUnitToTheCart($quantity, ProductInterface $
{
$unitDefinition = $this->findUnitDefinition($product, $unit);

$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);
$this->productPage->addToCartInUnitWithQuantity($unitDefinition, $quantity);

$this->sharedStorage->set('product', $product);
Expand Down
30 changes: 23 additions & 7 deletions src/CoreShop/Behat/Context/Ui/Frontend/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
use CoreShop\Behat\Page\Frontend\ProductPageInterface;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface;
use CoreShop\Component\Product\Model\ProductUnitInterface;
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;

final class ProductContext implements Context
{
private SharedStorageInterface $sharedStorage;
private LinkGeneratorInterface $linkGenerator;
private ProductPageInterface $productPage;

public function __construct(
SharedStorageInterface $sharedStorage,
LinkGeneratorInterface $linkGenerator,
ProductPageInterface $productPage
)
{
$this->sharedStorage = $sharedStorage;
$this->linkGenerator = $linkGenerator;
$this->productPage = $productPage;
}

Expand All @@ -52,15 +50,27 @@ public function iOpenPage($url, ProductInterface $product): void
*/
public function iShouldBeOnProductDetailedPage(ProductInterface $product): void
{
Assert::true($this->productPage->isOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en'])));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

Assert::true($this->productPage->isOpenWithUri($path));
}

/**
* @When /^I open the (product's) detail page$/
*/
public function iCheckLatestProducts(ProductInterface $product): void
{
$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);
}

/**
Expand Down Expand Up @@ -218,7 +228,13 @@ public function iShouldSeeTheQuantityPriceRuleForUnitStartingFrom(int $number, $
*/
public function iShouldSeeThatThisProductIsOutOfStock(ProductInterface $product): void
{
$this->productPage->tryToOpenWithUri($this->linkGenerator->generate($product, null, ['_locale' => 'en']));
$path = null;

if ($product instanceof Concrete) {
$path = $product->getClass()->getLinkGenerator()->generate($product, ['_locale' => 'en']);
}

$this->productPage->tryToOpenWithUri($path);

Assert::true($this->productPage->getIsOutOfStock());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ services:
class: CoreShop\Behat\Context\Domain\LinkGeneratorContext
arguments:
- '@coreshop.behat.shared_storage'
- '@CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface'
- '@router'
tags:
- { name: fob.context_service }

Expand Down
2 changes: 0 additions & 2 deletions src/CoreShop/Behat/Resources/config/services/contexts/ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ services:
class: CoreShop\Behat\Context\Ui\Frontend\ProductContext
arguments:
- '@coreshop.behat.shared_storage'
- '@CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface'
- '@CoreShop\Behat\Page\Frontend\ProductPageInterface'
tags:
- { name: fob.context_service }
Expand All @@ -54,7 +53,6 @@ services:
class: CoreShop\Behat\Context\Ui\Frontend\CartContext
arguments:
- '@coreshop.behat.shared_storage'
- '@CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface'
- '@CoreShop\Behat\Service\NotificationCheckerInterface'
- '@CoreShop\Behat\Page\Frontend\CartPageInterface'
- '@CoreShop\Behat\Page\Frontend\ProductPageInterface'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class MigrationGenerateCommand extends Command
protected function configure(): void
{
$this
->setName('coreshop:migrate:generate')
->setName('coreshop:migration:generate')
->setHidden(true)
->setDescription('Create a new CoreShop migrations.')
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

use CoreShop\Bundle\CoreBundle\Event\RequestNewsletterConfirmationEvent;
use CoreShop\Component\Core\Model\CustomerInterface;
use CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Webmozart\Assert\Assert;

final class CustomerNewsletterConfirmListener
{
private LinkGeneratorInterface $linkGenerator;
private RouterInterface $router;
private RequestStack $requestStack;
private EventDispatcherInterface $eventDispatcher;

public function __construct(
LinkGeneratorInterface $linkGenerator,
RouterInterface $router,
RequestStack $requestStack,
EventDispatcherInterface $eventDispatcher
) {
$this->linkGenerator = $linkGenerator;
$this->router = $router;
$this->requestStack = $requestStack;
$this->eventDispatcher = $eventDispatcher;
}
Expand Down Expand Up @@ -62,8 +62,7 @@ public function checkCustomerNewsletterConfirmation(GenericEvent $event): void

$confirmEvent = new RequestNewsletterConfirmationEvent(
$user,
$this->linkGenerator->generate(
$event->getSubject(),
$this->router->generate(
'coreshop_customer_confirm_newsletter',
['_locale' => $this->requestStack->getMainRequest()->getLocale()],
UrlGeneratorInterface::ABSOLUTE_URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
namespace CoreShop\Bundle\CoreBundle\EventListener;

use CoreShop\Component\Core\Model\StoreInterface;
use CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface;
use CoreShop\Component\Store\Context\StoreContextInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;

/** @psalm-suppress DeprecatedInterface */
final class ShopUserLogoutHandler implements LogoutSuccessHandlerInterface
{
private LinkGeneratorInterface $linkGenerator;
private RouterInterface $router;
private string $routeName;
private SessionInterface $session;
private StoreContextInterface $storeContext;

public function __construct(
LinkGeneratorInterface $linkGenerator,
RouterInterface $router,
string $routeName,
SessionInterface $session,
StoreContextInterface $storeContext
) {
$this->linkGenerator = $linkGenerator;
$this->router = $router;
$this->routeName = $routeName;
$this->session = $session;
$this->storeContext = $storeContext;
Expand All @@ -51,6 +51,6 @@ public function onLogoutSuccess(Request $request): Response
$this->session->remove('coreshop.cart.' . $store->getId());
}

return new RedirectResponse($this->linkGenerator->generate(null, $this->routeName, ['_locale' => $request->getLocale()]));
return new RedirectResponse($this->router->generate($this->routeName, ['_locale' => $request->getLocale()]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace CoreShop\Bundle\CoreBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20210924090831 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql("
ALTER TABLE coreshop_product_store_values CHANGE price price BIGINT NOT NULL COMMENT '(DC2Type:bigintInteger)';
ALTER TABLE coreshop_product_unit_definition_price CHANGE price price BIGINT NOT NULL COMMENT '(DC2Type:bigintInteger)';
ALTER TABLE coreshop_product_quantity_price_rule_range CHANGE amount amount BIGINT NOT NULL COMMENT '(DC2Type:bigintInteger)', CHANGE pseudo_price pseudo_price BIGINT NOT NULL COMMENT '(DC2Type:bigintInteger)';
");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</id>

<field name="product" column="product" type="pimcoreObject"/>
<field name="price" column="price" type="bigint"/>
<field name="price" column="price" type="bigintInteger"/>

<many-to-one field="store" target-entity="CoreShop\Component\Store\Model\StoreInterface">
<join-column name="store" referenced-column-name="id" on-delete="CASCADE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
<mapped-superclass name="CoreShop\Component\Core\Model\QuantityRange" table="coreshop_product_quantity_price_rule_range">
<field name="amount" column="amount" type="bigint"/>
<field name="pseudoPrice" column="pseudo_price" type="bigint"/>
<field name="amount" column="amount" type="bigintInteger"/>
<field name="pseudoPrice" column="pseudo_price" type="bigintInteger"/>

<many-to-one field="currency" target-entity="CoreShop\Component\Currency\Model\CurrencyInterface">
<join-column name="currencyId" referenced-column-name="id" on-delete="SET NULL"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
CoreShop\Bundle\CoreBundle\Twig\CheckoutIdentifierExtension:
arguments:
- '@request_stack'
- '@CoreShop\Component\Pimcore\Routing\LinkGeneratorInterface'
- '@router'
- '@CoreShop\Component\Order\Checkout\CheckoutManagerFactoryInterface'
- '@CoreShop\Component\Order\Context\CartContextInterface'
tags:
Expand Down
Loading

0 comments on commit 7ff79f4

Please sign in to comment.