Skip to content

Commit

Permalink
Update to Up to php 8.3 syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Oct 8, 2024
1 parent c9a555b commit 67f0d3f
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 129 deletions.
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// phpcs:disable
class_exists(\Mezzio\Swoole\ConfigProvider::class)
? \Mezzio\Swoole\ConfigProvider::class
: function() { return []; },
: fn() => [],
// phpcs:enable

// Default App module config
Expand Down
9 changes: 5 additions & 4 deletions src/App/Console/WriteRepositoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Console;

use App\Handler\MaintenanceOverviewHandler;
use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -54,6 +55,7 @@ public function __construct()
parent::__construct();
}

#[Override]
protected function configure(): void
{
$this->setName('app:generate-repository-data');
Expand All @@ -65,6 +67,7 @@ protected function configure(): void
$this->addArgument(self::ARGUMENT_TOKEN, InputArgument::OPTIONAL, 'GitHub token.');
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$userAgent = $input->getArgument(self::ARGUMENT_USER_AGENT);
Expand All @@ -75,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$token = $input->getArgument(self::ARGUMENT_TOKEN);
if (! $token) {
$variables = json_decode(base64_decode($_ENV['PLATFORM_VARIABLES']), true);
$variables = json_decode(base64_decode((string) $_ENV['PLATFORM_VARIABLES']), true);

Check failure on line 81 in src/App/Console/WriteRepositoryData.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.3, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

RedundantCast

src/App/Console/WriteRepositoryData.php:81:52: RedundantCast: Redundant cast to string (see https://psalm.dev/262)
assert(is_array($variables));
assert(isset($variables['REPO_TOKEN']));

Expand Down Expand Up @@ -169,9 +172,7 @@ private function generateDataFile(string $userAgent, string $token): void
curl_close($curl);

foreach ($singleResult as $key => $value) {
usort($singleResult[$key], function (array $a, array $b) {
return $a['name'] <=> $b['name'];
});
usort($singleResult[$key], fn(array $a, array $b) => $a['name'] <=> $b['name']);
}

$singleResult['last_updated'] = date('Y-m-d H:i:s');
Expand Down
10 changes: 7 additions & 3 deletions src/App/ContentParser/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@
namespace App\ContentParser;

use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
use Override;

final class Document implements DocumentInterface
final readonly class Document implements DocumentInterface
{
public function __construct(
private readonly RenderedContentWithFrontMatter $renderedContent,
private readonly ?string $tableOfContents
private RenderedContentWithFrontMatter $renderedContent,
private ?string $tableOfContents
) {
}

#[Override]
public function getFrontMatter(): array
{
return (array) $this->renderedContent->getFrontMatter();
}

#[Override]
public function getTableOfContents(): ?string
{
return $this->tableOfContents;
}

#[Override]
public function getContent(): string
{
return $this->renderedContent->getContent();
Expand Down
10 changes: 6 additions & 4 deletions src/App/ContentParser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
use League\CommonMark\Node\Query;
use League\CommonMark\Parser\MarkdownParser;
use League\CommonMark\Renderer\HtmlRenderer;
use Override;

use function file_get_contents;

final class Parser implements ParserInterface
final readonly class Parser implements ParserInterface
{
private readonly MarkdownConverter $converter;
private MarkdownConverter $converter;

private readonly MarkdownParser $parser;
private MarkdownParser $parser;

private readonly HtmlRenderer $renderer;
private HtmlRenderer $renderer;

public function __construct()
{
Expand Down Expand Up @@ -74,6 +75,7 @@ public function __construct()
$this->renderer = new HtmlRenderer($environment);
}

#[Override]
public function parse(string $file): DocumentInterface
{
$markdown = file_get_contents($file);
Expand Down
9 changes: 3 additions & 6 deletions src/App/Handler/CommercialVendorsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@

use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class CommercialVendorsHandler implements RequestHandlerInterface
{
private array $vendors;
private TemplateRendererInterface $renderer;

public function __construct(array $vendors, TemplateRendererInterface $renderer)
public function __construct(private readonly array $vendors, private readonly TemplateRendererInterface $renderer)
{
$this->vendors = $vendors;
$this->renderer = $renderer;
}

#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new HtmlResponse($this->renderer->render(
Expand Down
10 changes: 6 additions & 4 deletions src/App/Handler/HomePageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class HomePageHandler implements RequestHandlerInterface
{
public function __construct(
private array $vendors,
private array $sponsors,
private array $projects,
private TemplateRendererInterface $renderer
private readonly array $vendors,
private readonly array $sponsors,
private readonly array $projects,
private readonly TemplateRendererInterface $renderer
) {
}

#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new HtmlResponse($this->renderer->render(
Expand Down
8 changes: 5 additions & 3 deletions src/App/Handler/MaintenanceOverviewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand Down Expand Up @@ -39,12 +40,13 @@ class MaintenanceOverviewHandler implements RequestHandlerInterface
];

public function __construct(
private array $repositoryData,
private string $lastUpdated,
private TemplateRendererInterface $renderer
private readonly array $repositoryData,
private readonly string $lastUpdated,
private readonly TemplateRendererInterface $renderer
) {
}

#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new HtmlResponse($this->renderer->render(
Expand Down
4 changes: 3 additions & 1 deletion src/App/Handler/MaintenanceStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Handler;

use Laminas\Diactoros\Response\JsonResponse;
use Override;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand All @@ -13,10 +14,11 @@

class MaintenanceStatusHandler implements RequestHandlerInterface
{
public function __construct(private array $repositoryData)
public function __construct(private readonly array $repositoryData)
{
}

#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
return new JsonResponse(
Expand Down
8 changes: 3 additions & 5 deletions src/App/Handler/StaticPageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Router\RouteResult;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand All @@ -15,14 +16,11 @@

class StaticPageHandler implements RequestHandlerInterface
{
/** @var TemplateRendererInterface */
private $renderer;

public function __construct(TemplateRendererInterface $renderer)
public function __construct(private readonly TemplateRendererInterface $renderer)
{
$this->renderer = $renderer;
}

#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
/** @var RouteResult $routeResult */
Expand Down
4 changes: 2 additions & 2 deletions src/App/LoggingErrorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class LoggingErrorListener
/**
* Log message string with placeholders
*/
private const LOG_STRING = '{status} [{method}] {uri}: {error}';
private const string LOG_STRING = '{status} [{method}] {uri}: {error}';

public function __construct(private LoggerInterface $logger)
public function __construct(private readonly LoggerInterface $logger)
{
}

Expand Down
4 changes: 1 addition & 3 deletions src/App/Template/InjectAssetRevisionsDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal

isset($config['debug'])
? $this->injectAssets($engine, Closure::fromCallable([$this, 'getAssetMap']))
: $this->injectAssets($engine, function () use ($revisions): array {
return $revisions;
});
: $this->injectAssets($engine, fn(): array => $revisions);

return $engine;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Blog/Console/FeedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mezzio\Helper\ServerUrlHelper;
use Mezzio\Router\RouterInterface;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function __construct(
parent::__construct();
}

#[Override]
protected function configure(): void
{
$this->setName('blog:feed-generator');
Expand All @@ -75,6 +77,7 @@ protected function configure(): void
);
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
Expand Down
3 changes: 3 additions & 0 deletions src/Blog/Console/GenerateSearchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace GetLaminas\Blog\Console;

use GetLaminas\Blog\CreateBlogPostFromDataArray;
use Override;
use SplFileInfo;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -27,6 +28,7 @@ class GenerateSearchData extends Command
{
use CreateBlogPostFromDataArray;

#[Override]
protected function configure(): void
{
$this->setName('blog:generate-search-data');
Expand All @@ -43,6 +45,7 @@ protected function configure(): void
);
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
Expand Down
2 changes: 2 additions & 0 deletions src/Blog/Console/MarkdownFileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use FilterIterator;
use InvalidArgumentException;
use Override;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function __construct(string $dir = '.')
$this->rewind();
}

#[Override]
public function accept(): bool
{
$current = $this->getInnerIterator()->current();
Expand Down
5 changes: 4 additions & 1 deletion src/Blog/Console/SeedBlogDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTimeImmutable;
use GetLaminas\Blog\CreateBlogPostFromDataArray;
use Override;
use PDO;
use SplFileInfo;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -106,6 +107,7 @@ class SeedBlogDatabase extends Command
tags VARCHAR(255)
)';

#[Override]
protected function configure(): void
{
$this->setName('blog:seed-db');
Expand Down Expand Up @@ -145,6 +147,7 @@ protected function configure(): void
);
}

#[Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
Expand All @@ -157,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$pdo = $this->createDatabase($dbPath);

$path = sprintf('%s/%s', realpath($basePath), ltrim($postsPath));
$path = sprintf('%s/%s', realpath($basePath), ltrim((string) $postsPath));
$trim = strlen(realpath($basePath)) + 1;

$statements = [];
Expand Down
9 changes: 4 additions & 5 deletions src/Blog/FetchBlogPostEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
namespace GetLaminas\Blog;

use JsonSerializable;
use Override;
use Psr\EventDispatcher\StoppableEventInterface;

class FetchBlogPostEvent implements
JsonSerializable,
StoppableEventInterface
{
/** @var string */
private $id;

/** @var null|BlogPost */
private $post;

public function __construct(string $id)
public function __construct(private readonly string $id)
{
$this->id = $id;
}

#[Override]
public function jsonSerialize(): array
{
return [
Expand All @@ -30,6 +28,7 @@ public function jsonSerialize(): array
];
}

#[Override]
public function isPropagationStopped(): bool
{
return null !== $this->post;
Expand Down
Loading

0 comments on commit 67f0d3f

Please sign in to comment.