diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index da53794..4512227 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -98,7 +98,7 @@ jobs: run: "composer config --unset require-dev" - name: "Add shipmonk/composer-dependency-analyser to composer.json" - run: "composer require --dev --no-install --no-plugins --no-scripts shipmonk/composer-dependency-analyser" + run: "composer require --dev --no-install --no-update --no-plugins --no-scripts shipmonk/composer-dependency-analyser" - name: "Install composer dependencies" uses: "ramsey/composer-install@v3" diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index f628b86..6dbaf1c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -5,9 +5,9 @@ namespace Setono\SyliusPeakPlugin\DependencyInjection; use Setono\SyliusPeakPlugin\Model\InventoryUpdate; -use Setono\SyliusPeakPlugin\Model\RegisteredWebhooks; use Setono\SyliusPeakPlugin\Model\UploadOrderRequest; use Setono\SyliusPeakPlugin\Model\UploadProductVariantRequest; +use Setono\SyliusPeakPlugin\Model\WebhookRegistration; use Sylius\Component\Resource\Factory\Factory; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -64,14 +64,14 @@ private function addResourcesSection(ArrayNodeDefinition $node): void ->end() ->end() ->end() - ->arrayNode('registered_webhooks') // todo rename to webhook_registration? + ->arrayNode('webhook_registration') ->addDefaultsIfNotSet() ->children() ->variableNode('options')->end() ->arrayNode('classes') ->addDefaultsIfNotSet() ->children() - ->scalarNode('model')->defaultValue(RegisteredWebhooks::class)->cannotBeEmpty()->end() + ->scalarNode('model')->defaultValue(WebhookRegistration::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(Factory::class)->end() ->end() diff --git a/src/Factory/RegisteredWebhooksFactory.php b/src/Factory/WebhookRegistrationFactory.php similarity index 65% rename from src/Factory/RegisteredWebhooksFactory.php rename to src/Factory/WebhookRegistrationFactory.php index 48b76b5..e47abe6 100644 --- a/src/Factory/RegisteredWebhooksFactory.php +++ b/src/Factory/WebhookRegistrationFactory.php @@ -4,25 +4,25 @@ namespace Setono\SyliusPeakPlugin\Factory; -use Setono\SyliusPeakPlugin\Model\RegisteredWebhooksInterface; +use Setono\SyliusPeakPlugin\Model\WebhookRegistrationInterface; use Sylius\Component\Resource\Factory\FactoryInterface; -final class RegisteredWebhooksFactory implements RegisteredWebhooksFactoryInterface +final class WebhookRegistrationFactory implements WebhookRegistrationFactoryInterface { public function __construct( - /** @var FactoryInterface $decoratedFactory */ + /** @var FactoryInterface $decoratedFactory */ private readonly FactoryInterface $decoratedFactory, ) { } /** @psalm-suppress MoreSpecificReturnType */ - public function createNew(): RegisteredWebhooksInterface + public function createNew(): WebhookRegistrationInterface { /** @psalm-suppress LessSpecificReturnStatement */ return $this->decoratedFactory->createNew(); } - public function createFromData(string $version, array $webhooks): RegisteredWebhooksInterface + public function createFromData(string $version, array $webhooks): WebhookRegistrationInterface { $obj = $this->createNew(); $obj->setVersion($version); diff --git a/src/Factory/RegisteredWebhooksFactoryInterface.php b/src/Factory/WebhookRegistrationFactoryInterface.php similarity index 52% rename from src/Factory/RegisteredWebhooksFactoryInterface.php rename to src/Factory/WebhookRegistrationFactoryInterface.php index e5b1fab..53abc74 100644 --- a/src/Factory/RegisteredWebhooksFactoryInterface.php +++ b/src/Factory/WebhookRegistrationFactoryInterface.php @@ -5,18 +5,18 @@ namespace Setono\SyliusPeakPlugin\Factory; use Setono\PeakWMS\DataTransferObject\Webhook\Webhook; -use Setono\SyliusPeakPlugin\Model\RegisteredWebhooksInterface; +use Setono\SyliusPeakPlugin\Model\WebhookRegistrationInterface; use Sylius\Component\Resource\Factory\FactoryInterface; /** - * @extends FactoryInterface + * @extends FactoryInterface */ -interface RegisteredWebhooksFactoryInterface extends FactoryInterface +interface WebhookRegistrationFactoryInterface extends FactoryInterface { - public function createNew(): RegisteredWebhooksInterface; + public function createNew(): WebhookRegistrationInterface; /** * @param list $webhooks */ - public function createFromData(string $version, array $webhooks): RegisteredWebhooksInterface; + public function createFromData(string $version, array $webhooks): WebhookRegistrationInterface; } diff --git a/src/Model/RegisteredWebhooks.php b/src/Model/WebhookRegistration.php similarity index 93% rename from src/Model/RegisteredWebhooks.php rename to src/Model/WebhookRegistration.php index 67a896e..553c6e0 100644 --- a/src/Model/RegisteredWebhooks.php +++ b/src/Model/WebhookRegistration.php @@ -4,7 +4,7 @@ namespace Setono\SyliusPeakPlugin\Model; -class RegisteredWebhooks implements RegisteredWebhooksInterface +class WebhookRegistration implements WebhookRegistrationInterface { protected ?int $id = null; diff --git a/src/Model/RegisteredWebhooksInterface.php b/src/Model/WebhookRegistrationInterface.php similarity index 88% rename from src/Model/RegisteredWebhooksInterface.php rename to src/Model/WebhookRegistrationInterface.php index 659b040..614d609 100644 --- a/src/Model/RegisteredWebhooksInterface.php +++ b/src/Model/WebhookRegistrationInterface.php @@ -6,7 +6,7 @@ use Sylius\Component\Resource\Model\ResourceInterface; -interface RegisteredWebhooksInterface extends ResourceInterface +interface WebhookRegistrationInterface extends ResourceInterface { public function getId(): ?int; diff --git a/src/Registrar/WebhookRegistrar.php b/src/Registrar/WebhookRegistrar.php index 292a513..ea76e31 100644 --- a/src/Registrar/WebhookRegistrar.php +++ b/src/Registrar/WebhookRegistrar.php @@ -8,8 +8,8 @@ use Setono\PeakWMS\DataTransferObject\Webhook\Name; use Setono\PeakWMS\DataTransferObject\Webhook\Webhook; use Setono\SyliusPeakPlugin\Exception\WebhookRegistrationException; -use Setono\SyliusPeakPlugin\Factory\RegisteredWebhooksFactoryInterface; -use Setono\SyliusPeakPlugin\Model\RegisteredWebhooksInterface; +use Setono\SyliusPeakPlugin\Factory\WebhookRegistrationFactoryInterface; +use Setono\SyliusPeakPlugin\Model\WebhookRegistrationInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -18,8 +18,8 @@ final class WebhookRegistrar implements WebhookRegistrarInterface public function __construct( private readonly ClientInterface $client, private readonly UrlGeneratorInterface $urlGenerator, - private readonly RepositoryInterface $registeredWebhooksRepository, - private readonly RegisteredWebhooksFactoryInterface $registeredWebhooksFactory, + private readonly RepositoryInterface $webhookRegistrationRepository, + private readonly WebhookRegistrationFactoryInterface $webhookRegistrationFactory, ) { } @@ -28,11 +28,11 @@ public function register(): void /** * This will delete all webhooks registered with Peak WMS and also remove the logs from the database * - * @var RegisteredWebhooksInterface $registeredWebhooks + * @var WebhookRegistrationInterface $webhookRegistration */ - foreach ($this->registeredWebhooksRepository->findAll() as $registeredWebhooks) { + foreach ($this->webhookRegistrationRepository->findAll() as $webhookRegistration) { /** @var mixed $webhook */ - foreach ($registeredWebhooks->getWebhooks() as $webhook) { + foreach ($webhookRegistration->getWebhooks() as $webhook) { if (!is_array($webhook) || !isset($webhook['id']) || !is_int($webhook['id'])) { throw new WebhookRegistrationException('The webhooks are not in the correct format'); } @@ -40,7 +40,7 @@ public function register(): void $this->client->webhook()->delete($webhook['id']); } - $this->registeredWebhooksRepository->remove($registeredWebhooks); + $this->webhookRegistrationRepository->remove($webhookRegistration); } $postedWebhooks = []; @@ -49,21 +49,21 @@ public function register(): void $postedWebhooks[] = $this->client->webhook()->create($webhook); } - $registeredWebhooks = $this->registeredWebhooksFactory->createFromData($this->getVersion(), $postedWebhooks); - $this->registeredWebhooksRepository->add($registeredWebhooks); + $webhookRegistration = $this->webhookRegistrationFactory->createFromData($this->getVersion(), $postedWebhooks); + $this->webhookRegistrationRepository->add($webhookRegistration); } public function outOfDate(): bool { - /** @var list $registeredWebhooks */ - $registeredWebhooks = $this->registeredWebhooksRepository->findAll(); - if (count($registeredWebhooks) !== 1) { + /** @var list $webhookRegistrations */ + $webhookRegistrations = $this->webhookRegistrationRepository->findAll(); + if (count($webhookRegistrations) !== 1) { // We should only have one registered webhooks object. If we have more, it's a bug, and we consider it out of date. // If we have none, we consider it out of date because they need to be registered. return true; } - return $registeredWebhooks[0]->getVersion() !== $this->getVersion(); + return $webhookRegistrations[0]->getVersion() !== $this->getVersion(); } private function getVersion(): string diff --git a/src/Resources/config/doctrine/model/RegisteredWebhooks.orm.xml b/src/Resources/config/doctrine/model/RegisteredWebhooks.orm.xml index 9b74ab4..39c8c28 100644 --- a/src/Resources/config/doctrine/model/RegisteredWebhooks.orm.xml +++ b/src/Resources/config/doctrine/model/RegisteredWebhooks.orm.xml @@ -4,8 +4,8 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + diff --git a/src/Resources/config/services/factory.xml b/src/Resources/config/services/factory.xml index 973c14d..9ba88df 100644 --- a/src/Resources/config/services/factory.xml +++ b/src/Resources/config/services/factory.xml @@ -4,9 +4,9 @@ - - + + - - + + diff --git a/tests/DependencyInjection/SetonoSyliusPeakWMSExtensionTest.php b/tests/DependencyInjection/SetonoSyliusPeakWMSExtensionTest.php index 980a6b1..bcbcd03 100644 --- a/tests/DependencyInjection/SetonoSyliusPeakWMSExtensionTest.php +++ b/tests/DependencyInjection/SetonoSyliusPeakWMSExtensionTest.php @@ -26,6 +26,6 @@ public function after_loading_the_correct_parameter_has_been_set(): void { $this->load(); - $this->assertContainerBuilderHasParameter('setono_sylius_peak.api_key', '%env(PEAK_WMS_API_KEY)%'); + $this->assertContainerBuilderHasParameter('setono_sylius_peak.api.api_key', '%env(PEAK_WMS_API_KEY)%'); } }