From ef11dbe2fd83c92d07573edbfaeeefe9978ef41b Mon Sep 17 00:00:00 2001 From: Vladimir Jimenez Date: Fri, 29 Dec 2023 17:09:59 -0800 Subject: [PATCH] Migrate EventSubscriber and Exception namespaces --- src/EventSubscriber/AssetEngineSubscriber.php | 24 +++++++-------- src/EventSubscriber/RedirectSubscriber.php | 13 ++------- src/EventSubscriber/RouteSubscriber.php | 12 ++------ src/Exception/DependencyMissingException.php | 11 ++----- src/Exception/FileAwareException.php | 29 +++++++++---------- .../RecursiveConfigurationException.php | 8 ++--- .../UnsupportedDataTypeException.php | 11 ++----- 7 files changed, 36 insertions(+), 72 deletions(-) diff --git a/src/EventSubscriber/AssetEngineSubscriber.php b/src/EventSubscriber/AssetEngineSubscriber.php index aa2e33c1..2435f8a9 100644 --- a/src/EventSubscriber/AssetEngineSubscriber.php +++ b/src/EventSubscriber/AssetEngineSubscriber.php @@ -26,22 +26,18 @@ class AssetEngineSubscriber implements EventSubscriberInterface { - private $assetEngineManager; - private $assetPageViews; - private $logger; + private array $assetPageViews = []; - public function __construct(AssetEngineManager $assetEngineManager, LoggerInterface $logger) - { - $this->assetEngineManager = $assetEngineManager; - $this->assetPageViews = []; - $this->logger = $logger; + public function __construct( + private readonly AssetEngineManager $assetEngineManager, + private readonly LoggerInterface $logger + ) { } - public function processConfigurationSettings(ConfigurationParseComplete $event) + public function processConfigurationSettings(ConfigurationParseComplete $event): void { $configuration = $event->getConfiguration()->getConfiguration(); - /** @var AssetEngineInterface $engine */ foreach ($this->assetEngineManager->getEngines() as $engine) { $defaults = __::get($configuration, $engine->getConfigurationNamespace(), []); @@ -51,7 +47,7 @@ public function processConfigurationSettings(ConfigurationParseComplete $event) } } - public function processAssetEnginePageView(PageManagerPostProcess $event) + public function processAssetEnginePageView(PageManagerPostProcess $event): void { /** * @var string $folder @@ -98,7 +94,7 @@ public function processAssetEnginePageView(PageManagerPostProcess $event) } } - public function compileAssetEnginePageViews(CompilerPostRenderStaticPageView $event) + public function compileAssetEnginePageViews(CompilerPostRenderStaticPageView $event): void { $pageView = $event->getPageView(); $filePath = $pageView->getRelativeFilePath(); @@ -123,7 +119,7 @@ public function compileAssetEnginePageViews(CompilerPostRenderStaticPageView $ev } } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ConfigurationParseComplete::NAME => 'processConfigurationSettings', @@ -132,7 +128,7 @@ public static function getSubscribedEvents() ]; } - private function buildCacheFolder(AssetEngineInterface $engine) + private function buildCacheFolder(AssetEngineInterface $engine): WritableFolder { $cacheDirPath = new FilesystemPath(Service::getWorkingDirectory() . '/'); $cacheDirPath diff --git a/src/EventSubscriber/RedirectSubscriber.php b/src/EventSubscriber/RedirectSubscriber.php index 12e27d40..bbee40cb 100644 --- a/src/EventSubscriber/RedirectSubscriber.php +++ b/src/EventSubscriber/RedirectSubscriber.php @@ -11,15 +11,11 @@ class RedirectSubscriber implements EventSubscriberInterface { - /** @var RedirectMapper */ - private $redirectMapper; - - public function __construct(RedirectMapper $redirectMapper) + public function __construct(private readonly RedirectMapper $redirectMapper) { - $this->redirectMapper = $redirectMapper; } - public function registerRedirect(PageViewAdded $event) + public function registerRedirect(PageViewAdded $event): void { $pageView = $event->getPageView(); @@ -49,10 +45,7 @@ public function registerRedirect(PageViewAdded $event) } } - /** - * @inheritDoc - */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ PageViewAdded::NAME => 'registerRedirect', diff --git a/src/EventSubscriber/RouteSubscriber.php b/src/EventSubscriber/RouteSubscriber.php index 4c8aff0a..7552f83e 100644 --- a/src/EventSubscriber/RouteSubscriber.php +++ b/src/EventSubscriber/RouteSubscriber.php @@ -13,22 +13,16 @@ class RouteSubscriber implements EventSubscriberInterface { - private $routerMapping; - - public function __construct(RouteMapper $routerMapping) + public function __construct(private readonly RouteMapper $routerMapping) { - $this->routerMapping = $routerMapping; } - public function registerPageView(PageViewAdded $event) + public function registerPageView(PageViewAdded $event): void { $this->routerMapping->registerPageView($event->getPageView()); } - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ PageViewAdded::NAME => 'registerPageView', diff --git a/src/Exception/DependencyMissingException.php b/src/Exception/DependencyMissingException.php index ff4cb0e3..9f0cb86d 100644 --- a/src/Exception/DependencyMissingException.php +++ b/src/Exception/DependencyMissingException.php @@ -11,19 +11,12 @@ class DependencyMissingException extends \RuntimeException { - private $dependency; - - public function __construct($dependency, $message = '', $code = 0, Throwable $previous = null) + public function __construct(private readonly string $dependency, string $message = '', int $code = 0, Throwable $previous = null) { - $this->dependency = $dependency; - parent::__construct($message, $code, $previous); } - /** - * @return string - */ - public function getDependency() + public function getDependency(): string { return $this->dependency; } diff --git a/src/Exception/FileAwareException.php b/src/Exception/FileAwareException.php index 470c47c4..180b5ed3 100644 --- a/src/Exception/FileAwareException.php +++ b/src/Exception/FileAwareException.php @@ -7,44 +7,43 @@ namespace allejo\stakx\Exception; +use Twig\Error\SyntaxError; + /** * Exception thrown when an error is found in a file. */ class FileAwareException extends \RuntimeException { - private $lineNumber; - private $filePath; - - public function __construct($message = '', $code = 0, \Exception $previous = null, $path = '', $line = -1) - { + public function __construct( + string $message = '', + int $code = 0, + \Exception $previous = null, + private readonly string $filePath = '', + private readonly int $lineNumber = -1 + ) { parent::__construct($message, $code, $previous); - - $this->filePath = $path; - $this->lineNumber = $line; } - public function getLineNumber() + public function getLineNumber(): int { return $this->lineNumber; } - public function getPath() + public function getPath(): string { return $this->filePath; } - public static function castException(\Exception $e, $filePath) + public static function castException(\Exception $e, $filePath): FileAwareException { - $lineNumber = ($e instanceof \Twig_Error_Syntax) ? $e->getTemplateLine() : -1; + $lineNumber = ($e instanceof SyntaxError) ? $e->getTemplateLine() : -1; - $exception = new self( + return new self( $e->getMessage(), $e->getCode(), $e, $filePath, $lineNumber ); - - return $exception; } } diff --git a/src/Exception/RecursiveConfigurationException.php b/src/Exception/RecursiveConfigurationException.php index b765f8de..fa8dfe45 100644 --- a/src/Exception/RecursiveConfigurationException.php +++ b/src/Exception/RecursiveConfigurationException.php @@ -12,16 +12,12 @@ class RecursiveConfigurationException extends \RuntimeException { - private $import; - - public function __construct(File $import, $message = '', $code = 0, Exception $previous = null) + public function __construct(private readonly File $import, string $message = '', int $code = 0, Exception $previous = null) { - $this->import = $import; - parent::__construct($message, $code, $previous); } - public function getRecursiveImport() + public function getRecursiveImport(): string { return $this->import->getRelativeFilePath(); } diff --git a/src/Exception/UnsupportedDataTypeException.php b/src/Exception/UnsupportedDataTypeException.php index 7d2aaf81..4f436f5b 100644 --- a/src/Exception/UnsupportedDataTypeException.php +++ b/src/Exception/UnsupportedDataTypeException.php @@ -11,19 +11,12 @@ class UnsupportedDataTypeException extends \RuntimeException { - private $dataType; - - public function __construct($dataType, $message = '', $code = 0, Throwable $previous = null) + public function __construct(private readonly string $dataType, string $message = '', int $code = 0, Throwable $previous = null) { - $this->dataType = $dataType; - parent::__construct($message, $code, $previous); } - /** - * @return string - */ - public function getDataType() + public function getDataType(): string { return $this->dataType; }