Skip to content

Commit

Permalink
CS Fixes - Union types for nullables and constructor property promotion
Browse files Browse the repository at this point in the history
- SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion
- SlevomatCodingStandard.TypeHints.UnionTypeHintFormat

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Aug 29, 2022
1 parent b6d38ba commit 3144dfa
Show file tree
Hide file tree
Showing 31 changed files with 174 additions and 433 deletions.
22 changes: 5 additions & 17 deletions src/Application/Command/BumpChangelogForReleaseBranch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,14 @@

final class BumpChangelogForReleaseBranch extends Command
{
private Variables $environment;
private LoadCurrentGithubEvent $loadEvent;
private Fetch $fetch;
private GetMergeTargetCandidateBranches $getMergeTargets;
private BumpAndCommitChangelogVersion $bumpChangelogVersion;

public function __construct(
Variables $environment,
LoadCurrentGithubEvent $loadEvent,
Fetch $fetch,
GetMergeTargetCandidateBranches $getMergeTargets,
BumpAndCommitChangelogVersion $bumpChangelogVersion,
private readonly Variables $environment,
private readonly LoadCurrentGithubEvent $loadEvent,
private readonly Fetch $fetch,
private readonly GetMergeTargetCandidateBranches $getMergeTargets,
private readonly BumpAndCommitChangelogVersion $bumpChangelogVersion,
) {
parent::__construct('laminas:automatic-releases:bump-changelog');

$this->environment = $environment;
$this->loadEvent = $loadEvent;
$this->fetch = $fetch;
$this->getMergeTargets = $getMergeTargets;
$this->bumpChangelogVersion = $bumpChangelogVersion;
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down
34 changes: 8 additions & 26 deletions src/Application/Command/CreateMergeUpPullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,17 @@

final class CreateMergeUpPullRequest extends Command
{
private Variables $variables;
private LoadCurrentGithubEvent $loadGithubEvent;
private Fetch $fetch;
private GetMergeTargetCandidateBranches $getMergeCandidates;
private GetGithubMilestone $getMilestone;
private CreateReleaseText $createReleaseText;
private Push $push;
private CreatePullRequest $createPullRequest;

public function __construct(
Variables $variables,
LoadCurrentGithubEvent $loadGithubEvent,
Fetch $fetch,
GetMergeTargetCandidateBranches $getMergeCandidates,
GetGithubMilestone $getMilestone,
CreateReleaseText $createReleaseText,
Push $push,
CreatePullRequest $createPullRequest,
private readonly Variables $variables,
private readonly LoadCurrentGithubEvent $loadGithubEvent,
private readonly Fetch $fetch,
private readonly GetMergeTargetCandidateBranches $getMergeCandidates,
private readonly GetGithubMilestone $getMilestone,
private readonly CreateReleaseText $createReleaseText,
private readonly Push $push,
private readonly CreatePullRequest $createPullRequest,
) {
parent::__construct('laminas:automatic-releases:create-merge-up-pull-request');

$this->variables = $variables;
$this->loadGithubEvent = $loadGithubEvent;
$this->fetch = $fetch;
$this->getMergeCandidates = $getMergeCandidates;
$this->getMilestone = $getMilestone;
$this->createReleaseText = $createReleaseText;
$this->push = $push;
$this->createPullRequest = $createPullRequest;
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down
10 changes: 2 additions & 8 deletions src/Application/Command/CreateMilestones.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@

final class CreateMilestones extends Command
{
private LoadCurrentGithubEvent $loadEvent;
private CreateMilestone $createMilestone;

public function __construct(
LoadCurrentGithubEvent $loadEvent,
CreateMilestone $createMilestone,
private readonly LoadCurrentGithubEvent $loadEvent,
private readonly CreateMilestone $createMilestone,
) {
parent::__construct('laminas:automatic-releases:create-milestones');

$this->loadEvent = $loadEvent;
$this->createMilestone = $createMilestone;
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down
42 changes: 10 additions & 32 deletions src/Application/Command/ReleaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,19 @@

final class ReleaseCommand extends Command
{
private Variables $environment;
private LoadCurrentGithubEvent $loadEvent;
private Fetch $fetch;
private GetMergeTargetCandidateBranches $getMergeTargets;
private GetGithubMilestone $getMilestone;
private CommitReleaseChangelog $commitChangelog;
private CreateReleaseText $createChangelogText;
private CreateTag $createTag;
private Push $push;
private CreateRelease $createRelease;

public function __construct(
Variables $environment,
LoadCurrentGithubEvent $loadEvent,
Fetch $fetch,
GetMergeTargetCandidateBranches $getMergeTargets,
GetGithubMilestone $getMilestone,
CommitReleaseChangelog $commitChangelog,
CreateReleaseText $createChangelogText,
CreateTag $createTag,
Push $push,
CreateRelease $createRelease,
private readonly Variables $environment,
private readonly LoadCurrentGithubEvent $loadEvent,
private readonly Fetch $fetch,
private readonly GetMergeTargetCandidateBranches $getMergeTargets,
private readonly GetGithubMilestone $getMilestone,
private readonly CommitReleaseChangelog $commitChangelog,
private readonly CreateReleaseText $createChangelogText,
private readonly CreateTag $createTag,
private readonly Push $push,
private readonly CreateRelease $createRelease,
) {
parent::__construct('laminas:automatic-releases:release');

$this->environment = $environment;
$this->loadEvent = $loadEvent;
$this->fetch = $fetch;
$this->getMergeTargets = $getMergeTargets;
$this->getMilestone = $getMilestone;
$this->commitChangelog = $commitChangelog;
$this->createChangelogText = $createChangelogText;
$this->createTag = $createTag;
$this->push = $push;
$this->createRelease = $createRelease;
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down
30 changes: 7 additions & 23 deletions src/Application/Command/SwitchDefaultBranchToNextMinor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,16 @@

final class SwitchDefaultBranchToNextMinor extends Command
{
private Variables $variables;
private LoadCurrentGithubEvent $loadGithubEvent;
private Fetch $fetch;
private GetMergeTargetCandidateBranches $getMergeCandidates;
private Push $push;
private SetDefaultBranch $switchDefaultBranch;
private BumpAndCommitChangelogVersion $bumpChangelogVersion;

public function __construct(
Variables $variables,
LoadCurrentGithubEvent $loadGithubEvent,
Fetch $fetch,
GetMergeTargetCandidateBranches $getMergeCandidates,
Push $push,
SetDefaultBranch $switchDefaultBranch,
BumpAndCommitChangelogVersion $bumpChangelogVersion,
private readonly Variables $variables,
private readonly LoadCurrentGithubEvent $loadGithubEvent,
private readonly Fetch $fetch,
private readonly GetMergeTargetCandidateBranches $getMergeCandidates,
private readonly Push $push,
private readonly SetDefaultBranch $switchDefaultBranch,
private readonly BumpAndCommitChangelogVersion $bumpChangelogVersion,
) {
parent::__construct('laminas:automatic-releases:switch-default-branch-to-next-minor');

$this->variables = $variables;
$this->loadGithubEvent = $loadGithubEvent;
$this->fetch = $fetch;
$this->getMergeCandidates = $getMergeCandidates;
$this->push = $push;
$this->switchDefaultBranch = $switchDefaultBranch;
$this->bumpChangelogVersion = $bumpChangelogVersion;
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down
21 changes: 5 additions & 16 deletions src/Changelog/BumpAndCommitChangelogVersionViaKeepAChangelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,13 @@ class BumpAndCommitChangelogVersionViaKeepAChangelog implements BumpAndCommitCha
Updates the %s file to add a changelog entry for a new %s version.
COMMIT;

private ChangelogExists $changelogExists;
private CheckoutBranch $checkoutBranch;
private CommitFile $commitFile;
private Push $push;
private LoggerInterface $logger;

public function __construct(
ChangelogExists $changelogExists,
CheckoutBranch $checkoutBranch,
CommitFile $commitFile,
Push $push,
LoggerInterface $logger,
private readonly ChangelogExists $changelogExists,
private readonly CheckoutBranch $checkoutBranch,
private readonly CommitFile $commitFile,
private readonly Push $push,
private readonly LoggerInterface $logger,
) {
$this->changelogExists = $changelogExists;
$this->checkoutBranch = $checkoutBranch;
$this->commitFile = $commitFile;
$this->push = $push;
$this->logger = $logger;
}

public function __invoke(
Expand Down
10 changes: 2 additions & 8 deletions src/Changelog/ChangelogReleaseNotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class ChangelogReleaseNotes
{
private const CONCATENATION_STRING = "\n\n-----\n\n";

private ?ChangelogEntry $changelogEntry;

/** @psalm-var non-empty-string */
private string $contents;

/** @psalm-param non-empty-string $changelogFile */
public static function writeChangelogFile(string $changelogFile, self $releaseNotes): void
{
Expand All @@ -42,14 +37,13 @@ public static function writeChangelogFile(string $changelogFile, self $releaseNo

/** @psalm-param non-empty-string $contents */
public function __construct(
string $contents,
?ChangelogEntry $changelogEntry = null,
private string $contents,
private ChangelogEntry|null $changelogEntry = null,
) {
if ($changelogEntry) {
$changelogEntry = clone $changelogEntry;
}

$this->contents = $contents;
$this->changelogEntry = $changelogEntry;
}

Expand Down
21 changes: 5 additions & 16 deletions src/Changelog/CommitReleaseChangelogViaKeepAChangelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,13 @@ final class CommitReleaseChangelogViaKeepAChangelog implements CommitReleaseChan
Updates the %s to set the release date.
COMMIT;

private ChangelogExists $changelogExists;
private CheckoutBranch $checkoutBranch;
private CommitFile $commitFile;
private Push $push;
private LoggerInterface $logger;

public function __construct(
ChangelogExists $changelogExists,
CheckoutBranch $checkoutBranch,
CommitFile $commitFile,
Push $push,
LoggerInterface $logger,
private readonly ChangelogExists $changelogExists,
private readonly CheckoutBranch $checkoutBranch,
private readonly CommitFile $commitFile,
private readonly Push $push,
private readonly LoggerInterface $logger,
) {
$this->changelogExists = $changelogExists;
$this->checkoutBranch = $checkoutBranch;
$this->commitFile = $commitFile;
$this->push = $push;
$this->logger = $logger;
}

/** @psalm-param non-empty-string $repositoryDirectory */
Expand Down
37 changes: 7 additions & 30 deletions src/Environment/EnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ class EnvironmentVariables implements Variables
'EMERGENCY',
];

/** @psalm-var non-empty-string */
private string $githubToken;
private SecretKeyId $signingSecretKey;
/** @psalm-var non-empty-string */
private string $gitAuthorName;
/** @psalm-var non-empty-string */
private string $gitAuthorEmail;
/** @psalm-var non-empty-string */
private string $githubEventPath;
/** @psalm-var non-empty-string */
private string $workspacePath;
/** @psalm-var non-empty-string */
private string $logLevel;

/**
* @psalm-param non-empty-string $githubToken
* @psalm-param non-empty-string $gitAuthorName
Expand All @@ -56,29 +42,20 @@ class EnvironmentVariables implements Variables
* @psalm-param non-empty-string $logLevel
*/
private function __construct(
string $githubToken,
SecretKeyId $signingSecretKey,
string $gitAuthorName,
string $gitAuthorEmail,
string $githubEventPath,
string $workspacePath,
string $logLevel,
private readonly string $githubToken,
private readonly SecretKeyId $signingSecretKey,
private readonly string $gitAuthorName,
private readonly string $gitAuthorEmail,
private readonly string $githubEventPath,
private readonly string $workspacePath,
private readonly string $logLevel,
) {
$this->githubToken = $githubToken;
$this->signingSecretKey = $signingSecretKey;
$this->gitAuthorName = $gitAuthorName;
$this->gitAuthorEmail = $gitAuthorEmail;
$this->githubEventPath = $githubEventPath;
$this->workspacePath = $workspacePath;

/** @psalm-suppress ImpureFunctionCall the {@see \Psl\Iter\contains()} API is conditionally pure */
Psl\invariant(
Iter\contains(self::LOG_LEVELS, $logLevel),
'LOG_LEVEL env MUST be a valid monolog/monolog log level constant name or value;'
. ' see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels',
);

$this->logLevel = $logLevel;
}

public static function fromEnvironment(ImportGpgKeyFromString $importKey): self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

final class FetchAndSetCurrentUserByReplacingCurrentOriginRemote implements Fetch
{
private EnvironmentVariables $variables;

public function __construct(EnvironmentVariables $variables)
public function __construct(private readonly EnvironmentVariables $variables)
{
$this->variables = $variables;
}

public function __invoke(
Expand Down
2 changes: 1 addition & 1 deletion src/Git/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ interface Push
public function __invoke(
string $repositoryDirectory,
string $symbol,
?string $alias = null,
string|null $alias = null,
): void;
}
2 changes: 1 addition & 1 deletion src/Git/PushViaConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class PushViaConsole implements Push
public function __invoke(
string $repositoryDirectory,
string $symbol,
?string $alias = null,
string|null $alias = null,
): void {
if ($alias === null) {
Shell\execute('git', ['push', 'origin', $symbol], $repositoryDirectory);
Expand Down
Loading

0 comments on commit 3144dfa

Please sign in to comment.