Skip to content

Commit

Permalink
Merge pull request #17 from stefandoorn/refactor-product-detail-impre…
Browse files Browse the repository at this point in the history
…ssion

Refactor Product Detail Impression
  • Loading branch information
stefandoorn authored Nov 5, 2017
2 parents bd4635a + 6a56187 commit a5983b6
Show file tree
Hide file tree
Showing 19 changed files with 590 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
/vendor/
/etc/build/*
!/etc/build/.gitkeep

# PHPStorm
.idea/
2 changes: 1 addition & 1 deletion src/EventListener/CheckoutStepListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Class CheckoutStepListener
* @package GtmEnhancedEcommerce\EventListener
*/
class CheckoutStepListener
final class CheckoutStepListener
{
/**
* @var CheckoutStepInterface
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/ThankYouListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Class ThankYouListener
* @package GtmEnhancedEcommerce\EventListener
*/
class ThankYouListener
final class ThankYouListener
{

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Object/Factory/ProductDetailFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object\Factory;

use GtmEnhancedEcommercePlugin\Object\ProductDetail;
use GtmEnhancedEcommercePlugin\Object\ProductDetailInterface;

final class ProductDetailFactory implements ProductDetailFactoryInterface
{
/**
* @inheritDoc
*/
public function create(): ProductDetailInterface
{
return new ProductDetail();
}
}
17 changes: 17 additions & 0 deletions src/Object/Factory/ProductDetailFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object\Factory;

use GtmEnhancedEcommercePlugin\Object\ProductDetailInterface;

/**
* Interface ProductDetailFactoryInterface
* @package GtmEnhancedEcommercePlugin\Object\Factory
*/
interface ProductDetailFactoryInterface
{
/**
* @return ProductDetailInterface
*/
public function create(): ProductDetailInterface;
}
21 changes: 21 additions & 0 deletions src/Object/Factory/ProductDetailImpressionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object\Factory;

use GtmEnhancedEcommercePlugin\Object\ProductDetailImpression;
use GtmEnhancedEcommercePlugin\Object\ProductDetailImpressionInterface;

/**
* Class ProductDetailImpressionFactory
* @package GtmEnhancedEcommercePlugin\Object\Factory
*/
final class ProductDetailImpressionFactory implements ProductDetailImpressionFactoryInterface
{
/**
* @inheritDoc
*/
public function create(): ProductDetailImpressionInterface
{
return new ProductDetailImpression();
}
}
17 changes: 17 additions & 0 deletions src/Object/Factory/ProductDetailImpressionFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object\Factory;

use GtmEnhancedEcommercePlugin\Object\ProductDetailImpressionInterface;

/**
* Interface ProductDetailImpressionFactoryInterface
* @package GtmEnhancedEcommercePlugin\Object\Factory
*/
interface ProductDetailImpressionFactoryInterface
{
/**
* @return ProductDetailImpressionInterface
*/
public function create(): ProductDetailImpressionInterface;
}
129 changes: 129 additions & 0 deletions src/Object/ProductDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object;

/**
* Class ProductDetail
* @package GtmEnhancedEcommercePlugin\Object
*/
final class ProductDetail implements ProductDetailInterface
{
/**
* @var string
*/
private $name;

/**
* @var int
*/
private $id;

/**
* @var float
*/
private $price;

/**
* @var string|null
*/
private $category;

/**
* @var string|null
*/
private $variant;

/**
* @inheritdoc
*/
public function getName(): string
{
return $this->name;
}

/**
* @inheritdoc
*/
public function setName(string $name): void
{
$this->name = $name;
}

/**
* @inheritdoc
*/
public function getId(): int
{
return $this->id;
}

/**
* @inheritdoc
*/
public function setId(int $id): void
{
$this->id = $id;
}

/**
* @inheritdoc
*/
public function getPrice(): float
{
return $this->price;
}

/**
* @inheritdoc
*/
public function setPrice(float $price): void
{
$this->price = $price;
}

/**
* @inheritdoc
*/
public function getCategory(): ?string
{
return $this->category;
}

/**
* @inheritdoc
*/
public function setCategory(?string $category)
{
$this->category = $category;
}

/**
* @inheritdoc
*/
public function getVariant(): ?string
{
return $this->variant;
}

/**
* @inheritdoc
*/
public function setVariant(?string $variant)
{
$this->variant = $variant;
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'name' => $this->name,
'id' => $this->id,
'price' => $this->price,
'category' => $this->category ?? '',
'variant' => $this->variant ?? '',
];
}
}
33 changes: 33 additions & 0 deletions src/Object/ProductDetailImpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object;

/**
* Class ProductDetailImpressionData
* @package GtmEnhancedEcommercePlugin\Object
*/
final class ProductDetailImpression implements ProductDetailImpressionInterface
{
/**
* @var array|ProductDetailInterface[]
*/
private $variants = [];

/**
* @inheritDoc
*/
public function add(ProductDetailInterface $productDetail): void
{
$this->variants[] = $productDetail;
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return array_map(function(ProductDetailInterface $productDetail) {
return $productDetail->toArray();
}, $this->variants);
}
}
20 changes: 20 additions & 0 deletions src/Object/ProductDetailImpressionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object;

/**
* Interface ProductDetailImpressionDataInterface
* @package GtmEnhancedEcommercePlugin\Object
*/
interface ProductDetailImpressionInterface
{
/**
* @param ProductDetailInterface $productDetail
*/
public function add(ProductDetailInterface $productDetail): void;

/**
* @return array
*/
public function toArray(): array;
}
65 changes: 65 additions & 0 deletions src/Object/ProductDetailInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php declare(strict_types=1);

namespace GtmEnhancedEcommercePlugin\Object;

/**
* Interface ProductDetailInterface
* @package GtmEnhancedEcommercePlugin\Object
*/
interface ProductDetailInterface
{
/**
* @return string
*/
public function getName(): string;

/**
* @param string $name
*/
public function setName(string $name): void;

/**
* @return int
*/
public function getId(): int;

/**
* @param int $id
*/
public function setId(int $id): void;

/**
* @return float
*/
public function getPrice(): float;

/**
* @param float $price
*/
public function setPrice(float $price): void;

/**
* @return null|string
*/
public function getCategory(): ?string;

/**
* @param null|string $category
*/
public function setCategory(?string $category);

/**
* @return null|string
*/
public function getVariant(): ?string;

/**
* @param null|string $variant
*/
public function setVariant(?string $variant);

/**
* @return array
*/
public function toArray(): array;
}
2 changes: 1 addition & 1 deletion src/Resolver/CheckoutStepResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Class CheckoutStepResolver
* @package GtmEnhancedEcommercePlugin\Resolver
*/
class CheckoutStepResolver implements CheckoutStepResolverInterface
final class CheckoutStepResolver implements CheckoutStepResolverInterface
{
/**
* @inheritdoc
Expand Down
Loading

0 comments on commit a5983b6

Please sign in to comment.