Skip to content

Commit

Permalink
Code cleanups for mondern PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Mar 20, 2024
1 parent d823320 commit a63dc72
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 236 deletions.
10 changes: 1 addition & 9 deletions Classes/Cache/Listener/ForceStaticCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
*/
class ForceStaticCacheListener
{
protected EventDispatcherInterface $eventDispatcher;

/**
* PrepareMiddleware constructor.
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function __construct(readonly protected EventDispatcherInterface $eventDispatcher) {}

public function __invoke(CacheRuleEvent $event): void
{
Expand Down
9 changes: 0 additions & 9 deletions Classes/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@

use Symfony\Component\Console\Command\Command;

/**
* AbstractCommand.
*/
abstract class AbstractCommand extends Command
{
/**
* Set generic prefix for the description.
*
*
* @return $this
*/
public function setDescription(string $description): static
{
return parent::setDescription('StaticFileCache task: ' . $description);
Expand Down
42 changes: 3 additions & 39 deletions Classes/Command/BoostQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,22 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* BoostQueueRunCommand.
*/
class BoostQueueCommand extends AbstractCommand
{
/**
* @var QueueRepository
*/
protected $queueRepository;

/**
* @var QueueService
*/
protected $queueService;

public function __construct(QueueRepository $queueRepository, QueueService $queueService)
public function __construct(protected QueueRepository $queueRepository, protected QueueService $queueService)
{
$this->queueRepository = $queueRepository;
$this->queueService = $queueService;
parent::__construct();
}

/**
* Configures the current command.
*/
protected function configure(): void
{
parent::configure();
// @todo When compatibility is set to TYPO3 v11+ only, the description can be removed as it is defined in Services.yaml
$this->setDescription('Run (work on) the cache boost queue. Call this task every 5 minutes.')
->addOption('limit-items', null, InputOption::VALUE_REQUIRED, 'Limit the items that are crawled. 0 => all', 500)
$this->addOption('limit-items', null, InputOption::VALUE_REQUIRED, 'Limit the items that are crawled. 0 => all', 500)
->addOption('stop-processing-after', null, InputOption::VALUE_REQUIRED, 'Stop crawling new items after N seconds since scheduler task started. 0 => infinite', 240)
->addOption('avoid-cleanup', null, InputOption::VALUE_NONE, 'Avoid the cleanup of the queue items')
;
}

/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @throws NoSuchCacheException
*
* @return int null or 0 if everything went fine, or an error code
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
Expand Down Expand Up @@ -94,9 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

/**
* Cleanup queue.
*/

protected function cleanupQueue(SymfonyStyle $io): void
{
$uids = $this->queueRepository->findOldUids();
Expand Down
25 changes: 1 addition & 24 deletions Classes/Command/FlushCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,15 @@
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* FlushCacheCommand.
*/
class FlushCacheCommand extends AbstractCommand
{
/**
* Configures the current command.
*/
protected function configure(): void
{
parent::configure();
// @todo When compatibility is set to TYPO3 v11+ only, the description can be removed as it is defined in Services.yaml
$this->setDescription('Flush the cache. If the boost mode is active, all pages are added to the queue (you have to run the BoostQueueRun Command to recrawl the pages). If you use the force-boost-mode-flush argument, you directly drop the cache even the page is in Boostmode.')
->addOption('force-boost-mode-flush', null, InputOption::VALUE_NONE, 'Force a boost mode flush')
$this->addOption('force-boost-mode-flush', null, InputOption::VALUE_NONE, 'Force a boost mode flush')
;
}

/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @throws NoSuchCacheException
* @throws NoSuchCacheGroupException
*
* @return int null or 0 if everything went fine, or an error code
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$cacheService = GeneralUtility::makeInstance(CacheService::class);
Expand Down
3 changes: 0 additions & 3 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

/**
* Configuration.
*/
class Configuration extends StaticFileCacheObject
{
public const EXTENSION_KEY = 'staticfilecache';
Expand Down
15 changes: 1 addition & 14 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,9 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/**
* StaticFileCache backend module.
*/
class BackendController extends ActionController
{
protected QueueService $queueService;
protected ModuleTemplateFactory $moduleTemplateFactory;

/**
* BackendController constructor.
*/
public function __construct(QueueService $queueService, ModuleTemplateFactory $moduleTemplateFactory)
{
$this->queueService = $queueService;
$this->moduleTemplateFactory = $moduleTemplateFactory;
}
public function __construct(protected QueueService $queueService, protected ModuleTemplateFactory $moduleTemplateFactory) {}

public function listAction(string $filter = ''): ResponseInterface
{
Expand Down
10 changes: 1 addition & 9 deletions Classes/Event/BuildClientEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@

final class BuildClientEvent
{
private array $options;

private array $httpOptions;

public function __construct(array $options, array $httpOptions)
{
$this->options = $options;
$this->httpOptions = $httpOptions;
}
public function __construct(private array $options, private array $httpOptions) {}

public function getOptions(): array
{
Expand Down
17 changes: 5 additions & 12 deletions Classes/Event/CacheRuleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@

final class CacheRuleEvent implements CacheRuleEventInterface
{
private ServerRequestInterface $request;

private array $explanation;

private bool $skipProcessing;

public function __construct(ServerRequestInterface $request, array $explanation, bool $skipProcessing)
{
$this->request = $request;
$this->explanation = $explanation;
$this->skipProcessing = $skipProcessing;
}
public function __construct(
private ServerRequestInterface $request,
private array $explanation,
private bool $skipProcessing
) {}

public function getRequest(): ServerRequestInterface
{
Expand Down
13 changes: 1 addition & 12 deletions Classes/Event/CacheRuleFallbackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@

final class CacheRuleFallbackEvent implements CacheRuleEventInterface
{
private ServerRequestInterface $request;

private array $explanation;

private bool $skipProcessing;

public function __construct(ServerRequestInterface $request, array $explanation, bool $skipProcessing)
{
$this->request = $request;
$this->explanation = $explanation;
$this->skipProcessing = $skipProcessing;
}
public function __construct(private ServerRequestInterface $request, private array $explanation, private bool $skipProcessing) {}

public function getRequest(): ServerRequestInterface
{
Expand Down
16 changes: 1 addition & 15 deletions Classes/Event/ForceStaticFileCacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,7 @@

final class ForceStaticFileCacheEvent
{
private bool $forceStatic;

private ?TypoScriptFrontendController $frontendController;

private ServerRequestInterface $request;

/**
* ForceStaticFileCacheEvent constructor.
*/
public function __construct(bool $forceStatic, ?TypoScriptFrontendController $frontendController, ServerRequestInterface $request)
{
$this->forceStatic = $forceStatic;
$this->frontendController = $frontendController;
$this->request = $request;
}
public function __construct(private bool $forceStatic, private ?TypoScriptFrontendController $frontendController, private ServerRequestInterface $request) {}

public function isForceStatic(): bool
{
Expand Down
13 changes: 1 addition & 12 deletions Classes/Event/PreGenerateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@

final class PreGenerateEvent
{
private string $uri;

private ServerRequestInterface $request;

private ResponseInterface $response;

public function __construct(string $uri, ServerRequestInterface $request, ResponseInterface $response)
{
$this->uri = $uri;
$this->request = $request;
$this->response = $response;
}
public function __construct(private string $uri, private ServerRequestInterface $request, private ResponseInterface $response) {}

public function getUri(): string
{
Expand Down
14 changes: 1 addition & 13 deletions Classes/Middleware/CookieCheckMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,7 @@
*/
class CookieCheckMiddleware implements MiddlewareInterface
{
protected Context $context;
protected CookieService $cookieService;
protected EventDispatcherInterface $eventDispatcher;

/**
* CookieCheckMiddleware constructor.
*/
public function __construct(Context $context, CookieService $cookieService, EventDispatcherInterface $eventDispatcher)
{
$this->context = $context;
$this->cookieService = $cookieService;
$this->eventDispatcher = $eventDispatcher;
}
public function __construct(protected Context $context, protected CookieService $cookieService, protected EventDispatcherInterface $eventDispatcher) {}

/**
* Check for the sfc cookie and remove it when there is no valid user session.
Expand Down
13 changes: 1 addition & 12 deletions Classes/Middleware/FallbackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,8 @@
*/
class FallbackMiddleware implements MiddlewareInterface
{
protected EventDispatcherInterface$eventDispatcher;
public function __construct(protected EventDispatcherInterface $eventDispatcher, protected ConfigurationService $configurationService) {}

protected ConfigurationService $configurationService;

public function __construct(EventDispatcherInterface $eventDispatcher, ConfigurationService $configurationService)
{
$this->eventDispatcher = $eventDispatcher;
$this->configurationService = $configurationService;
}

/**
* Process the fallback middleware.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
Expand Down
15 changes: 1 addition & 14 deletions Classes/Middleware/GenerateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,12 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* GenerateMiddleware.
*/
class GenerateMiddleware implements MiddlewareInterface
{
protected ?UriFrontend $cache = null;

protected EventDispatcherInterface $eventDispatcher;

protected CookieService $cookieService;

/**
* GenerateMiddleware constructor.
*/
public function __construct(EventDispatcherInterface $eventDispatcher, CookieService $cookieService)
{
$this->eventDispatcher = $eventDispatcher;
$this->cookieService = $cookieService;
}
public function __construct(protected EventDispatcherInterface $eventDispatcher, protected CookieService $cookieService) {}

/**
* Process an incoming server request.
Expand Down
10 changes: 1 addition & 9 deletions Classes/Middleware/PrepareMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
*/
class PrepareMiddleware implements MiddlewareInterface
{
protected EventDispatcherInterface $eventDispatcher;

/**
* PrepareMiddleware constructor.
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function __construct(protected EventDispatcherInterface $eventDispatcher) {}

/**
* Process an incoming server request.
Expand Down
10 changes: 1 addition & 9 deletions Classes/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
*/
class ClientService extends AbstractService
{
protected EventDispatcherInterface $eventDispatcher;

/**
* PrepareMiddleware constructor.
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function __construct(protected EventDispatcherInterface $eventDispatcher) {}

/**
* Run a single request with guzzle and return status code.
Expand Down
Loading

0 comments on commit a63dc72

Please sign in to comment.