Skip to content

Commit

Permalink
Applied doctrine/coding-standar:^10 ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Aug 29, 2022
1 parent 5c1a565 commit 13cec01
Show file tree
Hide file tree
Showing 180 changed files with 742 additions and 1,058 deletions.
126 changes: 63 additions & 63 deletions bin/roave-backward-compatibility-check.php

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private function __construct(
private string $modificationType,
public string $description,
private bool $isBcBreak,
public ?string $file = null,
public ?int $line = null,
public ?int $column = null
public string|null $file = null,
public int|null $line = null,
public int|null $column = null,
) {
}

Expand Down Expand Up @@ -73,9 +73,9 @@ public function isSkipped(): bool

/** @internal */
public function withFilePositionsIfNotAlreadySet(
?string $file,
string|null $file,
int $line,
?int $column
int|null $column,
): self {
$instance = clone $this;

Expand All @@ -86,7 +86,7 @@ public function withFilePositionsIfNotAlreadySet(
return $instance;
}

public function onFile(?string $file): self
public function onFile(string|null $file): self
{
$instance = clone $this;

Expand All @@ -104,7 +104,7 @@ public function onLine(int $line): self
return $instance;
}

public function onColumn(?int $column): self
public function onColumn(int|null $column): self
{
$instance = clone $this;

Expand All @@ -119,7 +119,7 @@ public function __toString(): string
'%s%s: %s',
$this->isBcBreak ? '[BC] ' : ' ',
Str\uppercase($this->modificationType),
$this->description
$this->description,
);
}
}
12 changes: 3 additions & 9 deletions src/Changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@

use function array_values;

/**
* @implements IteratorAggregate<int, Change>
*/
/** @implements IteratorAggregate<int, Change> */
final class Changes implements IteratorAggregate, Countable
{
/** @var list<Change> */
private array $bufferedChanges;

/** @var iterable<int, Change>|null */
private ?iterable $unBufferedChanges = null;
private iterable|null $unBufferedChanges = null;

/** @param list<Change> $bufferedChanges */
private function __construct(array $bufferedChanges)
private function __construct(private array $bufferedChanges)
{
$this->bufferedChanges = $bufferedChanges;
}

public static function empty(): self
Expand Down
42 changes: 17 additions & 25 deletions src/Command/AssertBackwardsCompatible.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@

final class AssertBackwardsCompatible extends Command
{
/**
* @throws LogicException
*/
/** @throws LogicException */
public function __construct(
private PerformCheckoutOfRevision $git,
private ComposerInstallationReflectorFactory $makeComposerInstallationReflector,
private ParseRevision $parseRevision,
private GetVersionCollection $getVersions,
private PickVersionFromVersionCollection $pickFromVersion,
private LocateDependencies $locateDependencies,
private CompareApi $compareApi
private CompareApi $compareApi,
) {
parent::__construct();
}

/**
* @throws InvalidArgumentException
*/
/** @throws InvalidArgumentException */
protected function configure(): void
{
$this
Expand All @@ -60,27 +56,27 @@ protected function configure(): void
'from',
null,
InputOption::VALUE_OPTIONAL,
'Git reference for the base version of the library, which is considered "stable"'
'Git reference for the base version of the library, which is considered "stable"',
)
->addOption(
'to',
null,
InputOption::VALUE_REQUIRED,
'Git reference for the new version of the library, which is verified against "from" for BC breaks',
'HEAD'
'HEAD',
)
->addOption(
'format',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Currently supports "console", "markdown" or "github-actions"',
['console']
['console'],
)
->addOption(
'install-development-dependencies',
null,
InputOption::VALUE_NONE,
'Whether to also install "require-dev" dependencies too'
'Whether to also install "require-dev" dependencies too',
)
->addUsage(
<<<'USAGE'
Expand All @@ -104,13 +100,11 @@ protected function configure(): void
If you want to produce `STDOUT` output, then please use the
`--format` flag.
USAGE
USAGE,
);
}

/**
* @throws InvalidArgumentException
*/
/** @throws InvalidArgumentException */
public function execute(InputInterface $input, OutputInterface $output): int
{
$output = Type\object(ConsoleOutputInterface::class)->assert($output);
Expand All @@ -132,7 +126,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$stdErr->writeln(Str\format(
'Comparing from %s to %s...',
Type\string()->coerce($fromRevision),
Type\string()->coerce($toRevision)
Type\string()->coerce($toRevision),
));

$fromPath = $this->git->checkout($sourceRepo, $fromRevision);
Expand All @@ -142,16 +136,16 @@ public function execute(InputInterface $input, OutputInterface $output): int
$changes = ($this->compareApi)(
($this->makeComposerInstallationReflector)(
$fromPath->__toString(),
new AggregateSourceLocator() // no dependencies
new AggregateSourceLocator(), // no dependencies
),
($this->makeComposerInstallationReflector)(
$fromPath->__toString(),
($this->locateDependencies)($fromPath->__toString(), $includeDevelopmentDependencies)
($this->locateDependencies)($fromPath->__toString(), $includeDevelopmentDependencies),
),
($this->makeComposerInstallationReflector)(
$toPath->__toString(),
($this->locateDependencies)($toPath->__toString(), $includeDevelopmentDependencies)
)
($this->locateDependencies)($toPath->__toString(), $includeDevelopmentDependencies),
),
);

$formatters = [
Expand Down Expand Up @@ -190,9 +184,7 @@ private function printOutcomeAndExit(Changes $changes, OutputInterface $stdErr):
return $hasBcBreaks ? 3 : 0;
}

/**
* @throws InvalidArgumentException
*/
/** @throws InvalidArgumentException */
private function parseRevisionFromInput(InputInterface $input, CheckedOutRepository $repository): Revision
{
$from = Type\string()->coerce($input->getOption('from'));
Expand All @@ -202,7 +194,7 @@ private function parseRevisionFromInput(InputInterface $input, CheckedOutReposit

private function determineFromRevisionFromRepository(
CheckedOutRepository $repository,
OutputInterface $output
OutputInterface $output,
): Revision {
$versions = $this->getVersions->fromRepository($repository);

Expand All @@ -214,7 +206,7 @@ private function determineFromRevisionFromRepository(

return $this->parseRevision->fromStringForRepository(
$versionString,
$repository
$repository,
);
}
}
2 changes: 1 addition & 1 deletion src/CompareApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ interface CompareApi
public function __invoke(
Reflector $definedSymbols,
Reflector $pastSourcesWithDependencies,
Reflector $newSourcesWithDependencies
Reflector $newSourcesWithDependencies,
): Changes;
}
27 changes: 9 additions & 18 deletions src/CompareClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,34 @@

final class CompareClasses implements CompareApi
{
private ClassBased $classBasedComparisons;

private InterfaceBased $interfaceBasedComparisons;

private TraitBased $traitBasedComparisons;

public function __construct(
ClassBased $classBasedComparisons,
InterfaceBased $interfaceBasedComparisons,
TraitBased $traitBasedComparisons
private ClassBased $classBasedComparisons,
private InterfaceBased $interfaceBasedComparisons,
private TraitBased $traitBasedComparisons,
) {
$this->classBasedComparisons = $classBasedComparisons;
$this->interfaceBasedComparisons = $interfaceBasedComparisons;
$this->traitBasedComparisons = $traitBasedComparisons;
}

public function __invoke(
Reflector $definedSymbols,
Reflector $pastSourcesWithDependencies,
Reflector $newSourcesWithDependencies
Reflector $newSourcesWithDependencies,
): Changes {
$definedApiClassNames = Dict\map(
Dict\filter(
$definedSymbols->reflectAllClasses(),
function (ReflectionClass $class): bool {
return ! ($class->isAnonymous() || $this->isInternalDocComment($class->getDocComment()));
}
},
),
static function (ReflectionClass $class): string {
return $class->getName();
}
},
);

return Changes::fromIterator($this->makeSymbolsIterator(
$definedApiClassNames,
$pastSourcesWithDependencies,
$newSourcesWithDependencies
$newSourcesWithDependencies,
));
}

Expand All @@ -64,7 +55,7 @@ static function (ReflectionClass $class): string {
private function makeSymbolsIterator(
array $definedApiClassNames,
Reflector $pastSourcesWithDependencies,
Reflector $newSourcesWithDependencies
Reflector $newSourcesWithDependencies,
): iterable {
foreach ($definedApiClassNames as $apiClassName) {
$oldSymbol = $pastSourcesWithDependencies->reflectClass($apiClassName);
Expand All @@ -76,7 +67,7 @@ private function makeSymbolsIterator(
/** @return iterable<int, Change> */
private function examineSymbol(
ReflectionClass $oldSymbol,
Reflector $newSourcesWithDependencies
Reflector $newSourcesWithDependencies,
): iterable {
try {
$newClass = $newSourcesWithDependencies->reflectClass($oldSymbol->getName());
Expand Down
6 changes: 3 additions & 3 deletions src/DetectChanges/BCBreak/ClassBased/AncestorRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
{
$removedAncestors = Vec\concat(
Vec\values(Dict\diff($fromClass->getParentClassNames(), $toClass->getParentClassNames())),
Vec\values(Dict\diff($fromClass->getInterfaceNames(), $toClass->getInterfaceNames()))
Vec\values(Dict\diff($fromClass->getInterfaceNames(), $toClass->getInterfaceNames())),
);

if (! $removedAncestors) {
Expand All @@ -33,8 +33,8 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
Str\format(
'These ancestors of %s have been removed: %s',
$fromClass->getName(),
Json\encode($removedAncestors)
)
Json\encode($removedAncestors),
),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
}

return Changes::fromList(Change::changed(
Str\format('Class %s became abstract', $fromClass->getName())
Str\format('Class %s became abstract', $fromClass->getName()),
));
}
}
2 changes: 1 addition & 1 deletion src/DetectChanges/BCBreak/ClassBased/ClassBecameFinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
}

return Changes::fromList(Change::changed(
Str\format('Class %s became final', $fromClass->getName())
Str\format('Class %s became final', $fromClass->getName()),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
}

return Changes::fromList(Change::changed(
Str\format('Class %s became an interface', $fromClass->getName())
Str\format('Class %s became an interface', $fromClass->getName()),
));
}
}
4 changes: 2 additions & 2 deletions src/DetectChanges/BCBreak/ClassBased/ClassBecameInternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
return Changes::fromList(Change::changed(
Str\format(
'%s was marked "@internal"',
$fromClass->getName()
)
$fromClass->getName(),
),
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/DetectChanges/BCBreak/ClassBased/ClassBecameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
}

return Changes::fromList(Change::changed(
Str\format('Class %s became a trait', $fromClass->getName())
Str\format('Class %s became a trait', $fromClass->getName()),
));
}
}
7 changes: 2 additions & 5 deletions src/DetectChanges/BCBreak/ClassBased/ConstantChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@

final class ConstantChanged implements ClassBased
{
private ClassConstantBased $checkConstant;

public function __construct(ClassConstantBased $checkConstant)
public function __construct(private ClassConstantBased $checkConstant)
{
$this->checkConstant = $checkConstant;
}

public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass): Changes
{
return Changes::fromIterator($this->checkSymbols(
$fromClass->getReflectionConstants(),
$toClass->getReflectionConstants()
$toClass->getReflectionConstants(),
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/DetectChanges/BCBreak/ClassBased/ConstantRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass):
{
$removedConstants = Dict\diff_by_key(
$this->accessibleConstants($fromClass),
$this->accessibleConstants($toClass)
$this->accessibleConstants($toClass),
);

return Changes::fromList(...Vec\map($removedConstants, static function (ReflectionClassConstant $constant) use ($fromClass): Change {
return Change::removed(
Str\format('Constant %s::%s was removed', $fromClass->getName(), $constant->getName())
Str\format('Constant %s::%s was removed', $fromClass->getName(), $constant->getName()),
);
}));
}
Expand Down
Loading

0 comments on commit 13cec01

Please sign in to comment.