Skip to content

Commit

Permalink
Enhancement: Use constructor property promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 1, 2022
1 parent a774e00 commit 78a85f2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 46 deletions.
18 changes: 4 additions & 14 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,13 @@
*/
final class NormalizeCommand extends Command\BaseCommand
{
private Factory $factory;
private Normalizer\NormalizerInterface $normalizer;
private Normalizer\Format\FormatterInterface $formatter;
private Diff\Differ $differ;

public function __construct(
Factory $factory,
Normalizer\NormalizerInterface $normalizer,
Normalizer\Format\FormatterInterface $formatter,
Diff\Differ $differ,
private Factory $factory,
private Normalizer\NormalizerInterface $normalizer,
private Normalizer\Format\FormatterInterface $formatter,
private Diff\Differ $differ,
) {
parent::__construct('normalize');

$this->factory = $factory;
$this->normalizer = $normalizer;
$this->formatter = $formatter;
$this->differ = $differ;
}

protected function configure(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ public function testFailsWhenNormalizerThrowsRuntimeExceptionDuringNormalization
$application = self::createApplication(new NormalizeCommand(
new Factory(),
new class($exceptionMessage) implements Normalizer\NormalizerInterface {
private string $exceptionMessage;

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

public function normalize(Normalizer\Json $json): Normalizer\Json
Expand Down
5 changes: 1 addition & 4 deletions test/Util/CommandInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@

final class CommandInvocation
{
private string $style;

private function __construct(string $style)
private function __construct(private string $style)
{
$this->style = $style;
}

public static function inCurrentWorkingDirectory(): self
Expand Down
4 changes: 1 addition & 3 deletions test/Util/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

final class Directory
{
private string $path;
private bool $exists;

private function __construct(string $path)
private function __construct(private string $path)
{
$this->path = $path;
$this->exists = \file_exists($path) && \is_dir($path);
}

Expand Down
13 changes: 3 additions & 10 deletions test/Util/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@

final class File
{
private string $path;
private bool $exists;
private ?string $contents;

private function __construct(
string $path,
bool $exists,
?string $contents,
private string $path,
private bool $exists,
private ?string $contents,
) {
$this->path = $path;
$this->exists = $exists;
$this->contents = $contents;
}

public static function fromPath(string $path): self
Expand Down
9 changes: 2 additions & 7 deletions test/Util/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@

final class Scenario
{
private CommandInvocation $commandInvocation;
private State $initialState;

private function __construct(
CommandInvocation $commandInvocation,
State $initialState,
private CommandInvocation $commandInvocation,
private State $initialState,
) {
$this->commandInvocation = $commandInvocation;
$this->initialState = $initialState;
}

public static function fromCommandInvocationAndInitialState(
Expand Down
5 changes: 1 addition & 4 deletions test/Util/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@

final class State
{
private Directory $directory;
private File $composerJsonFile;
private File $composerLockFile;
private Directory $vendorDirectory;

private function __construct(Directory $directory)
private function __construct(private Directory $directory)
{
$this->directory = $directory;

$this->composerJsonFile = File::fromPath(\sprintf(
'%s/composer.json',
$directory->path(),
Expand Down

0 comments on commit 78a85f2

Please sign in to comment.