Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Nov 5, 2024
1 parent 142b315 commit 1d7e3dd
Show file tree
Hide file tree
Showing 43 changed files with 178 additions and 405 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"symfony/browser-kit": "^5.4.21 || ^6.4",
"symfony/debug-bundle": "^5.4.21 || ^6.4",
"symfony/dotenv": "^5.4.21 || ^6.4",
"symfony/intl": "^5.4 || ^6.0",
"symfony/intl": "^5.4.21 || ^6.0",
"symfony/web-profiler-bundle": "^5.4.21 || ^6.4",
"symfony/webpack-encore-bundle": "^1.15"
},
Expand Down
15 changes: 15 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $config): void
{
$config->sets([
LevelSetList::UP_TO_PHP_81,
SymfonySetList::SYMFONY_54,
]);
};
11 changes: 2 additions & 9 deletions src/Cli/GenerateInvoicesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ final class GenerateInvoicesCommand extends Command
{
protected static $defaultName = 'sylius-invoicing:generate-invoices';

private MassInvoicesCreatorInterface $massInvoicesCreator;

private OrderRepositoryInterface $orderRepository;

public function __construct(
MassInvoicesCreatorInterface $massInvoicesCreator,
OrderRepositoryInterface $orderRepository
private readonly MassInvoicesCreatorInterface $massInvoicesCreator,
private readonly OrderRepositoryInterface $orderRepository
) {
$this->massInvoicesCreator = $massInvoicesCreator;
$this->orderRepository = $orderRepository;

parent::__construct();
}

Expand Down
5 changes: 1 addition & 4 deletions src/Command/SendInvoiceEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@

final class SendInvoiceEmail
{
private string $orderNumber;

public function __construct(string $orderNumber)
public function __construct(private readonly string $orderNumber)
{
$this->orderNumber = $orderNumber;
}

public function orderNumber(): string
Expand Down
15 changes: 3 additions & 12 deletions src/CommandHandler/SendInvoiceEmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,11 @@

final class SendInvoiceEmailHandler
{
private InvoiceRepositoryInterface $invoiceRepository;

private OrderRepositoryInterface $orderRepository;

private InvoiceEmailSenderInterface $emailSender;

public function __construct(
InvoiceRepositoryInterface $invoiceRepository,
OrderRepositoryInterface $orderRepository,
InvoiceEmailSenderInterface $emailSender
private readonly InvoiceRepositoryInterface $invoiceRepository,
private readonly OrderRepositoryInterface $orderRepository,
private readonly InvoiceEmailSenderInterface $emailSender
) {
$this->invoiceRepository = $invoiceRepository;
$this->orderRepository = $orderRepository;
$this->emailSender = $emailSender;
}

public function __invoke(SendInvoiceEmail $command): void
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/OrderItemUnitsToLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
final class OrderItemUnitsToLineItemsConverter implements LineItemsConverterInterface
{
public function __construct(
private TaxRatePercentageProviderInterface $taxRatePercentageProvider,
private LineItemFactoryInterface $lineItemFactory,
private UnitNetPriceProviderInterface $unitNetPriceProvider
private readonly TaxRatePercentageProviderInterface $taxRatePercentageProvider,
private readonly LineItemFactoryInterface $lineItemFactory,
private readonly UnitNetPriceProviderInterface $unitNetPriceProvider,
) {
}

Expand Down
10 changes: 2 additions & 8 deletions src/Converter/ShippingAdjustmentsToLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@

final class ShippingAdjustmentsToLineItemsConverter implements LineItemsConverterInterface
{
private TaxRatePercentageProviderInterface $taxRatePercentageProvider;

private LineItemFactoryInterface $lineItemFactory;

public function __construct(
TaxRatePercentageProviderInterface $taxRatePercentageProvider,
LineItemFactoryInterface $lineItemFactory
private readonly TaxRatePercentageProviderInterface $taxRatePercentageProvider,
private readonly LineItemFactoryInterface $lineItemFactory,
) {
$this->taxRatePercentageProvider = $taxRatePercentageProvider;
$this->lineItemFactory = $lineItemFactory;
}

public function convert(OrderInterface $order): array
Expand Down
12 changes: 4 additions & 8 deletions src/Converter/TaxItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@

final class TaxItemsConverter implements TaxItemsConverterInterface
{
private TaxRatePercentageProviderInterface $taxRatePercentageProvider;

private TaxItemFactoryInterface $taxItemFactory;

public function __construct(TaxRatePercentageProviderInterface $taxRatePercentageProvider, TaxItemFactoryInterface $taxItemFactory)
{
$this->taxRatePercentageProvider = $taxRatePercentageProvider;
$this->taxItemFactory = $taxItemFactory;
public function __construct(
private readonly TaxRatePercentageProviderInterface $taxRatePercentageProvider,
private readonly TaxItemFactoryInterface $taxItemFactory,
) {
}

public function convert(OrderInterface $order): Collection
Expand Down
12 changes: 6 additions & 6 deletions src/Creator/InvoiceCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
final class InvoiceCreator implements InvoiceCreatorInterface
{
public function __construct(
private InvoiceRepositoryInterface $invoiceRepository,
private OrderRepositoryInterface $orderRepository,
private InvoiceGeneratorInterface $invoiceGenerator,
private InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator,
private InvoiceFileManagerInterface $invoiceFileManager,
private bool $hasEnabledPdfFileGenerator = true
private readonly InvoiceRepositoryInterface $invoiceRepository,
private readonly OrderRepositoryInterface $orderRepository,
private readonly InvoiceGeneratorInterface $invoiceGenerator,
private readonly InvoicePdfFileGeneratorInterface $invoicePdfFileGenerator,
private readonly InvoiceFileManagerInterface $invoiceFileManager,
private readonly bool $hasEnabledPdfFileGenerator = true
) {
}

Expand Down
12 changes: 3 additions & 9 deletions src/Creator/MassInvoicesCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@

final class MassInvoicesCreator implements MassInvoicesCreatorInterface
{
private InvoiceCreatorInterface $invoiceCreator;

private DateTimeProvider $dateTimeProvider;

public function __construct(
InvoiceCreatorInterface $invoiceCreator,
DateTimeProvider $dateTimeProvider
private readonly InvoiceCreatorInterface $invoiceCreator,
private readonly DateTimeProvider $dateTimeProvider
) {
$this->invoiceCreator = $invoiceCreator;
$this->dateTimeProvider = $dateTimeProvider;
}

public function __invoke(array $orders): void
Expand All @@ -37,7 +31,7 @@ public function __invoke(array $orders): void
foreach ($orders as $order) {
try {
$this->invoiceCreator->__invoke($order->getNumber(), $this->dateTimeProvider->__invoke());
} catch (InvoiceAlreadyGenerated $exception) {
} catch (InvoiceAlreadyGenerated) {
continue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SyliusInvoicingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ final class SyliusInvoicingExtension extends AbstractResourceExtension implement
{
use PrependDoctrineMigrationsTrait;

public function load(array $config, ContainerBuilder $container): void
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

/** @var ConfigurationInterface $configuration */
$configuration = $this->getConfiguration([], $container);

$config = $this->processConfiguration($configuration, $config);
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('sylius_invoicing.pdf_generator.allowed_files', $config['pdf_generator']['allowed_files']);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Email/InvoiceEmailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
final class InvoiceEmailSender implements InvoiceEmailSenderInterface
{
public function __construct(
private SenderInterface $emailSender,
private InvoiceFileProviderInterface $invoiceFileProvider,
private bool $hasEnabledPdfFileGenerator = true
private readonly SenderInterface $emailSender,
private readonly InvoiceFileProviderInterface $invoiceFileProvider,
private readonly bool $hasEnabledPdfFileGenerator = true
) {
}

Expand Down
45 changes: 9 additions & 36 deletions src/Entity/BillingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,17 @@ class BillingData implements BillingDataInterface, ResourceInterface
{
protected int $id;

protected string $firstName;

protected string $lastName;

protected ?string $company;

protected string $countryCode;

protected ?string $provinceCode;

protected ?string $provinceName;

protected string $street;

protected string $city;

protected string $postcode;

public function __construct(
string $firstName,
string $lastName,
string $countryCode,
string $street,
string $city,
string $postcode,
?string $provinceCode = null,
?string $provinceName = null,
?string $company = null
protected string $firstName,
protected string $lastName,
protected string $countryCode,
protected string $street,
protected string $city,
protected string $postcode,
protected ?string $provinceCode = null,
protected ?string $provinceName = null,
protected ?string $company = null,
) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->countryCode = $countryCode;
$this->street = $street;
$this->city = $city;
$this->postcode = $postcode;
$this->provinceCode = $provinceCode;
$this->provinceName = $provinceName;
$this->company = $company;
}

public function getId(): int
Expand Down
72 changes: 17 additions & 55 deletions src/Entity/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,70 +20,32 @@
/** @final */
class Invoice implements InvoiceInterface
{
protected string $id;

protected string $number;

protected OrderInterface $order;

protected \DateTimeInterface $issuedAt;

protected BillingDataInterface $billingData;

protected string $currencyCode;

protected string $localeCode;

protected int $total;

/** @var Collection|LineItemInterface[] */
protected Collection $lineItems;

/** @var Collection|TaxItemInterface[] */
protected Collection $taxItems;

protected ChannelInterface $channel;

protected string $paymentState;

protected InvoiceShopBillingDataInterface $shopBillingData;

public function __construct(
string $id,
string $number,
OrderInterface $order,
\DateTimeInterface $issuedAt,
BillingDataInterface $billingData,
string $currencyCode,
string $localeCode,
int $total,
Collection $lineItems,
Collection $taxItems,
ChannelInterface $channel,
string $paymentState,
InvoiceShopBillingDataInterface $shopBillingData
protected string $id,
protected string $number,
protected OrderInterface $order,
protected \DateTimeInterface $issuedAt,
protected BillingDataInterface $billingData,
protected string $currencyCode,
protected string $localeCode,
protected int $total,
/** @var Collection|LineItemInterface[] */
protected Collection $lineItems,
/** @var Collection|TaxItemInterface[] */
protected Collection $taxItems,
protected ChannelInterface $channel,
protected string $paymentState,
protected InvoiceShopBillingDataInterface $shopBillingData
) {
$this->id = $id;
$this->number = $number;
$this->order = $order;
$this->issuedAt = clone $issuedAt;
$this->billingData = $billingData;
$this->currencyCode = $currencyCode;
$this->localeCode = $localeCode;
$this->total = $total;
$this->lineItems = $lineItems;
$this->taxItems = $taxItems;
$this->channel = $channel;
$this->paymentState = $paymentState;
$this->shopBillingData = $shopBillingData;

/** @var LineItemInterface $lineItem */
foreach ($lineItems as $lineItem) {
foreach ($this->lineItems as $lineItem) {
$lineItem->setInvoice($this);
}

/** @var TaxItemInterface $taxItem */
foreach ($taxItems as $taxItem) {
foreach ($this->taxItems as $taxItem) {
$taxItem->setInvoice($this);
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/Entity/TaxItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ class TaxItem implements TaxItemInterface, ResourceInterface

protected ?InvoiceInterface $invoice = null;

protected string $label;

protected int $amount;

public function __construct(string $label, int $amount)
{
$this->label = $label;
$this->amount = $amount;
public function __construct(
protected string $label,
protected int $amount,
) {
}

public function getId()
Expand Down
11 changes: 5 additions & 6 deletions src/Event/OrderPaymentPaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@

final class OrderPaymentPaid
{
private string $orderNumber;
private readonly \DateTimeInterface $date;

private \DateTimeInterface $date;

public function __construct(string $orderNumber, \DateTimeInterface $date)
{
$this->orderNumber = $orderNumber;
public function __construct(
private readonly string $orderNumber,
\DateTimeInterface $date,
) {
$this->date = clone $date;
}

Expand Down
Loading

0 comments on commit 1d7e3dd

Please sign in to comment.