Skip to content

Commit

Permalink
Remove the usage of NonExistingIndexException
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jul 3, 2024
1 parent 457f872 commit 264cee0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 34 deletions.
13 changes: 6 additions & 7 deletions src/Config/IndexRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Setono\SyliusMeilisearchPlugin\Config;

use Setono\SyliusMeilisearchPlugin\Exception\NonExistingIndexException;

/**
* @implements \IteratorAggregate<string, Index>
*/
Expand All @@ -21,19 +19,20 @@ final class IndexRegistry implements \IteratorAggregate, IndexRegistryInterface
public function add(Index $index): void
{
if (isset($this->indexes[$index->name])) {
throw new \InvalidArgumentException(sprintf('An index with the name %s already exists', $index->name)); // todo better exception
throw new \InvalidArgumentException(sprintf('An index with the name %s already exists', $index->name));
}

$this->indexes[$index->name] = $index;
}

/**
* @throws NonExistingIndexException if no index exists with the given name
*/
public function get(string $name): Index
{
if (!isset($this->indexes[$name])) {
throw NonExistingIndexException::fromName($name, array_keys($this->indexes));
throw new \InvalidArgumentException(sprintf(
'No index exists with the name %s. Available indexes are: [%s]',
implode(', ', array_keys($this->indexes)),
$name,
));
}

return $this->indexes[$name];
Expand Down
4 changes: 1 addition & 3 deletions src/Config/IndexRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Setono\SyliusMeilisearchPlugin\Config;

use Setono\SyliusMeilisearchPlugin\Exception\NonExistingIndexException;

/**
* @extends \Traversable<Index>
*/
Expand All @@ -17,7 +15,7 @@ interface IndexRegistryInterface extends \Traversable
public function add(Index $index): void;

/**
* @throws NonExistingIndexException if no index exists with the given name
* @throws \InvalidArgumentException if no index exists with the given name
*/
public function get(string $name): Index;

Expand Down
22 changes: 0 additions & 22 deletions src/Exception/NonExistingIndexException.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/Message/Handler/IndexHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Setono\SyliusMeilisearchPlugin\Message\Handler;

use Setono\SyliusMeilisearchPlugin\Config\IndexRegistryInterface;
use Setono\SyliusMeilisearchPlugin\Exception\NonExistingIndexException;
use Setono\SyliusMeilisearchPlugin\Message\Command\Index;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;

Expand All @@ -19,7 +18,7 @@ public function __invoke(Index $message): void
{
try {
$this->indexRegistry->get($message->index)->indexer()->index();
} catch (NonExistingIndexException $e) {
} catch (\InvalidArgumentException $e) {
throw new UnrecoverableMessageHandlingException(message: $e->getMessage(), previous: $e);
}
}
Expand Down

0 comments on commit 264cee0

Please sign in to comment.