Skip to content

Commit

Permalink
Migrate EventSubscriber and Exception namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Dec 30, 2023
1 parent f3efb61 commit ef11dbe
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 72 deletions.
24 changes: 10 additions & 14 deletions src/EventSubscriber/AssetEngineSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), []);
Expand All @@ -51,7 +47,7 @@ public function processConfigurationSettings(ConfigurationParseComplete $event)
}
}

public function processAssetEnginePageView(PageManagerPostProcess $event)
public function processAssetEnginePageView(PageManagerPostProcess $event): void
{
/**
* @var string $folder
Expand Down Expand Up @@ -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();
Expand All @@ -123,7 +119,7 @@ public function compileAssetEnginePageViews(CompilerPostRenderStaticPageView $ev
}
}

public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
ConfigurationParseComplete::NAME => 'processConfigurationSettings',
Expand All @@ -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
Expand Down
13 changes: 3 additions & 10 deletions src/EventSubscriber/RedirectSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -49,10 +45,7 @@ public function registerRedirect(PageViewAdded $event)
}
}

/**
* @inheritDoc
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
PageViewAdded::NAME => 'registerRedirect',
Expand Down
12 changes: 3 additions & 9 deletions src/EventSubscriber/RouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 2 additions & 9 deletions src/Exception/DependencyMissingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 14 additions & 15 deletions src/Exception/FileAwareException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 2 additions & 6 deletions src/Exception/RecursiveConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
11 changes: 2 additions & 9 deletions src/Exception/UnsupportedDataTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ef11dbe

Please sign in to comment.