Skip to content

Commit

Permalink
Merge pull request Sylius#8473 from pamil/scalar-types/order
Browse files Browse the repository at this point in the history
[Order] Use typehints introduced by PHP7+
  • Loading branch information
Zales0123 committed Aug 30, 2017
2 parents aa937d4 + a861962 commit 303e386
Show file tree
Hide file tree
Showing 111 changed files with 697 additions and 731 deletions.
9 changes: 9 additions & 0 deletions UPGRADE.md
Expand Up @@ -65,6 +65,15 @@

* In order to be compatibile with Doctrine ORM 2.6+ and be more consistent
`OrderRepositoryInterface::count()` signature was changed to `OrderRepositoryInterface::countPlacedOrders()`.

* The following methods does not longer have a default null argument and requires one to be explicitly passed:

* `AdjustableInterface::getAdjustments`
* `AdjustmentInterface::setAdjustable`
* `OrderAwareInterace::setOrder`
* `OrderInterface::setCheckoutCompletedAt`

* `OrderInterface::getAdjustmentsRecursively` and `OrderItemInterface::getAdjustmentsRecursively` return type changed from `array` to `Collection`.

### Payment / PaymentBundle

Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Context/Setup/OrderContext.php
Expand Up @@ -434,7 +434,7 @@ public function thisCustomerPlacedOrdersOnChannelBuyingProducts(
$order,
$channel,
$this->variantResolver->getVariant($product),
$productCount
(int) $productCount
);

$order->setState(OrderInterface::STATE_NEW);
Expand Down Expand Up @@ -640,7 +640,7 @@ private function addProductVariantToOrder(ProductVariantInterface $productVarian
$order,
$this->sharedStorage->get('channel'),
$productVariant,
$quantity
(int) $quantity
);

return $order;
Expand All @@ -656,7 +656,7 @@ private function addProductVariantsToOrderWithChannelPrice(
OrderInterface $order,
ChannelInterface $channel,
ProductVariantInterface $productVariant,
$quantity = 1
int $quantity = 1
) {
/** @var OrderItemInterface $item */
$item = $this->orderItemFactory->createNew();
Expand Down
Expand Up @@ -59,7 +59,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getCart()
public function getCart(): OrderInterface
{
try {
$channel = $this->channelContext->getChannel();
Expand Down
Expand Up @@ -15,10 +15,10 @@

use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Channel\Context\ChannelNotFoundException;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Order\Context\CartContextInterface;
use Sylius\Component\Order\Context\CartNotFoundException;
use Sylius\Component\Order\Model\OrderInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getCart()
public function getCart(): OrderInterface
{
try {
$channel = $this->channelContext->getChannel();
Expand Down
Expand Up @@ -75,7 +75,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function generate(OrderInterface $order)
public function generate(OrderInterface $order): string
{
$sequence = $this->getSequence();

Expand Down
Expand Up @@ -13,6 +13,7 @@

namespace spec\Sylius\Bundle\CoreBundle\Doctrine\ORM\Inventory\Operator;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use PhpSpec\ObjectBehavior;
Expand Down Expand Up @@ -49,7 +50,7 @@ function it_locks_tracked_variants_during_cancelling(
OrderItemInterface $orderItem,
ProductVariantInterface $variant
) {
$order->getItems()->willReturn([$orderItem]);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$orderItem->getVariant()->willReturn($variant);
$variant->isTracked()->willReturn(true);
$variant->getVersion()->willReturn('7');
Expand All @@ -68,7 +69,7 @@ function it_locks_tracked_variants_during_holding(
OrderItemInterface $orderItem,
ProductVariantInterface $variant
) {
$order->getItems()->willReturn([$orderItem]);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$orderItem->getVariant()->willReturn($variant);
$variant->isTracked()->willReturn(true);
$variant->getVersion()->willReturn('7');
Expand All @@ -87,7 +88,7 @@ function it_locks_tracked_variants_during_selling(
OrderItemInterface $orderItem,
ProductVariantInterface $variant
) {
$order->getItems()->willReturn([$orderItem]);
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$orderItem->getVariant()->willReturn($variant);
$variant->isTracked()->willReturn(true);
$variant->getVersion()->willReturn('7');
Expand Down
Expand Up @@ -13,6 +13,7 @@

namespace spec\Sylius\Bundle\CoreBundle\Validator\Constraints;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\CoreBundle\Validator\Constraints\CartItemAvailability;
Expand Down Expand Up @@ -75,7 +76,7 @@ function it_does_not_add_violation_if_requested_cart_item_is_available(
$addCartItemCommand->getCartItem()->willReturn($orderItem);
$orderItem->getVariant()->willReturn($productVariant);
$orderItem->getQuantity()->willReturn(10);
$order->getItems()->willReturn([]);
$order->getItems()->willReturn(new ArrayCollection([]));

$availabilityChecker->isStockSufficient($productVariant, 10)->willReturn(true);

Expand All @@ -98,7 +99,7 @@ function it_adds_violation_if_requested_cart_item_is_not_available(
$addCartItemCommand->getCartItem()->willReturn($orderItem);
$orderItem->getVariant()->willReturn($productVariant);
$orderItem->getQuantity()->willReturn(10);
$order->getItems()->willReturn([]);
$order->getItems()->willReturn(new ArrayCollection([]));
$productVariant->getInventoryName()->willReturn('Mug');

$availabilityChecker->isStockSufficient($productVariant, 10)->willReturn(false);
Expand Down Expand Up @@ -126,7 +127,7 @@ function it_adds_violation_if_total_quantity_of_cart_items_exceed_available_quan
$orderItem->getQuantity()->willReturn(10);
$productVariant->getInventoryName()->willReturn('Mug');

$order->getItems()->willReturn([$existingOrderItem]);
$order->getItems()->willReturn(new ArrayCollection([$existingOrderItem->getWrappedObject()]));
$existingOrderItem->getQuantity()->willReturn(10);
$existingOrderItem->equals($orderItem)->willReturn(true);

Expand Down Expand Up @@ -155,7 +156,7 @@ function it_does_not_add_violation_if_total_quantity_of_cart_items_do_not_exceed
$orderItem->getQuantity()->willReturn(10);
$existingOrderItem->equals($orderItem)->willReturn(true);

$order->getItems()->willReturn([$existingOrderItem]);
$order->getItems()->willReturn(new ArrayCollection([$existingOrderItem->getWrappedObject()]));
$existingOrderItem->getQuantity()->willReturn(10);

$availabilityChecker->isStockSufficient($productVariant, 20)->willReturn(true);
Expand Down
Expand Up @@ -25,7 +25,7 @@ class RemoveExpiredCartsCommand extends ContainerAwareCommand
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('sylius:remove-expired-carts')
Expand All @@ -36,7 +36,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$expirationTime = $this->getContainer()->getParameter('sylius_order.cart_expiration_period');
$output->writeln(
Expand Down
Expand Up @@ -15,6 +15,7 @@

use Sylius\Component\Order\Context\CartContextInterface;
use Sylius\Component\Order\Context\CartNotFoundException;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Repository\OrderRepositoryInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

Expand Down Expand Up @@ -43,7 +44,7 @@ final class SessionBasedCartContext implements CartContextInterface
* @param string $sessionKeyName
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(SessionInterface $session, $sessionKeyName, OrderRepositoryInterface $orderRepository)
public function __construct(SessionInterface $session, string $sessionKeyName, OrderRepositoryInterface $orderRepository)
{
$this->session = $session;
$this->sessionKeyName = $sessionKeyName;
Expand All @@ -53,7 +54,7 @@ public function __construct(SessionInterface $session, $sessionKeyName, OrderRep
/**
* {@inheritdoc}
*/
public function getCart()
public function getCart(): OrderInterface
{
if (!$this->session->has($this->sessionKeyName)) {
throw new CartNotFoundException('Sylius was not able to find the cart in session');
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/OrderBundle/Controller/AddToCartCommand.php
Expand Up @@ -44,15 +44,15 @@ public function __construct(OrderInterface $cart, OrderItemInterface $cartItem)
/**
* @return OrderInterface
*/
public function getCart()
public function getCart(): OrderInterface
{
return $this->cart;
}

/**
* @return OrderItemInterface
*/
public function getCartItem()
public function getCartItem(): OrderItemInterface
{
return $this->cartItem;
}
Expand Down
Expand Up @@ -24,10 +24,10 @@ interface AddToCartCommandInterface
/**
* @return OrderInterface
*/
public function getCart();
public function getCart(): OrderInterface;

/**
* @return OrderItemInterface
*/
public function getCartItem();
public function getCartItem(): OrderItemInterface;
}
22 changes: 11 additions & 11 deletions src/Sylius/Bundle/OrderBundle/Controller/OrderController.php
Expand Up @@ -38,7 +38,7 @@ class OrderController extends ResourceController
*
* @return Response
*/
public function summaryAction(Request $request)
public function summaryAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

Expand Down Expand Up @@ -68,7 +68,7 @@ public function summaryAction(Request $request)
*
* @return Response
*/
public function widgetAction(Request $request)
public function widgetAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

Expand All @@ -91,7 +91,7 @@ public function widgetAction(Request $request)
*
* @return Response
*/
public function saveAction(Request $request)
public function saveAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

Expand Down Expand Up @@ -154,7 +154,7 @@ public function saveAction(Request $request)
*
* @return Response
*/
public function clearAction(Request $request)
public function clearAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

Expand Down Expand Up @@ -191,9 +191,9 @@ public function clearAction(Request $request)
/**
* @param RequestConfiguration $configuration
*
* @return RedirectResponse
* @return Response
*/
protected function redirectToCartSummary(RequestConfiguration $configuration)
protected function redirectToCartSummary(RequestConfiguration $configuration): Response
{
if (null === $configuration->getParameters()->get('redirect')) {
return $this->redirectHandler->redirectToRoute($configuration, $this->getCartSummaryRoute());
Expand All @@ -205,39 +205,39 @@ protected function redirectToCartSummary(RequestConfiguration $configuration)
/**
* @return string
*/
protected function getCartSummaryRoute()
protected function getCartSummaryRoute(): string
{
return 'sylius_cart_summary';
}

/**
* @return OrderInterface
*/
protected function getCurrentCart()
protected function getCurrentCart(): OrderInterface
{
return $this->getContext()->getCart();
}

/**
* @return CartContextInterface
*/
protected function getContext()
protected function getContext(): CartContextInterface
{
return $this->get('sylius.context.cart');
}

/**
* @return OrderRepositoryInterface
*/
protected function getOrderRepository()
protected function getOrderRepository(): OrderRepositoryInterface
{
return $this->get('sylius.repository.order');
}

/**
* @return EventDispatcherInterface
*/
protected function getEventDispatcher()
protected function getEventDispatcher(): EventDispatcherInterface
{
return $this->container->get('event_dispatcher');
}
Expand Down

0 comments on commit 303e386

Please sign in to comment.