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

[Enhancement] Refactor and deprecate Invoice repository class #186

Merged
merged 7 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### UPGRADE FROM 0.11.0 TO 0.11.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### UPGRADE FROM 0.11.0 TO 0.11.1
### UPGRADE FROM 0.11.0 TO 0.12.0


1. The custom repository has been removed :

- removed the repository class `DoctrineInvoiceRepository` and replaced by `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepository`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- removed the repository class `DoctrineInvoiceRepository` and replaced by `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepository`
- removed the repository class `Sylius\InvoicingPlugin\Repository\DoctrineInvoiceRepository` and replaced by `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepository`

- removed the related service `sylius_invoicing_plugin.custom_repository.invoice` use `sylius_invoicing_plugin.repository.invoice` instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- removed the related service `sylius_invoicing_plugin.custom_repository.invoice` use `sylius_invoicing_plugin.repository.invoice` instead
- removed the related service `sylius_invoicing_plugin.custom_repository.invoice`, use `sylius_invoicing_plugin.repository.invoice` instead

- removed the related interface `InvoiceRepository` use `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface` instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- removed the related interface `InvoiceRepository` use `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface` instead
- removed the related interface `Sylius\InvoicingPlugin\Repository\InvoiceRepository`, use `Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface` instead


### UPGRADE FROM 0.10.X TO 0.11.0

1. Upgrade your application to [Sylius 1.8](https:/Sylius/Sylius/blob/master/UPGRADE-1.8.md).
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"symfony/web-profiler-bundle": "^4.4",
"symfony/web-server-bundle": "^4.4"
},
"conflict": {
"symplify/package-builder": "^8.3.25"
},
"autoload": {
"psr-4": {
"Sylius\\InvoicingPlugin\\": "src/",
Expand Down
8 changes: 4 additions & 4 deletions spec/CommandHandler/SendInvoiceEmailHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Command\SendInvoiceEmail;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Email\InvoiceEmailSenderInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;

final class SendInvoiceEmailHandlerSpec extends ObjectBehavior
{
function let(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender
): void {
$this->beConstructedWith($invoiceRepository, $orderRepository, $emailSender);
}

function it_requests_an_email_with_an_invoice_to_be_sent(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender,
InvoiceInterface $invoice,
Expand All @@ -45,7 +45,7 @@ function it_requests_an_email_with_an_invoice_to_be_sent(
}

function it_does_not_request_an_email_to_be_sent_if_invoice_was_not_found(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender,
OrderInterface $order,
Expand Down
8 changes: 4 additions & 4 deletions spec/Creator/InvoiceCreatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Creator\InvoiceCreatorInterface;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Exception\InvoiceAlreadyGenerated;
use Sylius\InvoicingPlugin\Generator\InvoiceGeneratorInterface;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;

final class InvoiceCreatorSpec extends ObjectBehavior
{
public function let(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceGeneratorInterface $invoiceGenerator
): void {
Expand All @@ -30,7 +30,7 @@ public function it_implements_invoice_for_order_creator_interface(): void
}

public function it_creates_invoice_for_order(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceGeneratorInterface $invoiceGenerator,
OrderInterface $order,
Expand All @@ -50,7 +50,7 @@ public function it_creates_invoice_for_order(
}

public function it_throws_an_exception_when_invoice_was_already_created_for_given_order(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceGeneratorInterface $invoiceGenerator,
InvoiceInterface $invoice
Expand Down
8 changes: 4 additions & 4 deletions spec/EventProducer/OrderPaymentPaidProducerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\InvoicingPlugin\DateTimeProvider;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Event\OrderPaymentPaid;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

Expand All @@ -20,7 +20,7 @@ final class OrderPaymentPaidProducerSpec extends ObjectBehavior
function let(
MessageBusInterface $eventBus,
DateTimeProvider $dateTimeProvider,
InvoiceRepository $invoiceRepository
InvoiceRepositoryInterface $invoiceRepository
): void {
$this->beConstructedWith($eventBus, $dateTimeProvider, $invoiceRepository);
}
Expand All @@ -30,7 +30,7 @@ function it_dispatches_order_payment_paid_event_for_payment(
DateTimeProvider $dateTimeProvider,
PaymentInterface $payment,
OrderInterface $order,
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
InvoiceInterface $invoice
): void {
$payment->getOrder()->willReturn($order);
Expand Down Expand Up @@ -67,7 +67,7 @@ function it_does_not_dispatch_event_when_there_is_no_invoice_related_to_order(
DateTimeProvider $dateTimeProvider,
PaymentInterface $payment,
OrderInterface $order,
InvoiceRepository $invoiceRepository
InvoiceRepositoryInterface $invoiceRepository
): void {
$payment->getOrder()->willReturn($order);
$order->getNumber()->willReturn('0000001');
Expand Down
6 changes: 3 additions & 3 deletions src/CommandHandler/SendInvoiceEmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Command\SendInvoiceEmail;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Email\InvoiceEmailSenderInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;

final class SendInvoiceEmailHandler
{
/** @var InvoiceRepository */
/** @var InvoiceRepositoryInterface */
private $invoiceRepository;

/** @var OrderRepositoryInterface */
Expand All @@ -23,7 +23,7 @@ final class SendInvoiceEmailHandler
private $emailSender;

public function __construct(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender
) {
Expand Down
6 changes: 3 additions & 3 deletions src/Creator/InvoiceCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;
use Sylius\InvoicingPlugin\Exception\InvoiceAlreadyGenerated;
use Sylius\InvoicingPlugin\Generator\InvoiceGeneratorInterface;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;

final class InvoiceCreator implements InvoiceCreatorInterface
{
/** @var InvoiceRepository */
/** @var InvoiceRepositoryInterface */
private $invoiceRepository;

/** @var OrderRepositoryInterface */
Expand All @@ -23,7 +23,7 @@ final class InvoiceCreator implements InvoiceCreatorInterface
private $invoiceGenerator;

public function __construct(
InvoiceRepository $invoiceRepository,
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceGeneratorInterface $invoiceGenerator
) {
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\Factory\Factory;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepository;
use Sylius\InvoicingPlugin\Entity\BillingData;
use Sylius\InvoicingPlugin\Entity\BillingDataInterface;
use Sylius\InvoicingPlugin\Entity\Invoice;
Expand Down Expand Up @@ -42,7 +43,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('interface')->defaultValue(InvoiceInterface::class)->cannotBeEmpty()->end()
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
->scalarNode('repository')->cannotBeEmpty()->end()
->scalarNode('repository')->defaultValue(InvoiceRepository::class)->cannotBeEmpty()->end()
->end()
->end()
->end()
Expand Down
19 changes: 19 additions & 0 deletions src/Doctrine/ORM/InvoiceRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Doctrine\ORM;

use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;

class InvoiceRepository extends EntityRepository implements InvoiceRepositoryInterface
{
public function findOneByOrderNumber(string $orderNumber): ?InvoiceInterface
{
/** @var InvoiceInterface|null $invoice */
$invoice = $this->findOneBy(['orderNumber' => $orderNumber]);

return $invoice;
}
}
13 changes: 13 additions & 0 deletions src/Doctrine/ORM/InvoiceRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Sylius\InvoicingPlugin\Doctrine\ORM;

use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\InvoicingPlugin\Entity\InvoiceInterface;

interface InvoiceRepositoryInterface extends RepositoryInterface
{
public function findOneByOrderNumber(string $orderNumber): ?InvoiceInterface;
}
3 changes: 1 addition & 2 deletions src/Entity/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

/** @final */
class Invoice implements InvoiceInterface, ResourceInterface
class Invoice implements InvoiceInterface
{
/** @var string */
protected $id;
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/InvoiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Model\ResourceInterface;

interface InvoiceInterface
interface InvoiceInterface extends ResourceInterface
{
public function id(): string;

Expand Down
6 changes: 3 additions & 3 deletions src/EventProducer/OrderPaymentPaidProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\InvoicingPlugin\DateTimeProvider;
use Sylius\InvoicingPlugin\Doctrine\ORM\InvoiceRepositoryInterface;
use Sylius\InvoicingPlugin\Event\OrderPaymentPaid;
use Sylius\InvoicingPlugin\Repository\InvoiceRepository;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

Expand All @@ -20,13 +20,13 @@ final class OrderPaymentPaidProducer
/** @var DateTimeProvider */
private $dateTimeProvider;

/** @var InvoiceRepository */
/** @var InvoiceRepositoryInterface */
private $invoiceRepository;

public function __construct(
MessageBusInterface $eventBus,
DateTimeProvider $dateTimeProvider,
InvoiceRepository $invoiceRepository
InvoiceRepositoryInterface $invoiceRepository
) {
$this->eventBus = $eventBus;
$this->dateTimeProvider = $dateTimeProvider;
Expand Down
47 changes: 0 additions & 47 deletions src/Repository/DoctrineInvoiceRepository.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Repository/InvoiceRepository.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

<service id="sylius_invoicing_plugin.date_time_provider" class="Sylius\InvoicingPlugin\SystemDateTimeProvider" />

<service id="sylius_invoicing_plugin.custom_repository.invoice" class="Sylius\InvoicingPlugin\Repository\DoctrineInvoiceRepository" />

<service id="sylius_invoicing_plugin.email.invoice_email_sender" class="Sylius\InvoicingPlugin\Email\InvoiceEmailSender">
<argument type="service" id="sylius.email_sender" />
<argument type="service" id="sylius_invoicing_plugin.generator.invoice_pdf_file" />
</service>

<service id="sylius_invoicing_plugin.command_handler.send_invoice_email" class="Sylius\InvoicingPlugin\CommandHandler\SendInvoiceEmailHandler">
<argument type="service" id="sylius_invoicing_plugin.custom_repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.repository.invoice" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius_invoicing_plugin.email.invoice_email_sender" />
<tag name="messenger.message_handler" />
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<defaults autoconfigure="true" autowire="true" public="true" />

<service id="sylius_invoicing_plugin.ui.action.download_invoice" class="Sylius\InvoicingPlugin\Ui\Action\DownloadInvoiceAction">
<argument type="service" id="sylius_invoicing_plugin.custom_repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.repository.invoice" />
<argument type="service" id="security.authorization_checker" />
<argument type="service" id="sylius_invoicing_plugin.generator.invoice_pdf_file" />
</service>

<service id="sylius_invoicing_plugin.ui.action.resend_invoice" class="Sylius\InvoicingPlugin\Ui\Action\Admin\ResendInvoiceAction">
<argument type="service" id="sylius_invoicing_plugin.custom_repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.email.invoice_email_sender" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="router" />
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<service id="sylius_invoicing_plugin.event_producer.order_payment_paid" class="Sylius\InvoicingPlugin\EventProducer\OrderPaymentPaidProducer">
<argument type="service" id="sylius_invoicing_plugin.event_bus" />
<argument type="service" id="sylius_invoicing_plugin.date_time_provider" />
<argument type="service" id="sylius_invoicing_plugin.custom_repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.repository.invoice" />
</service>

<service id="sylius_invoicing_plugin.event_listener.order_placed" class="Sylius\InvoicingPlugin\EventListener\CreateInvoiceOnOrderPlacedListener">
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/generators.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</service>

<service id="sylius_invoicing_plugin.creator.invoice" class="Sylius\InvoicingPlugin\Creator\InvoiceCreator">
<argument type="service" id="sylius_invoicing_plugin.custom_repository.invoice" />
<argument type="service" id="sylius_invoicing_plugin.repository.invoice" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius_invoicing_plugin.generator.invoice" />
</service>
Expand Down
Loading