Skip to content

Commit

Permalink
style: Construct promotion and tests fixes for v12
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Jan 17, 2024
1 parent ca09ad3 commit 1c062a1
Show file tree
Hide file tree
Showing 33 changed files with 79 additions and 184 deletions.
7 changes: 1 addition & 6 deletions Classes/Check/BackendUserCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@

class BackendUserCheck
{
protected SiteConfigurationService $siteConfigurationService;

public function __construct(SiteConfigurationService $siteConfigurationService)
{
$this->siteConfigurationService = $siteConfigurationService;
}
public function __construct(protected SiteConfigurationService $siteConfigurationService) {}

public function __invoke(CheckLanguageDetectionEvent $event): void
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Check/EnableCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@

class EnableCheck
{
protected SiteConfigurationService $siteConfigurationService;

public function __construct(SiteConfigurationService $siteConfigurationService)
{
$this->siteConfigurationService = $siteConfigurationService;
}
public function __construct(protected SiteConfigurationService $siteConfigurationService) {}

public function __invoke(CheckLanguageDetectionEvent $event): void
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Check/PathCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@

class PathCheck
{
protected SiteConfigurationService $siteConfigurationService;

public function __construct(SiteConfigurationService $siteConfigurationService)
{
$this->siteConfigurationService = $siteConfigurationService;
}
public function __construct(protected SiteConfigurationService $siteConfigurationService) {}

public function __invoke(CheckLanguageDetectionEvent $event): void
{
Expand Down
18 changes: 6 additions & 12 deletions Classes/Detect/GeoPluginDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@
*/
class GeoPluginDetect
{
protected IpLocation $ipLocation;
protected LanguageService $languageService;
protected SiteConfigurationService $siteConfigurationService;
protected LocaleCollectionSortService $localeCollectionSortService;

public function __construct(IpLocation $ipLocation, LanguageService $languageService, SiteConfigurationService $siteConfigurationService, LocaleCollectionSortService $localeCollectionSortService)
{
$this->ipLocation = $ipLocation;
$this->languageService = $languageService;
$this->siteConfigurationService = $siteConfigurationService;
$this->localeCollectionSortService = $localeCollectionSortService;
}
public function __construct(
protected IpLocation $ipLocation,
protected LanguageService $languageService,
protected SiteConfigurationService $siteConfigurationService,
protected LocaleCollectionSortService $localeCollectionSortService
) {}

public function __invoke(DetectUserLanguagesEvent $event): void
{
Expand Down
15 changes: 5 additions & 10 deletions Classes/Detect/MaxMindDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@

class MaxMindDetect
{
protected LanguageService $languageService;
protected SiteConfigurationService $siteConfigurationService;
protected LocaleCollectionSortService $localeCollectionSortService;

public function __construct(LanguageService $languageService, SiteConfigurationService $siteConfigurationService, LocaleCollectionSortService $localeCollectionSortService)
{
$this->languageService = $languageService;
$this->siteConfigurationService = $siteConfigurationService;
$this->localeCollectionSortService = $localeCollectionSortService;
}
public function __construct(
protected LanguageService $languageService,
protected SiteConfigurationService $siteConfigurationService,
protected LocaleCollectionSortService $localeCollectionSortService
) {}

public function __invoke(DetectUserLanguagesEvent $event): void
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Domain/Model/Dto/LocaleValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@

class LocaleValueObject
{
protected string $locale;

public function __construct(string $locale)
{
$this->locale = $locale;
}
public function __construct(protected string $locale) {}

public function getLocale(): string
{
Expand Down
58 changes: 12 additions & 46 deletions Classes/Domain/Model/Dto/SiteConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,19 @@

class SiteConfiguration
{
protected bool $enableLanguageDetection;

protected bool $disableRedirectWithBackendSession;

protected string $addIpLocationToBrowserLanguage;

protected bool $allowAllPaths;

protected int $redirectHttpStatusCode;

protected string $forwardRedirectParameters;

protected int $fallbackDetectionLanguage;

protected string $maxMindDatabasePath;

protected int $maxMindAccountId;

protected string $maxMindLicenseKey;

protected string $maxMindMode;

public function __construct(
bool $enableLanguageDetection,
bool $disableRedirectWithBackendSession,
string $addIpLocationToBrowserLanguage,
bool $allowAllPaths,
int $redirectHttpStatusCode,
string $forwardRedirectParameters,
int $fallbackDetectionLanguage,
string $maxMindDatabasePath,
int $maxMindAccountId,
string $maxMindLicenseKey,
string $maxMindMode
) {
$this->enableLanguageDetection = $enableLanguageDetection;
$this->disableRedirectWithBackendSession = $disableRedirectWithBackendSession;
$this->addIpLocationToBrowserLanguage = $addIpLocationToBrowserLanguage;
$this->allowAllPaths = $allowAllPaths;
$this->redirectHttpStatusCode = $redirectHttpStatusCode;
$this->forwardRedirectParameters = $forwardRedirectParameters;
$this->fallbackDetectionLanguage = $fallbackDetectionLanguage;
$this->maxMindDatabasePath = $maxMindDatabasePath;
$this->maxMindAccountId = $maxMindAccountId;
$this->maxMindLicenseKey = $maxMindLicenseKey;
$this->maxMindMode = $maxMindMode;
}
protected bool $enableLanguageDetection,
protected bool $disableRedirectWithBackendSession,
protected string $addIpLocationToBrowserLanguage,
protected bool $allowAllPaths,
protected int $redirectHttpStatusCode,
protected string $forwardRedirectParameters,
protected int $fallbackDetectionLanguage,
protected string $maxMindDatabasePath,
protected int $maxMindAccountId,
protected string $maxMindLicenseKey,
protected string $maxMindMode
) {}

public function isEnableLanguageDetection(): bool
{
Expand Down
14 changes: 5 additions & 9 deletions Classes/Event/BuildResponseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

final class BuildResponseEvent extends AbstractEvent implements StoppableEventInterface
{
private SiteInterface $site;
private ServerRequestInterface $request;
private SiteLanguage $selectedLanguage;
private ?ResponseInterface $response = null;

public function __construct(SiteInterface $site, ServerRequestInterface $request, SiteLanguage $selectedLanguage)
{
$this->site = $site;
$this->request = $request;
$this->selectedLanguage = $selectedLanguage;
}
public function __construct(
private SiteInterface $site,
private ServerRequestInterface $request,
private SiteLanguage $selectedLanguage
) {}

public function getSite(): SiteInterface
{
Expand Down
11 changes: 4 additions & 7 deletions Classes/Event/CheckLanguageDetectionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

final class CheckLanguageDetectionEvent extends AbstractEvent implements StoppableEventInterface
{
private SiteInterface $site;
private ServerRequestInterface $request;
private bool $handle = true;

public function __construct(SiteInterface $site, ServerRequestInterface $request)
{
$this->site = $site;
$this->request = $request;
}
public function __construct(
private SiteInterface $site,
private ServerRequestInterface $request
) {}

public function getSite(): SiteInterface
{
Expand Down
10 changes: 4 additions & 6 deletions Classes/Event/DetectUserLanguagesEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

final class DetectUserLanguagesEvent extends AbstractEvent
{
private SiteInterface $site;
private ServerRequestInterface $request;
private LocaleCollection $userLanguages;

public function __construct(SiteInterface $site, ServerRequestInterface $request)
{
$this->site = $site;
$this->request = $request;
public function __construct(
protected SiteInterface $site,
protected ServerRequestInterface $request
) {
$this->userLanguages = new LocaleCollection();
}

Expand Down
14 changes: 5 additions & 9 deletions Classes/Event/NegotiateSiteLanguageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

final class NegotiateSiteLanguageEvent extends AbstractEvent implements StoppableEventInterface
{
private SiteInterface $site;
private ServerRequestInterface $request;
private LocaleCollection $userLanguages;
private ?SiteLanguage $selectedLanguage = null;

public function __construct(SiteInterface $site, ServerRequestInterface $request, LocaleCollection $userLanguages)
{
$this->site = $site;
$this->request = $request;
$this->userLanguages = $userLanguages;
}
public function __construct(
private SiteInterface $site,
private ServerRequestInterface $request,
private LocaleCollection $userLanguages
) {}

public function getSite(): SiteInterface
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

abstract class AbstractHandler
{
protected EventDispatcherInterface $eventDispatcher;

public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function __construct(protected EventDispatcherInterface $eventDispatcher) {}

protected function getSiteFromRequest(ServerRequestInterface $request): SiteInterface
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Middleware/JsonDetectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@

class JsonDetectionMiddleware implements MiddlewareInterface
{
protected JsonDetectionHandler $jsonDetectionHandler;

public function __construct(JsonDetectionHandler $jsonDetectionHandler)
{
$this->jsonDetectionHandler = $jsonDetectionHandler;
}
public function __construct(protected JsonDetectionHandler $jsonDetectionHandler) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Middleware/LanguageDetectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@

class LanguageDetectionMiddleware implements MiddlewareInterface
{
protected LanguageDetectionHandler $languageDetectionHandler;

public function __construct(LanguageDetectionHandler $languageDetectionHandler)
{
$this->languageDetectionHandler = $languageDetectionHandler;
}
public function __construct(protected LanguageDetectionHandler $languageDetectionHandler) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Negotiation/DefaultNegotiation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@

class DefaultNegotiation
{
protected Normalizer $normalizer;

public function __construct(Normalizer $normalizer)
{
$this->normalizer = $normalizer;
}
public function __construct(protected Normalizer $normalizer) {}

public function __invoke(NegotiateSiteLanguageEvent $event): void
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Negotiation/FallbackNegotiation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

class FallbackNegotiation
{
protected SiteConfigurationService $siteConfigurationService;

public function __construct(SiteConfigurationService $siteConfigurationService)
{
$this->siteConfigurationService = $siteConfigurationService;
}
public function __construct(protected SiteConfigurationService $siteConfigurationService) {}

public function __invoke(NegotiateSiteLanguageEvent $event): void
{
Expand Down
7 changes: 1 addition & 6 deletions Classes/Response/DefaultResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

class DefaultResponse
{
protected SiteConfigurationService $siteConfigurationService;

public function __construct(SiteConfigurationService $siteConfigurationService)
{
$this->siteConfigurationService = $siteConfigurationService;
}
public function __construct(protected SiteConfigurationService $siteConfigurationService) {}

public function __invoke(BuildResponseEvent $event): void
{
Expand Down
19 changes: 12 additions & 7 deletions Classes/Service/IpLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

use Psr\Http\Message\RequestFactoryInterface;
use TYPO3\CMS\Core\Http\Client\GuzzleClientFactory;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class IpLocation
{
private RequestFactoryInterface $requestFactory;

public function __construct(RequestFactoryInterface $requestFactory)
{
$this->requestFactory = $requestFactory;
}
public function __construct(private RequestFactoryInterface $requestFactory) {}

public function getCountryCode(string $ip): ?string
{
Expand All @@ -24,7 +21,7 @@ public function getCountryCode(string $ip): ?string
$urlService = 'http://www.geoplugin.net/php.gp?ip=' . $ip;
try {
$request = $this->requestFactory->createRequest('GET', $urlService);
$response = GuzzleClientFactory::getClient()->send($request);
$response = $this->getClient()->send($request);

if ($response->getStatusCode() !== 200) {
throw new IpLocationException('Missing information in response', 123781);
Expand All @@ -40,4 +37,12 @@ public function getCountryCode(string $ip): ?string
return null;
}
}

protected function getClient(): \Psr\Http\Client\ClientInterface
{
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() >= 12) {
return GeneralUtility::makeInstance(GuzzleClientFactory::class)->getClient();
}
return GuzzleClientFactory::getClient();
}
}
6 changes: 2 additions & 4 deletions Classes/Service/TcaLanguageSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

class TcaLanguageSelection
{
protected SiteFinder $siteFinder;

public function __construct(?SiteFinder $siteFinder = null)
public function __construct(protected ?SiteFinder $siteFinder = null)
{
if ($siteFinder === null) {
/** @var SiteFinder $siteFinder */
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$this->siteFinder = $siteFinder;
}
$this->siteFinder = $siteFinder;
}

/**
Expand Down
Loading

0 comments on commit 1c062a1

Please sign in to comment.