Skip to content

Commit

Permalink
Merge pull request #532 from derrabus/improvement/final-readonly
Browse files Browse the repository at this point in the history
Use final and readonly where possible
  • Loading branch information
SenseException authored Sep 26, 2023
2 parents 3a4eb99 + 0bd4b40 commit 82d7d1e
Show file tree
Hide file tree
Showing 67 changed files with 279 additions and 208 deletions.
2 changes: 1 addition & 1 deletion lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions lib/Assets/AssetIntegrityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Cache/CacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function glob;
use function sprintf;

class CacheClearer
final readonly class CacheClearer
{
public function __construct(
private Filesystem $filesystem,
Expand Down
6 changes: 3 additions & 3 deletions lib/Commands/BuildAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Commands/BuildDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Commands/BuildWebsiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use function sprintf;
use function time;

class BuildWebsiteCommand extends Command
final class BuildWebsiteCommand extends Command
{
private const WATCH_DIRS = [
'config',
Expand All @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Commands/BuildWebsiteDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Commands/ClearBuildCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Commands/SyncRepositoriesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/AtomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\BlogPost;
use Doctrine\Website\Repositories\BlogPostRepository;

class AtomController
final readonly class AtomController
{
/** @param BlogPostRepository<BlogPost> $blogPostRepository */
public function __construct(private BlogPostRepository $blogPostRepository)
{
public function __construct(
private BlogPostRepository $blogPostRepository,
) {
}

public function index(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\BlogPost;
use Doctrine\Website\Repositories\BlogPostRepository;

class BlogController
final readonly class BlogController
{
/** @param BlogPostRepository<BlogPost> $blogPostRepository */
public function __construct(private BlogPostRepository $blogPostRepository)
{
public function __construct(
private BlogPostRepository $blogPostRepository,
) {
}

public function index(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/ConsultingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
use Doctrine\Website\Model\TeamMember;
use Doctrine\Website\Repositories\TeamMemberRepository;

class ConsultingController
final readonly class ConsultingController
{
/** @param TeamMemberRepository<TeamMember> $teamMemberRepository */
public function __construct(private TeamMemberRepository $teamMemberRepository)
{
public function __construct(
private TeamMemberRepository $teamMemberRepository,
) {
}

public function index(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/DocumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\Project;
use Doctrine\Website\Repositories\ProjectRepository;

class DocumentationController
final readonly class DocumentationController
{
/** @param ProjectRepository<Project> $projectRepository */
public function __construct(private ProjectRepository $projectRepository)
{
public function __construct(
private ProjectRepository $projectRepository,
) {
}

public function view(string $docsSlug, string $docsVersion): Response
Expand Down
2 changes: 1 addition & 1 deletion lib/Controllers/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Doctrine\Website\Repositories\PartnerRepository;
use Doctrine\Website\Repositories\ProjectRepository;

class HomepageController
final readonly class HomepageController
{
/**
* @param BlogPostRepository<BlogPost> $blogPostRepository
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/PartnersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\Partner;
use Doctrine\Website\Repositories\PartnerRepository;

final class PartnersController
final readonly class PartnersController
{
/** @param PartnerRepository<Partner> $partnerRepository */
public function __construct(private PartnerRepository $partnerRepository)
{
public function __construct(
private PartnerRepository $partnerRepository,
) {
}

public function index(): Response
Expand Down
2 changes: 1 addition & 1 deletion lib/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Doctrine\Website\Repositories\ProjectContributorRepository;
use Doctrine\Website\Repositories\ProjectRepository;

class ProjectController
final readonly class ProjectController
{
/**
* @param ProjectRepository<Project> $projectRepository
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\SitemapPage;
use Doctrine\Website\Repositories\SitemapPageRepository;

class SitemapController
final readonly class SitemapController
{
/** @param SitemapPageRepository<SitemapPage> $sitemapPageRepository */
public function __construct(private SitemapPageRepository $sitemapPageRepository)
{
public function __construct(
private SitemapPageRepository $sitemapPageRepository,
) {
}

public function index(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/SponsorshipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\Sponsor;
use Doctrine\Website\Repositories\SponsorRepository;

class SponsorshipController
final readonly class SponsorshipController
{
/** @param SponsorRepository<Sponsor> $sponsorRepository */
public function __construct(private SponsorRepository $sponsorRepository)
{
public function __construct(
private SponsorRepository $sponsorRepository,
) {
}

public function index(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/Controllers/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Website\Model\Contributor;
use Doctrine\Website\Repositories\ContributorRepository;

class TeamController
final readonly class TeamController
{
/** @param ContributorRepository<Contributor> $contributorRepository */
public function __construct(private ContributorRepository $contributorRepository)
{
public function __construct(
private ContributorRepository $contributorRepository,
) {
}

public function maintainers(): Response
Expand Down
7 changes: 4 additions & 3 deletions lib/DataBuilder/BlogPostDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/DataBuilder/ContributorDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectContributor> $projectContributorRepository */
public function __construct(private ProjectContributorRepository $projectContributorRepository)
{
public function __construct(
private ProjectContributorRepository $projectContributorRepository,
) {
}

public function getName(): string
Expand Down
2 changes: 1 addition & 1 deletion lib/DataBuilder/ProjectContributorDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/DataBuilder/ProjectDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 5 additions & 3 deletions lib/DataBuilder/WebsiteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/DataBuilder/WebsiteDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/DataBuilder/WebsiteDataWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 82d7d1e

Please sign in to comment.