Skip to content

Commit

Permalink
Add interfaces to services
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 committed Aug 14, 2023
1 parent fc2bf8a commit 3bc22cf
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Command/ImportModListsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Command;

use App\Service\LegacyModListImport\ModListImport;
use App\Service\LegacyModListImport\ModListImportInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -13,7 +13,7 @@
class ImportModListsCommand extends Command
{
public function __construct(
private ModListImport $modListImport
private ModListImportInterface $modListImport
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Controller;

use App\Service\Mission\MissionClient;
use App\Service\Mission\MissionClientInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -16,7 +16,7 @@
class HomeController extends AbstractController
{
public function __construct(
private MissionClient $missionClient,
private MissionClientInterface $missionClient,
private LoggerInterface $logger
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ModListPublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Repository\Mod\ModRepository;
use App\Repository\ModList\ModListRepository;
use App\Security\Enum\PermissionsEnum;
use App\Service\Mission\MissionClient;
use App\Service\Mission\MissionClientInterface;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -25,7 +25,7 @@ public function __construct(
private LoggerInterface $logger,
private ModRepository $modRepository,
private ModListRepository $modListRepository,
private MissionClient $missionClient,
private MissionClientInterface $missionClient,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Form/Dlc/DataTransformer/DlcFormDtoDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use App\Form\FormDtoInterface;
use App\Form\RegisteredDataTransformerInterface;
use App\Service\Steam\Helper\SteamHelper;
use App\Service\Steam\SteamApiClient;
use App\Service\Steam\SteamApiClientInterface;
use Ramsey\Uuid\Uuid;

class DlcFormDtoDataTransformer implements RegisteredDataTransformerInterface
{
public function __construct(
private SteamApiClient $steamApiClient
private SteamApiClientInterface $steamApiClient
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Form/Mod/DataTransformer/ModFormDtoDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use App\Form\Mod\Dto\ModFormDto;
use App\Form\RegisteredDataTransformerInterface;
use App\Service\Steam\Helper\SteamHelper;
use App\Service\Steam\SteamApiClient;
use App\Service\Steam\SteamApiClientInterface;
use Ramsey\Uuid\Uuid;

class ModFormDtoDataTransformer implements RegisteredDataTransformerInterface
{
public function __construct(
private SteamApiClient $steamApiClient
private SteamApiClientInterface $steamApiClient
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/LegacyModListImport/DtoToEntityConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @see https://github.com/ArmaForces/modlist/blob/master/src/util/mods.js
*/
class DtoToEntityConverter
class DtoToEntityConverter implements DtoToEntityConverterInterface
{
public function convert(ModCsvEntryDto $modCsvEntryDto): AbstractMod
{
Expand Down
13 changes: 13 additions & 0 deletions src/Service/LegacyModListImport/DtoToEntityConverterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Service\LegacyModListImport;

use App\Entity\Mod\AbstractMod;
use App\Service\LegacyModListImport\Dto\ModCsvEntryDto;

interface DtoToEntityConverterInterface
{
public function convert(ModCsvEntryDto $modCsvEntryDto): AbstractMod;
}
2 changes: 1 addition & 1 deletion src/Service/LegacyModListImport/ModListCsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Service\LegacyModListImport\Dto\ModCsvEntryDto;
use League\Csv\Reader;

class ModListCsvReader
class ModListCsvReader implements ModListCsvReaderInterface
{
protected const COLUMN_INDEX_ID = 0;
protected const COLUMN_INDEX_NAME = 1;
Expand Down
10 changes: 10 additions & 0 deletions src/Service/LegacyModListImport/ModListCsvReaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Service\LegacyModListImport;

interface ModListCsvReaderInterface
{
public function readCsvRow(string $path, string $delimiter = ';'): \Generator;
}
6 changes: 3 additions & 3 deletions src/Service/LegacyModListImport/ModListImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
use Ramsey\Uuid\Uuid;
use Symfony\Component\Finder\Finder;

class ModListImport
class ModListImport implements ModListImportInterface
{
public function __construct(
private EntityManagerInterface $entityManager,
private ModListCsvReader $modListCsvReader,
private DtoToEntityConverter $dtoToEntityConverter,
private ModListCsvReaderInterface $modListCsvReader,
private DtoToEntityConverterInterface $dtoToEntityConverter,
private SteamWorkshopModRepository $steamWorkshopModRepository,
private DirectoryModRepository $directoryModRepository
) {
Expand Down
10 changes: 10 additions & 0 deletions src/Service/LegacyModListImport/ModListImportInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Service\LegacyModListImport;

interface ModListImportInterface
{
public function importFromDirectory(string $path, string $extension = '.csv'): void;
}
2 changes: 1 addition & 1 deletion src/Service/Mission/MissionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\HttpClient\ScopingHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class MissionClient
class MissionClient implements MissionClientInterface
{
public function __construct(
private HttpClientInterface $client,
Expand Down
20 changes: 20 additions & 0 deletions src/Service/Mission/MissionClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Service\Mission;

use App\Service\Mission\Dto\MissionDto;

interface MissionClientInterface
{
public function getMissions(bool $includeArchive = true, int $ttl = 600): \Generator;

public function getNextUpcomingMission(): ?MissionDto;

public function getCurrentMission(): ?MissionDto;

public function getArchivedMissions(): array;

public function getUpcomingMissions(): array;
}
2 changes: 1 addition & 1 deletion src/Service/Steam/SteamApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class SteamApiClient
class SteamApiClient implements SteamApiClientInterface
{
public function __construct(
private HttpClientInterface $httpClient
Expand Down
15 changes: 15 additions & 0 deletions src/Service/Steam/SteamApiClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace App\Service\Steam;

use App\Service\Steam\Dto\AppInfoDto;
use App\Service\Steam\Dto\WorkshopItemInfoDto;

interface SteamApiClientInterface
{
public function getWorkshopItemInfo(int $itemId): WorkshopItemInfoDto;

public function getAppInfo(int $appId): AppInfoDto;
}
2 changes: 1 addition & 1 deletion src/Service/Version/VersionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Service\Version;

class VersionProvider
class VersionProvider implements VersionProviderInterface
{
public function __construct(
private string $projectDir,
Expand Down
10 changes: 10 additions & 0 deletions src/Service/Version/VersionProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Service\Version;

interface VersionProviderInterface
{
public function getVersion(): string;
}
4 changes: 2 additions & 2 deletions src/Twig/VersionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace App\Twig;

use App\Service\Version\VersionProvider;
use App\Service\Version\VersionProviderInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class VersionExtension extends AbstractExtension
{
public function __construct(
private VersionProvider $version
private VersionProviderInterface $version
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Dlc/SteamStoreArma3DlcUrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Service\Steam\Exception\AppNotFoundException;
use App\Service\Steam\Helper\Exception\InvalidAppUrlFormatException;
use App\Service\Steam\Helper\SteamHelper;
use App\Service\Steam\SteamApiClient;
use App\Service\Steam\SteamApiClientInterface;
use App\Validator\AbstractValidator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
Expand All @@ -20,7 +20,7 @@ class SteamStoreArma3DlcUrlValidator extends AbstractValidator

public function __construct(
EntityManagerInterface $entityManager,
private SteamApiClient $steamApiClient
private SteamApiClientInterface $steamApiClient
) {
parent::__construct($entityManager);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Mod/SteamWorkshopArma3ModUrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Service\Steam\Exception\WorkshopItemNotFoundException;
use App\Service\Steam\Helper\Exception\InvalidWorkshopItemUrlFormatException;
use App\Service\Steam\Helper\SteamHelper;
use App\Service\Steam\SteamApiClient;
use App\Service\Steam\SteamApiClientInterface;
use App\Validator\AbstractValidator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Constraint;
Expand All @@ -20,7 +20,7 @@ class SteamWorkshopArma3ModUrlValidator extends AbstractValidator

public function __construct(
EntityManagerInterface $entityManager,
private SteamApiClient $steamApiClient
private SteamApiClientInterface $steamApiClient
) {
parent::__construct($entityManager);
}
Expand Down

0 comments on commit 3bc22cf

Please sign in to comment.