From 0bd4b405232df5454450fadd1fd681512f2f727e Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 26 Sep 2023 22:45:03 +0200 Subject: [PATCH] Use final and readonly where possible --- lib/Application.php | 2 +- lib/Assets/AssetIntegrityGenerator.php | 7 +++- lib/Cache/CacheClearer.php | 2 +- lib/Commands/BuildAllCommand.php | 6 +-- lib/Commands/BuildDocsCommand.php | 7 ++-- lib/Commands/BuildWebsiteCommand.php | 8 ++-- lib/Commands/BuildWebsiteDataCommand.php | 12 +++--- lib/Commands/ClearBuildCacheCommand.php | 9 ++-- lib/Commands/SyncRepositoriesCommand.php | 6 +-- lib/Controllers/AtomController.php | 7 ++-- lib/Controllers/BlogController.php | 7 ++-- lib/Controllers/ConsultingController.php | 7 ++-- lib/Controllers/DocumentationController.php | 7 ++-- lib/Controllers/HomepageController.php | 2 +- lib/Controllers/PartnersController.php | 7 ++-- lib/Controllers/ProjectController.php | 2 +- lib/Controllers/SitemapController.php | 7 ++-- lib/Controllers/SponsorshipController.php | 7 ++-- lib/Controllers/TeamController.php | 7 ++-- lib/DataBuilder/BlogPostDataBuilder.php | 7 ++-- lib/DataBuilder/ContributorDataBuilder.php | 7 ++-- .../ProjectContributorDataBuilder.php | 2 +- lib/DataBuilder/ProjectDataBuilder.php | 2 +- lib/DataBuilder/WebsiteData.php | 8 ++-- lib/DataBuilder/WebsiteDataReader.php | 6 ++- lib/DataBuilder/WebsiteDataWriter.php | 7 ++-- lib/DataSources/ArrayDataSource.php | 7 ++-- lib/DataSources/BlogPosts.php | 7 ++-- lib/DataSources/Contributors.php | 2 +- lib/DataSources/ProjectContributors.php | 2 +- lib/DataSources/Projects.php | 7 ++-- lib/DataSources/SitemapPages.php | 7 ++-- lib/Docs/BuildDocs.php | 2 +- lib/Docs/CodeBlockConsoleRenderer.php | 1 + lib/Docs/CodeBlockLanguageDetector.php | 7 ++-- lib/Docs/CodeBlockRenderer.php | 2 +- lib/Docs/CodeBlockWithLineNumbersRenderer.php | 36 ++++++++-------- lib/Docs/RST/RSTBuilder.php | 13 +++--- lib/Docs/RST/RSTCopier.php | 41 ++++++++++--------- lib/Docs/RST/RSTFileRepository.php | 1 + lib/Docs/RST/RSTLanguage.php | 8 ++-- lib/Docs/RST/RSTLanguagesDetector.php | 3 +- lib/Docs/RST/RSTPostBuildProcessor.php | 23 ++++++----- lib/Docs/SearchIndexer.php | 9 ++-- lib/EventListener/NodeValue.php | 2 +- lib/EventListener/TableIncompatibility.php | 2 +- lib/Git/Tag.php | 8 ++-- lib/Git/TagBranchGuesser.php | 6 ++- lib/Git/TagReader.php | 6 ++- lib/Github/GithubClientProvider.php | 7 +++- lib/Github/ProdGithubProjectContributors.php | 2 +- lib/Hydrators/ModelHydrator.php | 7 ++-- lib/ProcessFactory.php | 1 + lib/Projects/GetProjectPackagistData.php | 6 ++- lib/Projects/GetTotalDownloads.php | 7 ++-- lib/Projects/ProjectDataReader.php | 9 ++-- lib/Projects/ProjectDataRepository.php | 6 ++- lib/Projects/ProjectGitSyncer.php | 10 +++-- lib/Projects/ProjectVersionsReader.php | 7 +++- lib/Requests/ContributorRequests.php | 7 ++-- lib/Requests/PartnerRequests.php | 7 ++-- lib/Requests/ProjectRequests.php | 7 ++-- lib/Requests/ProjectVersionRequests.php | 7 ++-- lib/Site.php | 2 +- lib/Twig/MainExtension.php | 10 ++--- lib/Twig/ProjectExtension.php | 8 ++-- lib/WebsiteBuilder.php | 17 ++++---- 67 files changed, 279 insertions(+), 208 deletions(-) diff --git a/lib/Application.php b/lib/Application.php index 91295b7e..fac3bfb7 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -28,7 +28,7 @@ use function realpath; use function sprintf; -class Application +final readonly class Application { public const ENV_PROD = 'prod'; public const ENV_STAGING = 'staging'; diff --git a/lib/Assets/AssetIntegrityGenerator.php b/lib/Assets/AssetIntegrityGenerator.php index 96dd952e..0d08f319 100644 --- a/lib/Assets/AssetIntegrityGenerator.php +++ b/lib/Assets/AssetIntegrityGenerator.php @@ -10,13 +10,16 @@ use function hash; use function realpath; +/** @final */ class AssetIntegrityGenerator { /** @var string[] */ private array $cache = []; - public function __construct(private string $sourceDir, private string $webpackBuildDir) - { + public function __construct( + private readonly string $sourceDir, + private readonly string $webpackBuildDir, + ) { } public function getAssetIntegrity(string $path, string|null $rootPath = null): string diff --git a/lib/Cache/CacheClearer.php b/lib/Cache/CacheClearer.php index 9b43f2c8..37465b8a 100644 --- a/lib/Cache/CacheClearer.php +++ b/lib/Cache/CacheClearer.php @@ -10,7 +10,7 @@ use function glob; use function sprintf; -class CacheClearer +final readonly class CacheClearer { public function __construct( private Filesystem $filesystem, diff --git a/lib/Commands/BuildAllCommand.php b/lib/Commands/BuildAllCommand.php index add4d10f..034332c8 100644 --- a/lib/Commands/BuildAllCommand.php +++ b/lib/Commands/BuildAllCommand.php @@ -20,11 +20,11 @@ use function is_string; use function sprintf; -class BuildAllCommand extends Command +final class BuildAllCommand extends Command { public function __construct( - private string $rootDir, - private string $env, + private readonly string $rootDir, + private readonly string $env, ) { parent::__construct(); } diff --git a/lib/Commands/BuildDocsCommand.php b/lib/Commands/BuildDocsCommand.php index a0b140fd..0b262f2d 100644 --- a/lib/Commands/BuildDocsCommand.php +++ b/lib/Commands/BuildDocsCommand.php @@ -14,10 +14,11 @@ use function is_bool; use function is_string; -class BuildDocsCommand extends Command +final class BuildDocsCommand extends Command { - public function __construct(private BuildDocs $buildDocs) - { + public function __construct( + private readonly BuildDocs $buildDocs, + ) { parent::__construct(); } diff --git a/lib/Commands/BuildWebsiteCommand.php b/lib/Commands/BuildWebsiteCommand.php index a5428ff6..66e0fb6c 100644 --- a/lib/Commands/BuildWebsiteCommand.php +++ b/lib/Commands/BuildWebsiteCommand.php @@ -26,7 +26,7 @@ use function sprintf; use function time; -class BuildWebsiteCommand extends Command +final class BuildWebsiteCommand extends Command { private const WATCH_DIRS = [ 'config', @@ -37,9 +37,9 @@ class BuildWebsiteCommand extends Command ]; public function __construct( - private WebsiteBuilder $websiteBuilder, - private string $rootDir, - private string $env, + private readonly WebsiteBuilder $websiteBuilder, + private readonly string $rootDir, + private readonly string $env, ) { parent::__construct(); } diff --git a/lib/Commands/BuildWebsiteDataCommand.php b/lib/Commands/BuildWebsiteDataCommand.php index 273d3d11..49c602d0 100644 --- a/lib/Commands/BuildWebsiteDataCommand.php +++ b/lib/Commands/BuildWebsiteDataCommand.php @@ -15,14 +15,14 @@ use function sprintf; -class BuildWebsiteDataCommand extends Command +final class BuildWebsiteDataCommand extends Command { public function __construct( - private ProjectDataBuilder $projectDataBuilder, - private ProjectContributorDataBuilder $projectContributorDataBuilder, - private ContributorDataBuilder $contributorDataBuilder, - private BlogPostDataBuilder $blogPostDataBuilder, - private WebsiteDataWriter $dataWriter, + private readonly ProjectDataBuilder $projectDataBuilder, + private readonly ProjectContributorDataBuilder $projectContributorDataBuilder, + private readonly ContributorDataBuilder $contributorDataBuilder, + private readonly BlogPostDataBuilder $blogPostDataBuilder, + private readonly WebsiteDataWriter $dataWriter, ) { parent::__construct(); } diff --git a/lib/Commands/ClearBuildCacheCommand.php b/lib/Commands/ClearBuildCacheCommand.php index 62485dd4..c0b36483 100644 --- a/lib/Commands/ClearBuildCacheCommand.php +++ b/lib/Commands/ClearBuildCacheCommand.php @@ -14,10 +14,13 @@ use function is_string; use function sprintf; -class ClearBuildCacheCommand extends Command +final class ClearBuildCacheCommand extends Command { - public function __construct(private CacheClearer $cacheClearer, private string $rootDir, private string $env) - { + public function __construct( + private readonly CacheClearer $cacheClearer, + private readonly string $rootDir, + private readonly string $env, + ) { parent::__construct(); } diff --git a/lib/Commands/SyncRepositoriesCommand.php b/lib/Commands/SyncRepositoriesCommand.php index 0352c39c..5e9d44fd 100644 --- a/lib/Commands/SyncRepositoriesCommand.php +++ b/lib/Commands/SyncRepositoriesCommand.php @@ -12,11 +12,11 @@ use function sprintf; -class SyncRepositoriesCommand extends Command +final class SyncRepositoriesCommand extends Command { public function __construct( - private ProjectDataRepository $projectDataRepository, - private ProjectGitSyncer $projectGitSyncer, + private readonly ProjectDataRepository $projectDataRepository, + private readonly ProjectGitSyncer $projectGitSyncer, ) { parent::__construct(); } diff --git a/lib/Controllers/AtomController.php b/lib/Controllers/AtomController.php index e069f85e..89f9aa39 100644 --- a/lib/Controllers/AtomController.php +++ b/lib/Controllers/AtomController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\BlogPost; use Doctrine\Website\Repositories\BlogPostRepository; -class AtomController +final readonly class AtomController { /** @param BlogPostRepository $blogPostRepository */ - public function __construct(private BlogPostRepository $blogPostRepository) - { + public function __construct( + private BlogPostRepository $blogPostRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/BlogController.php b/lib/Controllers/BlogController.php index f3630092..eb243dd9 100644 --- a/lib/Controllers/BlogController.php +++ b/lib/Controllers/BlogController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\BlogPost; use Doctrine\Website\Repositories\BlogPostRepository; -class BlogController +final readonly class BlogController { /** @param BlogPostRepository $blogPostRepository */ - public function __construct(private BlogPostRepository $blogPostRepository) - { + public function __construct( + private BlogPostRepository $blogPostRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/ConsultingController.php b/lib/Controllers/ConsultingController.php index 1834c3bf..f00f1381 100644 --- a/lib/Controllers/ConsultingController.php +++ b/lib/Controllers/ConsultingController.php @@ -9,11 +9,12 @@ use Doctrine\Website\Model\TeamMember; use Doctrine\Website\Repositories\TeamMemberRepository; -class ConsultingController +final readonly class ConsultingController { /** @param TeamMemberRepository $teamMemberRepository */ - public function __construct(private TeamMemberRepository $teamMemberRepository) - { + public function __construct( + private TeamMemberRepository $teamMemberRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/DocumentationController.php b/lib/Controllers/DocumentationController.php index ebe3b34c..9aa5d745 100644 --- a/lib/Controllers/DocumentationController.php +++ b/lib/Controllers/DocumentationController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\Project; use Doctrine\Website\Repositories\ProjectRepository; -class DocumentationController +final readonly class DocumentationController { /** @param ProjectRepository $projectRepository */ - public function __construct(private ProjectRepository $projectRepository) - { + public function __construct( + private ProjectRepository $projectRepository, + ) { } public function view(string $docsSlug, string $docsVersion): Response diff --git a/lib/Controllers/HomepageController.php b/lib/Controllers/HomepageController.php index 8fb3b2e6..35b1f74e 100644 --- a/lib/Controllers/HomepageController.php +++ b/lib/Controllers/HomepageController.php @@ -15,7 +15,7 @@ use Doctrine\Website\Repositories\PartnerRepository; use Doctrine\Website\Repositories\ProjectRepository; -class HomepageController +final readonly class HomepageController { /** * @param BlogPostRepository $blogPostRepository diff --git a/lib/Controllers/PartnersController.php b/lib/Controllers/PartnersController.php index 984354c5..9aaf0ebc 100644 --- a/lib/Controllers/PartnersController.php +++ b/lib/Controllers/PartnersController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\Partner; use Doctrine\Website\Repositories\PartnerRepository; -final class PartnersController +final readonly class PartnersController { /** @param PartnerRepository $partnerRepository */ - public function __construct(private PartnerRepository $partnerRepository) - { + public function __construct( + private PartnerRepository $partnerRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/ProjectController.php b/lib/Controllers/ProjectController.php index cf8557b5..e1fe86a1 100644 --- a/lib/Controllers/ProjectController.php +++ b/lib/Controllers/ProjectController.php @@ -10,7 +10,7 @@ use Doctrine\Website\Repositories\ProjectContributorRepository; use Doctrine\Website\Repositories\ProjectRepository; -class ProjectController +final readonly class ProjectController { /** * @param ProjectRepository $projectRepository diff --git a/lib/Controllers/SitemapController.php b/lib/Controllers/SitemapController.php index 82796497..a20a06ec 100644 --- a/lib/Controllers/SitemapController.php +++ b/lib/Controllers/SitemapController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\SitemapPage; use Doctrine\Website\Repositories\SitemapPageRepository; -class SitemapController +final readonly class SitemapController { /** @param SitemapPageRepository $sitemapPageRepository */ - public function __construct(private SitemapPageRepository $sitemapPageRepository) - { + public function __construct( + private SitemapPageRepository $sitemapPageRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/SponsorshipController.php b/lib/Controllers/SponsorshipController.php index f086d963..2b951cd2 100644 --- a/lib/Controllers/SponsorshipController.php +++ b/lib/Controllers/SponsorshipController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\Sponsor; use Doctrine\Website\Repositories\SponsorRepository; -class SponsorshipController +final readonly class SponsorshipController { /** @param SponsorRepository $sponsorRepository */ - public function __construct(private SponsorRepository $sponsorRepository) - { + public function __construct( + private SponsorRepository $sponsorRepository, + ) { } public function index(): Response diff --git a/lib/Controllers/TeamController.php b/lib/Controllers/TeamController.php index ed8c8cd6..c95e526d 100644 --- a/lib/Controllers/TeamController.php +++ b/lib/Controllers/TeamController.php @@ -8,11 +8,12 @@ use Doctrine\Website\Model\Contributor; use Doctrine\Website\Repositories\ContributorRepository; -class TeamController +final readonly class TeamController { /** @param ContributorRepository $contributorRepository */ - public function __construct(private ContributorRepository $contributorRepository) - { + public function __construct( + private ContributorRepository $contributorRepository, + ) { } public function maintainers(): Response diff --git a/lib/DataBuilder/BlogPostDataBuilder.php b/lib/DataBuilder/BlogPostDataBuilder.php index 5bb1f2d4..a82cb3b2 100644 --- a/lib/DataBuilder/BlogPostDataBuilder.php +++ b/lib/DataBuilder/BlogPostDataBuilder.php @@ -6,12 +6,13 @@ use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFileFilesystemReader; -class BlogPostDataBuilder implements DataBuilder +final readonly class BlogPostDataBuilder implements DataBuilder { public const DATA_FILE = 'blog_posts'; - public function __construct(private SourceFileFilesystemReader $sourceFileFilesystemReader) - { + public function __construct( + private SourceFileFilesystemReader $sourceFileFilesystemReader, + ) { } public function getName(): string diff --git a/lib/DataBuilder/ContributorDataBuilder.php b/lib/DataBuilder/ContributorDataBuilder.php index c26227de..5615814f 100644 --- a/lib/DataBuilder/ContributorDataBuilder.php +++ b/lib/DataBuilder/ContributorDataBuilder.php @@ -7,13 +7,14 @@ use Doctrine\Website\Model\ProjectContributor; use Doctrine\Website\Repositories\ProjectContributorRepository; -class ContributorDataBuilder implements DataBuilder +final readonly class ContributorDataBuilder implements DataBuilder { public const DATA_FILE = 'contributors'; /** @param ProjectContributorRepository $projectContributorRepository */ - public function __construct(private ProjectContributorRepository $projectContributorRepository) - { + public function __construct( + private ProjectContributorRepository $projectContributorRepository, + ) { } public function getName(): string diff --git a/lib/DataBuilder/ProjectContributorDataBuilder.php b/lib/DataBuilder/ProjectContributorDataBuilder.php index 3064c9ce..19ea84cd 100644 --- a/lib/DataBuilder/ProjectContributorDataBuilder.php +++ b/lib/DataBuilder/ProjectContributorDataBuilder.php @@ -10,7 +10,7 @@ use Doctrine\Website\Repositories\ProjectRepository; use Doctrine\Website\Repositories\TeamMemberRepository; -class ProjectContributorDataBuilder implements DataBuilder +final readonly class ProjectContributorDataBuilder implements DataBuilder { public const DATA_FILE = 'project_contributors'; diff --git a/lib/DataBuilder/ProjectDataBuilder.php b/lib/DataBuilder/ProjectDataBuilder.php index 272a69c5..ae5a6db2 100644 --- a/lib/DataBuilder/ProjectDataBuilder.php +++ b/lib/DataBuilder/ProjectDataBuilder.php @@ -21,7 +21,7 @@ use function strnatcmp; use function usort; -class ProjectDataBuilder implements DataBuilder +final readonly class ProjectDataBuilder implements DataBuilder { public const DATA_FILE = 'projects'; diff --git a/lib/DataBuilder/WebsiteData.php b/lib/DataBuilder/WebsiteData.php index a10f7524..493f9792 100644 --- a/lib/DataBuilder/WebsiteData.php +++ b/lib/DataBuilder/WebsiteData.php @@ -4,11 +4,13 @@ namespace Doctrine\Website\DataBuilder; -class WebsiteData +final readonly class WebsiteData { /** @param mixed[] $data */ - public function __construct(private string $name, private array $data) - { + public function __construct( + private string $name, + private array $data, + ) { } public function getName(): string diff --git a/lib/DataBuilder/WebsiteDataReader.php b/lib/DataBuilder/WebsiteDataReader.php index d49ed114..fe232831 100644 --- a/lib/DataBuilder/WebsiteDataReader.php +++ b/lib/DataBuilder/WebsiteDataReader.php @@ -11,10 +11,12 @@ use function json_decode; use function sprintf; +/** @final */ class WebsiteDataReader { - public function __construct(private string $cacheDir) - { + public function __construct( + private readonly string $cacheDir, + ) { } public function read(string $file): WebsiteData diff --git a/lib/DataBuilder/WebsiteDataWriter.php b/lib/DataBuilder/WebsiteDataWriter.php index a927a814..b07a6695 100644 --- a/lib/DataBuilder/WebsiteDataWriter.php +++ b/lib/DataBuilder/WebsiteDataWriter.php @@ -13,10 +13,11 @@ use const JSON_PRETTY_PRINT; use const JSON_UNESCAPED_SLASHES; -class WebsiteDataWriter +final readonly class WebsiteDataWriter { - public function __construct(private string $cacheDir) - { + public function __construct( + private string $cacheDir, + ) { } public function write(WebsiteData $websiteData): void diff --git a/lib/DataSources/ArrayDataSource.php b/lib/DataSources/ArrayDataSource.php index 3cd42641..0b2b83eb 100644 --- a/lib/DataSources/ArrayDataSource.php +++ b/lib/DataSources/ArrayDataSource.php @@ -6,11 +6,12 @@ use Doctrine\SkeletonMapper\DataSource\DataSource; -final class ArrayDataSource implements DataSource +final readonly class ArrayDataSource implements DataSource { /** @param mixed[] $sourceRows */ - public function __construct(private array $sourceRows) - { + public function __construct( + private array $sourceRows, + ) { } /** @return mixed[][] */ diff --git a/lib/DataSources/BlogPosts.php b/lib/DataSources/BlogPosts.php index c69cd713..6ec7fe4a 100644 --- a/lib/DataSources/BlogPosts.php +++ b/lib/DataSources/BlogPosts.php @@ -9,10 +9,11 @@ use Doctrine\Website\DataBuilder\BlogPostDataBuilder; use Doctrine\Website\DataBuilder\WebsiteDataReader; -class BlogPosts implements DataSource +final readonly class BlogPosts implements DataSource { - public function __construct(private WebsiteDataReader $dataReader) - { + public function __construct( + private WebsiteDataReader $dataReader, + ) { } /** @return mixed[][] */ diff --git a/lib/DataSources/Contributors.php b/lib/DataSources/Contributors.php index b3a6050c..82f550ba 100644 --- a/lib/DataSources/Contributors.php +++ b/lib/DataSources/Contributors.php @@ -12,7 +12,7 @@ use Doctrine\Website\Repositories\ProjectRepository; use Doctrine\Website\Repositories\TeamMemberRepository; -class Contributors implements DataSource +final readonly class Contributors implements DataSource { /** * @param TeamMemberRepository $teamMemberRepository diff --git a/lib/DataSources/ProjectContributors.php b/lib/DataSources/ProjectContributors.php index cd5b111c..e25b1294 100644 --- a/lib/DataSources/ProjectContributors.php +++ b/lib/DataSources/ProjectContributors.php @@ -12,7 +12,7 @@ use Doctrine\Website\Repositories\ProjectRepository; use Doctrine\Website\Repositories\TeamMemberRepository; -class ProjectContributors implements DataSource +final readonly class ProjectContributors implements DataSource { /** * @param TeamMemberRepository $teamMemberRepository diff --git a/lib/DataSources/Projects.php b/lib/DataSources/Projects.php index cc460aac..8866af06 100644 --- a/lib/DataSources/Projects.php +++ b/lib/DataSources/Projects.php @@ -8,10 +8,11 @@ use Doctrine\Website\DataBuilder\ProjectDataBuilder; use Doctrine\Website\DataBuilder\WebsiteDataReader; -class Projects implements DataSource +final readonly class Projects implements DataSource { - public function __construct(private WebsiteDataReader $dataReader) - { + public function __construct( + private WebsiteDataReader $dataReader, + ) { } /** @return mixed[][] */ diff --git a/lib/DataSources/SitemapPages.php b/lib/DataSources/SitemapPages.php index 0c0e3078..8354e72e 100644 --- a/lib/DataSources/SitemapPages.php +++ b/lib/DataSources/SitemapPages.php @@ -8,10 +8,11 @@ use Doctrine\SkeletonMapper\DataSource\DataSource; use Doctrine\StaticWebsiteGenerator\SourceFile\SourceFileRepository; -class SitemapPages implements DataSource +final readonly class SitemapPages implements DataSource { - public function __construct(private SourceFileRepository $sourceFileRepository) - { + public function __construct( + private SourceFileRepository $sourceFileRepository, + ) { } /** @return mixed[][] */ diff --git a/lib/Docs/BuildDocs.php b/lib/Docs/BuildDocs.php index 6d1f11c8..c808042e 100644 --- a/lib/Docs/BuildDocs.php +++ b/lib/Docs/BuildDocs.php @@ -17,7 +17,7 @@ use function count; use function sprintf; -class BuildDocs +final readonly class BuildDocs { /** @param ProjectRepository $projectRepository */ public function __construct( diff --git a/lib/Docs/CodeBlockConsoleRenderer.php b/lib/Docs/CodeBlockConsoleRenderer.php index 1eada4b3..ae0be0d9 100644 --- a/lib/Docs/CodeBlockConsoleRenderer.php +++ b/lib/Docs/CodeBlockConsoleRenderer.php @@ -10,6 +10,7 @@ use function sprintf; use function substr; +/** @final */ class CodeBlockConsoleRenderer { /** @param string[] $lines */ diff --git a/lib/Docs/CodeBlockLanguageDetector.php b/lib/Docs/CodeBlockLanguageDetector.php index 762e88a7..b2a132eb 100644 --- a/lib/Docs/CodeBlockLanguageDetector.php +++ b/lib/Docs/CodeBlockLanguageDetector.php @@ -9,7 +9,7 @@ use function sprintf; use function trim; -class CodeBlockLanguageDetector +final readonly class CodeBlockLanguageDetector { /** * We use some language aliases not supported by our highlighter library @@ -22,8 +22,9 @@ class CodeBlockLanguageDetector 'php-attributes' => 'php', ]; - public function __construct(private string $rootDir) - { + public function __construct( + private string $rootDir, + ) { } /** @param string[] $lines */ diff --git a/lib/Docs/CodeBlockRenderer.php b/lib/Docs/CodeBlockRenderer.php index 5eee468a..eb39c90e 100644 --- a/lib/Docs/CodeBlockRenderer.php +++ b/lib/Docs/CodeBlockRenderer.php @@ -6,7 +6,7 @@ use function in_array; -class CodeBlockRenderer +final readonly class CodeBlockRenderer { private const CONSOLE_LANGUAGES = ['terminal', 'bash', 'sh', 'console']; diff --git a/lib/Docs/CodeBlockWithLineNumbersRenderer.php b/lib/Docs/CodeBlockWithLineNumbersRenderer.php index f77ab11f..9626d461 100644 --- a/lib/Docs/CodeBlockWithLineNumbersRenderer.php +++ b/lib/Docs/CodeBlockWithLineNumbersRenderer.php @@ -14,6 +14,7 @@ use function sprintf; use function str_replace; +/** @final */ class CodeBlockWithLineNumbersRenderer { /** @@ -31,23 +32,24 @@ class CodeBlockWithLineNumbersRenderer private const CODE_LINE_TABLE_COLUMN_TEMPLATE = '{{ RENDERED_CODE }}'; private const CODE_BLOCK_TABLE_TEMPLATE = <<<'TEMPLATE' -
-    
-        
-        
%s
-
-
-TEMPLATE; - - public function __construct(private Highlighter $highlighter) - { +
+            
+                
+                
%s
+
+
+ TEMPLATE; + + public function __construct( + private readonly Highlighter $highlighter, + ) { } /** @param string[] $lines */ diff --git a/lib/Docs/RST/RSTBuilder.php b/lib/Docs/RST/RSTBuilder.php index 8c0d9978..8afd2c69 100644 --- a/lib/Docs/RST/RSTBuilder.php +++ b/lib/Docs/RST/RSTBuilder.php @@ -10,16 +10,17 @@ use Doctrine\Website\Model\ProjectVersion; use Symfony\Component\Filesystem\Filesystem; +/** @final */ class RSTBuilder { public function __construct( - private RSTFileRepository $rstFileRepository, - private RSTCopier $rstCopier, + private readonly RSTFileRepository $rstFileRepository, + private readonly RSTCopier $rstCopier, private Builder $builder, - private RSTPostBuildProcessor $rstPostBuildProcessor, - private Filesystem $filesystem, - private string $sourceDir, - private string $docsDir, + private readonly RSTPostBuildProcessor $rstPostBuildProcessor, + private readonly Filesystem $filesystem, + private readonly string $sourceDir, + private readonly string $docsDir, ) { } diff --git a/lib/Docs/RST/RSTCopier.php b/lib/Docs/RST/RSTCopier.php index 194bd71c..f6bfaded 100644 --- a/lib/Docs/RST/RSTCopier.php +++ b/lib/Docs/RST/RSTCopier.php @@ -13,30 +13,31 @@ use function sprintf; use function str_replace; +/** @final */ class RSTCopier { - public const RST_TEMPLATE = <<<'TEMPLATE' -SIDEBAR BEGIN - -{{ sidebar }} - -CONTENT BEGIN - -{{ content }} -TEMPLATE; - - public const DEFAULT_SIDEBAR = <<<'SIDEBAR' -.. toctree:: - :depth: 3 - :glob: - - /* -SIDEBAR; + final public const RST_TEMPLATE = <<<'TEMPLATE' + SIDEBAR BEGIN + + {{ sidebar }} + + CONTENT BEGIN + + {{ content }} + TEMPLATE; + + final public const DEFAULT_SIDEBAR = <<<'SIDEBAR' + .. toctree:: + :depth: 3 + :glob: + + /* + SIDEBAR; public function __construct( - private RSTFileRepository $rstFileRepository, - private Filesystem $filesystem, - private string $docsDir, + private readonly RSTFileRepository $rstFileRepository, + private readonly Filesystem $filesystem, + private readonly string $docsDir, ) { } diff --git a/lib/Docs/RST/RSTFileRepository.php b/lib/Docs/RST/RSTFileRepository.php index 34381cc2..56926d3a 100644 --- a/lib/Docs/RST/RSTFileRepository.php +++ b/lib/Docs/RST/RSTFileRepository.php @@ -16,6 +16,7 @@ use function sprintf; use function trim; +/** @final */ class RSTFileRepository { /** @throws InvalidArgumentException */ diff --git a/lib/Docs/RST/RSTLanguage.php b/lib/Docs/RST/RSTLanguage.php index 910a1bd4..2e9e514b 100644 --- a/lib/Docs/RST/RSTLanguage.php +++ b/lib/Docs/RST/RSTLanguage.php @@ -4,10 +4,12 @@ namespace Doctrine\Website\Docs\RST; -class RSTLanguage +final readonly class RSTLanguage { - public function __construct(private string $code, private string $path) - { + public function __construct( + private string $code, + private string $path, + ) { } public function getCode(): string diff --git a/lib/Docs/RST/RSTLanguagesDetector.php b/lib/Docs/RST/RSTLanguagesDetector.php index c734d12d..dc70f784 100644 --- a/lib/Docs/RST/RSTLanguagesDetector.php +++ b/lib/Docs/RST/RSTLanguagesDetector.php @@ -17,9 +17,10 @@ use function iterator_to_array; use function strlen; +/** @final */ class RSTLanguagesDetector { - public const ENGLISH_LANGUAGE_CODE = 'en'; + final public const ENGLISH_LANGUAGE_CODE = 'en'; /** @return RSTLanguage[] */ public function detectLanguages(string $docsDir): array diff --git a/lib/Docs/RST/RSTPostBuildProcessor.php b/lib/Docs/RST/RSTPostBuildProcessor.php index d10bb2d3..a5d5051b 100644 --- a/lib/Docs/RST/RSTPostBuildProcessor.php +++ b/lib/Docs/RST/RSTPostBuildProcessor.php @@ -14,21 +14,22 @@ use function str_replace; use function strpos; +/** @final */ class RSTPostBuildProcessor { - public const PARAMETERS_TEMPLATE = <<<'TEMPLATE' ---- -title: "%s" -docsIndex: %s -docsSourcePath: "%s" ---- -%s -TEMPLATE; + final public const PARAMETERS_TEMPLATE = <<<'TEMPLATE' + --- + title: "%s" + docsIndex: %s + docsSourcePath: "%s" + --- + %s + TEMPLATE; public function __construct( - private RSTFileRepository $rstFileRepository, - private Filesystem $filesystem, - private string $sourceDir, + private readonly RSTFileRepository $rstFileRepository, + private readonly Filesystem $filesystem, + private readonly string $sourceDir, ) { } diff --git a/lib/Docs/SearchIndexer.php b/lib/Docs/SearchIndexer.php index f02ef338..d0d77829 100644 --- a/lib/Docs/SearchIndexer.php +++ b/lib/Docs/SearchIndexer.php @@ -22,13 +22,16 @@ /** * Influenced by Laravel.com website code search indexes that also use Algolia. + * + * @final */ class SearchIndexer { - public const INDEX_NAME = 'pages'; + final public const INDEX_NAME = 'pages'; - public function __construct(private SearchClient $client) - { + public function __construct( + private readonly SearchClient $client, + ) { } public function initSearchIndex(): void diff --git a/lib/EventListener/NodeValue.php b/lib/EventListener/NodeValue.php index 61513cea..545db993 100644 --- a/lib/EventListener/NodeValue.php +++ b/lib/EventListener/NodeValue.php @@ -9,7 +9,7 @@ use function str_replace; -final class NodeValue +final readonly class NodeValue { public function preNodeRender(PreNodeRenderEvent $event): void { diff --git a/lib/EventListener/TableIncompatibility.php b/lib/EventListener/TableIncompatibility.php index ba370ca7..f0c6c511 100644 --- a/lib/EventListener/TableIncompatibility.php +++ b/lib/EventListener/TableIncompatibility.php @@ -9,7 +9,7 @@ use function str_contains; use function str_replace; -final class TableIncompatibility +final readonly class TableIncompatibility { private const BEFORE = '| **SQL Server** | +----------------------------------------------------------+'; private const AFTER = '| **SQL Server** | | |'; diff --git a/lib/Git/Tag.php b/lib/Git/Tag.php index e8a78bda..9f47aa48 100644 --- a/lib/Git/Tag.php +++ b/lib/Git/Tag.php @@ -11,7 +11,7 @@ use function strpos; use function strtoupper; -class Tag +final readonly class Tag { private const ALPHA = 'alpha'; private const BETA = 'beta'; @@ -27,8 +27,10 @@ class Tag private const COMPOSER_EPOCH = '2011-09-25'; - public function __construct(private string $name, private DateTimeImmutable $date) - { + public function __construct( + private string $name, + private DateTimeImmutable $date, + ) { } public function getName(): string diff --git a/lib/Git/TagBranchGuesser.php b/lib/Git/TagBranchGuesser.php index 8f8486ea..5d62ac60 100644 --- a/lib/Git/TagBranchGuesser.php +++ b/lib/Git/TagBranchGuesser.php @@ -12,12 +12,14 @@ use function preg_match_all; use function sprintf; +/** @final */ class TagBranchGuesser { private const COMMAND = 'cd %s && git branch -a'; - public function __construct(private ProcessFactory $processFactory) - { + public function __construct( + private ProcessFactory $processFactory, + ) { } public function guessTagBranchName(string $repositoryPath, Tag $tag): string|null diff --git a/lib/Git/TagReader.php b/lib/Git/TagReader.php index 0a35e3bb..59b4b084 100644 --- a/lib/Git/TagReader.php +++ b/lib/Git/TagReader.php @@ -13,12 +13,14 @@ use function str_replace; use function usort; +/** @final */ class TagReader { private const COMMAND = "cd %s && git tag -l --format='refname: %%(refname) creatordate: %%(creatordate)'"; - public function __construct(private ProcessFactory $processFactory) - { + public function __construct( + private readonly ProcessFactory $processFactory, + ) { } /** @return Tag[] */ diff --git a/lib/Github/GithubClientProvider.php b/lib/Github/GithubClientProvider.php index e848298a..1970b2da 100644 --- a/lib/Github/GithubClientProvider.php +++ b/lib/Github/GithubClientProvider.php @@ -8,12 +8,15 @@ use Github\Client; use InvalidArgumentException; +/** @final */ class GithubClientProvider { private bool $authenticated = false; - public function __construct(private Client $githubClient, private string $githubHttpToken) - { + public function __construct( + private readonly Client $githubClient, + private readonly string $githubHttpToken, + ) { if ($githubHttpToken === '') { throw new InvalidArgumentException('You must configure a Github http token.'); } diff --git a/lib/Github/ProdGithubProjectContributors.php b/lib/Github/ProdGithubProjectContributors.php index 17d29793..1d6ac73e 100644 --- a/lib/Github/ProdGithubProjectContributors.php +++ b/lib/Github/ProdGithubProjectContributors.php @@ -14,7 +14,7 @@ use function sleep; use function sprintf; -class ProdGithubProjectContributors implements GithubProjectContributors +final readonly class ProdGithubProjectContributors implements GithubProjectContributors { public function __construct( private CacheItemPoolInterface $cache, diff --git a/lib/Hydrators/ModelHydrator.php b/lib/Hydrators/ModelHydrator.php index 88e2976b..2eed801e 100644 --- a/lib/Hydrators/ModelHydrator.php +++ b/lib/Hydrators/ModelHydrator.php @@ -15,13 +15,14 @@ abstract class ModelHydrator extends ObjectHydrator private object $object; /** @var ClassMetadataInterface */ - private ClassMetadataInterface $classMetadata; + private readonly ClassMetadataInterface $classMetadata; /** @var ReflectionProperty[] */ private array $reflectionProperties; - public function __construct(protected ObjectManagerInterface $objectManager) - { + public function __construct( + protected readonly ObjectManagerInterface $objectManager, + ) { $this->classMetadata = $this->objectManager->getClassMetadata($this->getClassName()); } diff --git a/lib/ProcessFactory.php b/lib/ProcessFactory.php index 32682e38..0bba1e1f 100644 --- a/lib/ProcessFactory.php +++ b/lib/ProcessFactory.php @@ -8,6 +8,7 @@ use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; +/** @final */ class ProcessFactory { /** @return Process */ diff --git a/lib/Projects/GetProjectPackagistData.php b/lib/Projects/GetProjectPackagistData.php index 6724308a..ef4e87ad 100644 --- a/lib/Projects/GetProjectPackagistData.php +++ b/lib/Projects/GetProjectPackagistData.php @@ -8,10 +8,12 @@ use function json_decode; use function sprintf; +/** @final */ class GetProjectPackagistData { - public function __construct(private string $packagistUrlFormat) - { + public function __construct( + private readonly string $packagistUrlFormat, + ) { } /** @return mixed[] */ diff --git a/lib/Projects/GetTotalDownloads.php b/lib/Projects/GetTotalDownloads.php index 197a9911..a6a6903a 100644 --- a/lib/Projects/GetTotalDownloads.php +++ b/lib/Projects/GetTotalDownloads.php @@ -7,11 +7,12 @@ use Doctrine\Website\Model\Project; use Doctrine\Website\Repositories\ProjectRepository; -final class GetTotalDownloads +final readonly class GetTotalDownloads { /** @param ProjectRepository $projectRepository */ - public function __construct(private ProjectRepository $projectRepository) - { + public function __construct( + private ProjectRepository $projectRepository, + ) { } public function __invoke(): int diff --git a/lib/Projects/ProjectDataReader.php b/lib/Projects/ProjectDataReader.php index 77a8bbc2..12b7bf2e 100644 --- a/lib/Projects/ProjectDataReader.php +++ b/lib/Projects/ProjectDataReader.php @@ -21,22 +21,23 @@ use const JSON_ERROR_NONE; +/** @final */ class ProjectDataReader { private const DOCTRINE_PROJECT_JSON_FILE_NAME = '.doctrine-project.json'; private const COMPOSER_JSON_FILE_NAME = 'composer.json'; - private Inflector $inflector; + private readonly Inflector $inflector; /** * @param mixed[] $projectsData * @param mixed[] $projectIntegrationTypes */ public function __construct( - private string $projectsDir, - private array $projectsData, - private array $projectIntegrationTypes, + private readonly string $projectsDir, + private readonly array $projectsData, + private readonly array $projectIntegrationTypes, ) { $this->inflector = InflectorFactory::create()->build(); } diff --git a/lib/Projects/ProjectDataRepository.php b/lib/Projects/ProjectDataRepository.php index 843dae1f..4de23d0d 100644 --- a/lib/Projects/ProjectDataRepository.php +++ b/lib/Projects/ProjectDataRepository.php @@ -4,11 +4,13 @@ namespace Doctrine\Website\Projects; +/** @final */ class ProjectDataRepository { /** @param mixed[][] $projectsData */ - public function __construct(private array $projectsData = []) - { + public function __construct( + private readonly array $projectsData = [], + ) { } /** @return string[] */ diff --git a/lib/Projects/ProjectGitSyncer.php b/lib/Projects/ProjectGitSyncer.php index 849ef0ac..07da306a 100644 --- a/lib/Projects/ProjectGitSyncer.php +++ b/lib/Projects/ProjectGitSyncer.php @@ -12,12 +12,16 @@ use function is_dir; use function sprintf; +/** @final */ class ProjectGitSyncer { - private Repo $githubRepo; + private readonly Repo $githubRepo; - public function __construct(private ProcessFactory $processFactory, GithubClientProvider $githubClientProvider, private string $projectsDir) - { + public function __construct( + private readonly ProcessFactory $processFactory, + GithubClientProvider $githubClientProvider, + private readonly string $projectsDir, + ) { // TODO Inject Repo instead of GithubClientProvider $this->githubRepo = $githubClientProvider->getGithubClient()->repo(); } diff --git a/lib/Projects/ProjectVersionsReader.php b/lib/Projects/ProjectVersionsReader.php index f026fa44..6a6fd3aa 100644 --- a/lib/Projects/ProjectVersionsReader.php +++ b/lib/Projects/ProjectVersionsReader.php @@ -11,10 +11,13 @@ use function array_filter; use function array_values; +/** @final */ class ProjectVersionsReader { - public function __construct(private TagReader $tagReader, private TagBranchGuesser $tagBranchGuesser) - { + public function __construct( + private readonly TagReader $tagReader, + private readonly TagBranchGuesser $tagBranchGuesser, + ) { } /** @return mixed[] */ diff --git a/lib/Requests/ContributorRequests.php b/lib/Requests/ContributorRequests.php index 4f916040..0913cc04 100644 --- a/lib/Requests/ContributorRequests.php +++ b/lib/Requests/ContributorRequests.php @@ -9,11 +9,12 @@ use Doctrine\Website\Model\Contributor; use Doctrine\Website\Repositories\ContributorRepository; -class ContributorRequests +final readonly class ContributorRequests { /** @param ContributorRepository $contributorRepository */ - public function __construct(private ContributorRepository $contributorRepository) - { + public function __construct( + private ContributorRepository $contributorRepository, + ) { } public function getContributors(): RequestCollection diff --git a/lib/Requests/PartnerRequests.php b/lib/Requests/PartnerRequests.php index adb019d4..8d9e90f0 100644 --- a/lib/Requests/PartnerRequests.php +++ b/lib/Requests/PartnerRequests.php @@ -9,11 +9,12 @@ use Doctrine\Website\Model\Partner; use Doctrine\Website\Repositories\PartnerRepository; -class PartnerRequests +final readonly class PartnerRequests { /** @param PartnerRepository $partnerRepository */ - public function __construct(private PartnerRepository $partnerRepository) - { + public function __construct( + private PartnerRepository $partnerRepository, + ) { } public function getPartners(): RequestCollection diff --git a/lib/Requests/ProjectRequests.php b/lib/Requests/ProjectRequests.php index 1cdd7cc3..7b3a3838 100644 --- a/lib/Requests/ProjectRequests.php +++ b/lib/Requests/ProjectRequests.php @@ -9,11 +9,12 @@ use Doctrine\Website\Model\Project; use Doctrine\Website\Repositories\ProjectRepository; -class ProjectRequests +final readonly class ProjectRequests { /** @param ProjectRepository $projectRepository */ - public function __construct(private ProjectRepository $projectRepository) - { + public function __construct( + private ProjectRepository $projectRepository, + ) { } public function getProjects(): RequestCollection diff --git a/lib/Requests/ProjectVersionRequests.php b/lib/Requests/ProjectVersionRequests.php index 9430c221..53e222b1 100644 --- a/lib/Requests/ProjectVersionRequests.php +++ b/lib/Requests/ProjectVersionRequests.php @@ -9,11 +9,12 @@ use Doctrine\Website\Model\Project; use Doctrine\Website\Repositories\ProjectRepository; -class ProjectVersionRequests +final readonly class ProjectVersionRequests { /** @param ProjectRepository $projectRepository */ - public function __construct(private ProjectRepository $projectRepository) - { + public function __construct( + private ProjectRepository $projectRepository, + ) { } public function getProjectVersions(): RequestCollection diff --git a/lib/Site.php b/lib/Site.php index 5044aece..6c82659c 100644 --- a/lib/Site.php +++ b/lib/Site.php @@ -17,7 +17,7 @@ public function __construct( string $description, string $env, string $googleAnalyticsTrackingId, - private string $assetsUrl, + private readonly string $assetsUrl, ) { parent::__construct( $title, diff --git a/lib/Twig/MainExtension.php b/lib/Twig/MainExtension.php index 718ab070..fcba7c3a 100644 --- a/lib/Twig/MainExtension.php +++ b/lib/Twig/MainExtension.php @@ -23,13 +23,13 @@ use function strrpos; use function substr; -class MainExtension extends AbstractExtension +final class MainExtension extends AbstractExtension { public function __construct( - private Parsedown $parsedown, - private AssetIntegrityGenerator $assetIntegrityGenerator, - private string $sourceDir, - private string $webpackBuildDir, + private readonly Parsedown $parsedown, + private readonly AssetIntegrityGenerator $assetIntegrityGenerator, + private readonly string $sourceDir, + private readonly string $webpackBuildDir, ) { } diff --git a/lib/Twig/ProjectExtension.php b/lib/Twig/ProjectExtension.php index 2165af05..ef243d53 100644 --- a/lib/Twig/ProjectExtension.php +++ b/lib/Twig/ProjectExtension.php @@ -14,11 +14,13 @@ use function str_replace; use function strpos; -class ProjectExtension extends AbstractExtension +final class ProjectExtension extends AbstractExtension { /** @param ProjectRepository $projectRepository */ - public function __construct(private ProjectRepository $projectRepository, private string $sourceDir) - { + public function __construct( + private readonly ProjectRepository $projectRepository, + private readonly string $sourceDir, + ) { } /** {@inheritDoc} */ diff --git a/lib/WebsiteBuilder.php b/lib/WebsiteBuilder.php index 4c875c88..f8683f35 100644 --- a/lib/WebsiteBuilder.php +++ b/lib/WebsiteBuilder.php @@ -22,6 +22,7 @@ use function is_link; use function sprintf; +/** @final */ class WebsiteBuilder { public const PUBLISHABLE_ENVS = [Application::ENV_PROD, Application::ENV_STAGING]; @@ -36,14 +37,14 @@ class WebsiteBuilder /** @param ProjectRepository $projectRepository */ public function __construct( - private ProcessFactory $processFactory, - private ProjectRepository $projectRepository, - private Filesystem $filesystem, - private SourceFileRepository $sourceFileRepository, - private SourceFilesBuilder $sourceFilesBuilder, - private string $rootDir, - private string $cacheDir, - private string $webpackBuildDir, + private readonly ProcessFactory $processFactory, + private readonly ProjectRepository $projectRepository, + private readonly Filesystem $filesystem, + private readonly SourceFileRepository $sourceFileRepository, + private readonly SourceFilesBuilder $sourceFilesBuilder, + private readonly string $rootDir, + private readonly string $cacheDir, + private readonly string $webpackBuildDir, ) { }