Skip to content

Commit

Permalink
Merge pull request #38 from Setono/more-upgrades
Browse files Browse the repository at this point in the history
More upgrades to make the plugin simpler and more robust
  • Loading branch information
loevgaard authored Jan 29, 2021
2 parents 31e4f25 + a3bbcfe commit eaa2030
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 283 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"psr/log": "^1.1",
"setono/doctrine-orm-batcher": "^0.6",
"setono/doctrine-orm-batcher-bundle": "^0.3.1",
"spatie/enum": "^3.7",
"sylius/resource-bundle": "^1.6",
"symfony/config": "^4.4 || ^5.0",
"symfony/console": "^4.4 || ^5.0",
Expand Down
26 changes: 0 additions & 26 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,3 @@ parameters:
message: "#^Parameter \\#1 \\$configuration of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:processConfiguration\\(\\) expects Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface, Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface\\|null given\\.$#"
count: 1
path: src/DependencyInjection/SetonoSyliusFeedExtension.php

-
message: "#^Method Setono\\\\SyliusFeedPlugin\\\\Feed\\\\Model\\\\Enum\\:\\:constant\\(\\) should return static\\(Setono\\\\SyliusFeedPlugin\\\\Feed\\\\Model\\\\Enum\\) but returns Setono\\\\SyliusFeedPlugin\\\\Feed\\\\Model\\\\Enum\\.$#"
count: 1
path: src/Feed/Model/Enum.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Feed/Model/Enum.php

-
message: "#^Parameter \\#2 \\$format \\(string\\) of method Setono\\\\SyliusFeedPlugin\\\\Normalizer\\\\ToStringNormalizer\\:\\:normalize\\(\\) should be contravariant with parameter \\$format \\(string\\|null\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:normalize\\(\\)$#"
count: 2
path: src/Normalizer/ToStringNormalizer.php

-
message: "#^Parameter \\#2 \\$format \\(string\\) of method Setono\\\\SyliusFeedPlugin\\\\Normalizer\\\\ToStringNormalizer\\:\\:supportsNormalization\\(\\) should be contravariant with parameter \\$format \\(string\\|null\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\ContextAwareNormalizerInterface\\:\\:supportsNormalization\\(\\)$#"
count: 1
path: src/Normalizer/ToStringNormalizer.php

-
message: "#^Parameter \\#2 \\$format \\(string\\) of method Setono\\\\SyliusFeedPlugin\\\\Normalizer\\\\ToStringNormalizer\\:\\:supportsNormalization\\(\\) should be contravariant with parameter \\$format \\(string\\|null\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:supportsNormalization\\(\\)$#"
count: 1
path: src/Normalizer/ToStringNormalizer.php

69 changes: 0 additions & 69 deletions src/Feed/Model/Enum.php

This file was deleted.

39 changes: 13 additions & 26 deletions src/Feed/Model/Google/Shopping/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,24 @@

namespace Setono\SyliusFeedPlugin\Feed\Model\Google\Shopping;

use Setono\SyliusFeedPlugin\Feed\Model\Enum;
use Spatie\Enum\Enum;

/**
* @method static self inStock()
* @method static self outOfStock()
* @method static self preOrder()
*/
final class Availability extends Enum
{
private const IN_STOCK = 'in stock';

private const OUT_OF_STOCK = 'out of stock';

private const PREORDER = 'preorder';

public static function inStock(): self
{
return self::constant(self::IN_STOCK);
}

public static function outOfStock(): self
{
return self::constant(self::OUT_OF_STOCK);
}

public static function preorder(): self
{
return self::constant(self::PREORDER);
}

public static function getValues(): array
/**
* @return array<string, string>
*/
protected static function values(): array
{
return [
self::IN_STOCK,
self::OUT_OF_STOCK,
self::PREORDER,
'inStock' => 'in stock',
'outOfStock' => 'out of stock',
'preOrder' => 'pre order',
];
}
}
36 changes: 6 additions & 30 deletions src/Feed/Model/Google/Shopping/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,13 @@

namespace Setono\SyliusFeedPlugin\Feed\Model\Google\Shopping;

use Setono\SyliusFeedPlugin\Feed\Model\Enum;
use Spatie\Enum\Enum;

/**
* @method static self new()
* @method static self refurbished()
* @method static self used()
*/
final class Condition extends Enum
{
private const NEW = 'new';

private const REFURBISHED = 'refurbished';

private const USED = 'used';

public static function new(): self
{
return self::constant(self::NEW);
}

public static function refurbished(): self
{
return self::constant(self::REFURBISHED);
}

public static function used(): self
{
return self::constant(self::USED);
}

public static function getValues(): array
{
return [
self::NEW,
self::REFURBISHED,
self::USED,
];
}
}
9 changes: 8 additions & 1 deletion src/Feed/Model/Google/Shopping/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Setono\SyliusFeedPlugin\Feed\Model\Google\Shopping;

final class DateRange
use JsonSerializable;

final class DateRange implements JsonSerializable
{
private DateTime $start;

Expand All @@ -20,4 +22,9 @@ public function __toString(): string
{
return $this->start . '/' . $this->end;
}

public function jsonSerialize(): string
{
return (string) $this;
}
}
10 changes: 8 additions & 2 deletions src/Feed/Model/Google/Shopping/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace Setono\SyliusFeedPlugin\Feed\Model\Google\Shopping;

use DateTime as BaseDateTime;
use JsonSerializable;
use Safe\DateTime as BaseDateTime;

final class DateTime extends BaseDateTime
final class DateTime extends BaseDateTime implements JsonSerializable
{
public function __toString(): string
{
return $this->format('Y-m-d\TH:iO');
}

public function jsonSerialize(): string
{
return (string) $this;
}
}
8 changes: 7 additions & 1 deletion src/Feed/Model/Google/Shopping/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Setono\SyliusFeedPlugin\Feed\Model\Google\Shopping;

use JsonSerializable;
use Webmozart\Assert\Assert;

final class Price
final class Price implements JsonSerializable
{
private int $amount;

Expand All @@ -27,4 +28,9 @@ public function __toString(): string
{
return round($this->amount / 100, 2) . ' ' . $this->currency;
}

public function jsonSerialize(): string
{
return (string) $this;
}
}
12 changes: 1 addition & 11 deletions src/FeedContext/Google/Shopping/ProductItemContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Setono\SyliusFeedPlugin\Model\GtinAwareInterface;
use Setono\SyliusFeedPlugin\Model\MpnAwareInterface;
use Setono\SyliusFeedPlugin\Model\SizeAwareInterface;
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ImageInterface;
use Sylius\Component\Core\Model\ImagesAwareInterface;
Expand All @@ -30,7 +29,6 @@
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;
Expand All @@ -41,23 +39,15 @@ class ProductItemContext implements ItemContextInterface

private CacheManager $cacheManager;

private ProductVariantPriceCalculatorInterface $productVariantPriceCalculator;

private ProductVariantResolverInterface $productVariantResolver;

private AvailabilityCheckerInterface $availabilityChecker;

public function __construct(
RouterInterface $router,
CacheManager $cacheManager,
ProductVariantResolverInterface $productVariantResolver,
ProductVariantPriceCalculatorInterface $productVariantPriceCalculator,
AvailabilityCheckerInterface $availabilityChecker
) {
$this->router = $router;
$this->cacheManager = $cacheManager;
$this->productVariantPriceCalculator = $productVariantPriceCalculator;
$this->productVariantResolver = $productVariantResolver;
$this->availabilityChecker = $availabilityChecker;
}

Expand Down Expand Up @@ -94,7 +84,7 @@ public function getContextList(object $product, ChannelInterface $channel, Local

$data->setCondition(
$product instanceof ConditionAwareInterface ?
Condition::fromValue((string) $product->getCondition()) : Condition::new()
new Condition((string) $product->getCondition()) : Condition::new()
);

if (null !== $productType) {
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Handler/GenerateBatchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusFeedPlugin\Message\Handler;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
use const JSON_INVALID_UTF8_IGNORE;
use const JSON_PRESERVE_ZERO_FRACTION;
Expand Down
34 changes: 0 additions & 34 deletions src/Normalizer/ToStringNormalizer.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<import resource="services/generator.xml"/>
<import resource="services/menu.xml"/>
<import resource="services/message_handler.xml"/>
<import resource="services/normalizer.xml"/>
<import resource="services/processor.xml"/>
<import resource="services/registry.xml"/>
<import resource="services/resolver.xml"/>
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/config/services/command.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Setono\SyliusFeedPlugin\Command\ProcessFeedsCommand">
<argument type="service" id="setono_sylius_feed.processor.feed" />
<argument type="service" id="setono_sylius_feed.processor.feed"/>

<tag name="console.command" />
<tag name="console.command"/>
</service>
</services>
</container>
Loading

0 comments on commit eaa2030

Please sign in to comment.