Skip to content

Commit

Permalink
Simplify gift card configuration factory
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed May 9, 2022
1 parent b0c74a5 commit 7e09d62
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 15 deletions.
9 changes: 0 additions & 9 deletions src/Factory/GiftCardConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

namespace Setono\SyliusGiftCardPlugin\Factory;

use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImageInterface;
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

final class GiftCardConfigurationFactory implements GiftCardConfigurationFactoryInterface
{
private FactoryInterface $decoratedFactory;

private FactoryInterface $imageFactory;

private string $defaultOrientation;

private string $defaultPageSize;

public function __construct(
FactoryInterface $decoratedFactory,
FactoryInterface $imageFactory,
string $defaultOrientation,
string $defaultPageSize
) {
$this->decoratedFactory = $decoratedFactory;
$this->imageFactory = $imageFactory;
$this->defaultOrientation = $defaultOrientation;
$this->defaultPageSize = $defaultPageSize;
}
Expand All @@ -35,10 +30,6 @@ public function createNew(): GiftCardConfigurationInterface
/** @var GiftCardConfigurationInterface $configuration */
$configuration = $this->decoratedFactory->createNew();

/** @var GiftCardConfigurationImageInterface $backgroundImage */
$backgroundImage = $this->imageFactory->createNew();
$configuration->setBackgroundImage($backgroundImage);

$configuration->setOrientation($this->defaultOrientation);
$configuration->setPageSize($this->defaultPageSize);

Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services/factory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class="Setono\SyliusGiftCardPlugin\Factory\GiftCardConfigurationFactory"
decorates="setono_sylius_gift_card.factory.gift_card_configuration">
<argument type="service" id="setono_sylius_gift_card.custom_factory.gift_card_configuration.inner" />
<argument type="service" id="setono_sylius_gift_card.factory.gift_card_configuration_image" />
<argument>%setono_sylius_gift_card.pdf_rendering.default_orientation%</argument>
<argument>%setono_sylius_gift_card.pdf_rendering.default_page_size%</argument>
</service>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Shop/GiftCard/pdf.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set path = '' %}
{% if configuration.backgroundImage.path is not empty %}
{% if configuration.backgroundImage is not null and configuration.backgroundImage.path is not empty %}
{% set path = configuration.backgroundImage.path|imagine_filter('setono_sylius_gift_card_background') %}
{% endif %}

Expand Down
4 changes: 0 additions & 4 deletions tests/Unit/Factory/GiftCardConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Setono\SyliusGiftCardPlugin\Factory\GiftCardConfigurationFactory;
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfiguration;
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationImage;
use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

Expand All @@ -24,16 +23,13 @@ public function it_creates_a_new_gift_card_configuration(): void
$giftCardConfiguration = new GiftCardConfiguration();

$decoratedFactory = $this->prophesize(FactoryInterface::class);
$imageFactory = $this->prophesize(FactoryInterface::class);
$defaultOrientation = PdfRenderingOptionsProviderInterface::ORIENTATION_PORTRAIT;
$defaultPageSize = PdfRenderingOptionsProviderInterface::PAGE_SIZE_A8;

$decoratedFactory->createNew()->willReturn($giftCardConfiguration);
$imageFactory->createNew()->willReturn(new GiftCardConfigurationImage());

$factory = new GiftCardConfigurationFactory(
$decoratedFactory->reveal(),
$imageFactory->reveal(),
$defaultOrientation,
$defaultPageSize
);
Expand Down

0 comments on commit 7e09d62

Please sign in to comment.