Skip to content

Commit

Permalink
Modernize syntax and internal improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Mar 6, 2021
1 parent f27a379 commit 826fb21
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
12 changes: 3 additions & 9 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

final class Api
{
private string $basePath;

/** @var mixed[] */
private array $data;

Expand All @@ -22,26 +20,22 @@ final class Api
/** @var string[] */
private array $formatHtmlInjects;

private Minifier $minifier;


/**
* @param mixed[] $data
* @param string[] $formatHeaders
* @param string[] $formatHtmlInjects
*/
public function __construct(
string $basePath,
private string $basePath,
array $data,
array $formatHeaders,
array $formatHtmlInjects,
Minifier $minifier
private Minifier $minifier
) {
$this->basePath = $basePath;
$this->data = $data;
$this->formatHeaders = $formatHeaders;
$this->formatHtmlInjects = $formatHtmlInjects;
$this->minifier = $minifier;
}


Expand Down Expand Up @@ -205,7 +199,7 @@ private function findGlobalData(string $route): array
*/
private function findDataBySelectors(array $selectors): array
{
$selectors = array_map(fn(string $item): string => trim($item, ':'), $selectors);
$selectors = array_map(static fn(string $item): string => trim($item, ':'), $selectors);
$return = [];
foreach (array_unique($selectors) as $selector) {
$return[] = $this->data[$selector] ?? [];
Expand Down
8 changes: 0 additions & 8 deletions src/AssetLoaderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,4 @@

final class AssetLoaderException extends \RuntimeException
{
public static function routeIsInInvalidFormat(string $route): void
{
throw new self(
'Route "' . $route . '" is invalid. '
. 'Route must be absolute "Module:Presenter:action" or end '
. 'with dynamic part in format "Module:*" or "Module:Presenter:*".',
);
}
}
6 changes: 5 additions & 1 deletion src/LoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ private function validateRouteFormat(string $route): void
return;
}
if (preg_match('/^[A-Z0-9][A-Za-z0-9]*:(?:\*|[A-Z0-9][A-Za-z0-9]*:(?:\*|[a-z0-9][A-Za-z0-9]*))$/', trim($route, ':')) === 0) {
AssetLoaderException::routeIsInInvalidFormat($route);
throw new AssetLoaderException(
'Route "' . $route . '" is invalid. '
. 'Route must be absolute "Module:Presenter:action" or end '
. 'with dynamic part in format "Module:*" or "Module:Presenter:*".',
);
}
}
}
2 changes: 1 addition & 1 deletion src/Minifier/DefaultCssMinifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function minify(string $haystack): string
{
$return = (string) preg_replace_callback(
'#[ \t\r\n]+|<(/)?(textarea|pre)(?=\W)#i',
fn(array $match): string => empty($match[2]) ? ' ' : $match[0],
static fn(array $match): string => empty($match[2]) ? ' ' : $match[0],
$haystack,
);
$return = (string) preg_replace('/(\w|;)\s+({|})\s+(\w|\.|#)/', '$1$2$3', $return);
Expand Down

0 comments on commit 826fb21

Please sign in to comment.