Skip to content

Commit

Permalink
feat: make ShopRepository generic
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 9, 2023
1 parent d2ff1cf commit 48a09db
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/AppLifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
class AppLifecycle
{
/**
* @param ShopRepositoryInterface<ShopInterface> $shopRepository
*/
public function __construct(
private readonly RegistrationService $registrationService,
private readonly ShopResolver $shopResolver,
Expand Down
4 changes: 4 additions & 0 deletions src/Registration/RegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
use Shopware\App\SDK\Exception\ShopNotFoundException;
use Shopware\App\SDK\Exception\SignatureNotFoundException;
use Shopware\App\SDK\Exception\SignatureInvalidException;
use Shopware\App\SDK\Shop\ShopInterface;
use Shopware\App\SDK\Shop\ShopRepositoryInterface;

class RegistrationService
{
/**
* @param ShopRepositoryInterface<ShopInterface> $shopRepository
*/
public function __construct(
private readonly AppConfiguration $appConfiguration,
private readonly ShopRepositoryInterface $shopRepository,
Expand Down
15 changes: 15 additions & 0 deletions src/Shop/ShopRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@

namespace Shopware\App\SDK\Shop;

/**
* @template T of ShopInterface
*/
interface ShopRepositoryInterface
{
/**
* @return T
*/
public function createShopStruct(string $shopId, string $shopUrl, string $shopSecret): ShopInterface;

/**
* @param T $shop
*/
public function createShop(ShopInterface $shop): void;

/**
* @return T|null
*/
public function getShopFromId(string $shopId): ShopInterface|null;

/**
* @param T $shop
*/
public function updateShop(ShopInterface $shop): void;

public function deleteShop(string $shopId): void;
Expand Down
3 changes: 3 additions & 0 deletions src/Shop/ShopResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
class ShopResolver
{
/**
* @param ShopRepositoryInterface<ShopInterface> $shopRepository
*/
public function __construct(private readonly ShopRepositoryInterface $shopRepository, private readonly RequestVerifier $requestVerifier = new RequestVerifier())
{
}
Expand Down
5 changes: 4 additions & 1 deletion src/Test/MockShopRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Shopware\App\SDK\Shop\ShopInterface;
use Shopware\App\SDK\Shop\ShopRepositoryInterface;

/**
* @implements ShopRepositoryInterface<MockShop>
*/
class MockShopRepository implements ShopRepositoryInterface
{
/**
* @var array<string, ShopInterface>
* @var array<string, MockShop>
*/
public array $shops = [];

Expand Down

0 comments on commit 48a09db

Please sign in to comment.