Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#24 rename package to roave/backward-compatibility-check #50

Merged
merged 21 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
96586a9
#24 renamed package to `roave/backward-compatibility-check`
Ocramius Apr 27, 2018
e119e62
#24 renamed `Roave\ApiCompare\Comparator\BackwardsCompatibility` to `…
Ocramius Apr 27, 2018
62eeb33
#24 renamed all `compare()` methods on all BC break detectors to just…
Ocramius Apr 27, 2018
4ead51c
#24 renamed `Changes::new()` to `Changes::empty()`
Ocramius Apr 27, 2018
2bca1ac
#24 minor performance optimisation: if `Changes#mergeWith()` is merge…
Ocramius Apr 27, 2018
ecd9ed9
#24 removed `Changes#withAddedChange()`, as `mergeWith` is the prefer…
Ocramius Apr 27, 2018
b416323
#24 renamed `Changes::fromArray()` in favour of `Changes::fromList()`…
Ocramius Apr 27, 2018
d59ee07
#24 avoid greedy usage of `array_merge()` where a splat operator woul…
Ocramius Apr 27, 2018
4c4ba88
#24 performance/memory optimisation: avoid trashing memory with `Chan…
Ocramius Apr 27, 2018
692de1d
#24 corrected `exclude-pattern` entries in the phpcs config (forgot a…
Ocramius Apr 27, 2018
9c0053b
#24 verifying that `Changes#mergeWith()` avoids copy-on-write when an…
Ocramius Apr 27, 2018
ef30d0b
#24 changed command name and description
Ocramius Apr 27, 2018
fb19272
#24 renamed command class to match command name
Ocramius Apr 27, 2018
9e897d1
#24 using `1` as exit code for failed checks - exit code `2` is reser…
Ocramius Apr 27, 2018
ba589c2
#24 renamed package from `Roave\ApiCompare` to `Roave\BackwardCompati…
Ocramius Apr 27, 2018
c7f98d8
#24 added binary to composer binary paths
Ocramius Apr 27, 2018
4f95a2c
#24 added BC verification to the travis build
Ocramius Apr 27, 2018
2dcfd7f
#24 added a success/failure message at the end of the execution of th…
Ocramius Apr 27, 2018
e539096
#24 improved CLI command documentation by dcumenting all options
Ocramius Apr 27, 2018
2c8fe42
#24 moved most docs to the CLI command itself: `--help` is our friend!
Ocramius Apr 27, 2018
ea02a5d
#24 using exit code `3` instead of `1` for when BC breaks are detected
Ocramius Apr 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#24 renamed Changes::fromArray() in favour of Changes::fromList()
…, which is type-safe
  • Loading branch information
Ocramius committed Apr 27, 2018
commit b4163236428ddeef585c8b0018d2b30b95a48b44
11 changes: 4 additions & 7 deletions src/Changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ public static function empty() : self
return new self();
}

/**
* @param Change[] $changes
* @return Changes
*/
public static function fromArray(array $changes) : self
public static function fromList(Change ...$changes) : self
{
Assert::that($changes)->all()->isInstanceOf(Change::class);
$instance = self::empty();
$instance = new self();

$instance->changes = $changes;

return $instance;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private function examineSymbol(
/** @var ReflectionClass $newClass */
$newClass = $newSourcesWithDependencies->reflect($oldSymbol->getName());
} catch (IdentifierNotFound $exception) {
return $changelog->mergeWith(Changes::fromArray([
return $changelog->mergeWith(Changes::fromList(
Change::removed(sprintf('Class %s has been deleted', $oldSymbol->getName()), true)
]));
));
}

if ($oldSymbol->isInterface()) {
Expand Down
5 changes: 2 additions & 3 deletions src/DetectChanges/BCBreak/ClassBased/ClassBecameAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Class %s became abstract', $fromClass->getName()),
true
),
]);
));
}
}
5 changes: 2 additions & 3 deletions src/DetectChanges/BCBreak/ClassBased/ClassBecameFinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Class %s became final', $fromClass->getName()),
true
),
]);
));
}
}
5 changes: 2 additions & 3 deletions src/DetectChanges/BCBreak/ClassBased/ClassBecameInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Class %s became an interface', $fromClass->getName()),
true
),
]);
));
}
}
5 changes: 2 additions & 3 deletions src/DetectChanges/BCBreak/ClassBased/ClassBecameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Class %s became a trait', $fromClass->getName()),
true
),
]);
));
}
}
2 changes: 1 addition & 1 deletion src/DetectChanges/BCBreak/ClassBased/ConstantRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
$this->accessibleConstants($toClass)
);

return Changes::fromArray(array_values(array_map(function (ReflectionClassConstant $constant) use ($fromClass) : Change {
return Changes::fromList(...array_values(array_map(function (ReflectionClassConstant $constant) use ($fromClass) : Change {
return Change::removed(
sprintf('Constant %s::%s was removed', $fromClass->getName(), $constant->getName()),
true
Expand Down
2 changes: 1 addition & 1 deletion src/DetectChanges/BCBreak/ClassBased/MethodRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
array_change_key_case($this->accessibleMethods($toClass), CASE_UPPER)
);

return Changes::fromArray(array_values(array_map(function (ReflectionMethod $method) : Change {
return Changes::fromList(...array_values(array_map(function (ReflectionMethod $method) : Change {
return Change::removed(
sprintf('Method %s was removed', $this->formatFunction->__invoke($method)),
true
Expand Down
2 changes: 1 addition & 1 deletion src/DetectChanges/BCBreak/ClassBased/PropertyRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
array_keys($this->accessibleProperties($toClass))
);

return Changes::fromArray(array_values(array_map(function (string $property) use ($fromProperties) : Change {
return Changes::fromList(...array_values(array_map(function (string $property) use ($fromProperties) : Change {
return Change::removed(
sprintf('Property %s was removed', $this->formatProperty->__invoke($fromProperties[$property])),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ public function __invoke(ReflectionClassConstant $fromConstant, ReflectionClassC
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'Value of constant %s::%s changed from %s to %s',
$fromConstant->getDeclaringClass()->getName(),
$fromConstant->getName(),
var_export($fromValue, true),
var_export($toValue, true)
),
true
return Changes::fromList(Change::changed(
sprintf(
'Value of constant %s::%s changed from %s to %s',
$fromConstant->getDeclaringClass()->getName(),
$fromConstant->getName(),
var_export($fromValue, true),
var_export($toValue, true)
),
]);
true
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __invoke(ReflectionClassConstant $fromConstant, ReflectionClassC
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf(
'Constant %s::%s visibility reduced from %s to %s',
$fromConstant->getDeclaringClass()->getName(),
Expand All @@ -36,8 +36,7 @@ public function __invoke(ReflectionClassConstant $fromConstant, ReflectionClassC
$visibilityTo
),
true
),
]);
));
}

private function propertyVisibility(ReflectionClassConstant $property) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ private function compareParameter(ReflectionParameter $fromParameter, Reflection
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$this->referenceToString($fromByReference),
$this->referenceToString($toByReference)
),
true
return Changes::fromList(Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$this->referenceToString($fromByReference),
$this->referenceToString($toByReference)
),
]);
true
));
}

private function referenceToString(bool $reference) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@ public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFun
continue;
}

$changes = $changes->mergeWith(Changes::fromArray([
Change::changed(
sprintf(
'Default parameter value for for parameter $%s of %s changed from %s to %s',
$parameter->getName(),
$this->formatFunction->__invoke($fromFunction),
var_export($defaultValueFrom, true),
var_export($defaultValueTo, true)
),
true
$changes = $changes->mergeWith(Changes::fromList(Change::changed(
sprintf(
'Default parameter value for for parameter $%s of %s changed from %s to %s',
$parameter->getName(),
$this->formatFunction->__invoke($fromFunction),
var_export($defaultValueFrom, true),
var_export($defaultValueTo, true)
),
]));
true
)));
}

return $changes;
Expand Down
20 changes: 9 additions & 11 deletions src/DetectChanges/BCBreak/FunctionBased/ParameterTypeChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ private function compareParameter(ReflectionParameter $fromParameter, Reflection
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$fromType,
$toType
),
true
return Changes::fromList(Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$fromType,
$toType
),
]);
true
));
}

private function typeToString(?ReflectionType $type) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ private function compareParameter(ReflectionParameter $fromParameter, Reflection
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to a non-contravariant %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$this->typeToString($fromType),
$this->typeToString($toType)
),
true
return Changes::fromList(Change::changed(
sprintf(
'The parameter $%s of %s changed from %s to a non-contravariant %s',
$fromParameter->getName(),
$this->formatFunction->__invoke($fromParameter->getDeclaringFunction()),
$this->typeToString($fromType),
$this->typeToString($toType)
),
]);
true
));
}

private function typeToString(?ReflectionType $type) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFun
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The number of required arguments for %s increased from %d to %d',
$this->formatFunction->__invoke($fromFunction),
$fromRequiredParameters,
$toRequiredParameters
),
true
return Changes::fromList(Change::changed(
sprintf(
'The number of required arguments for %s increased from %d to %d',
$this->formatFunction->__invoke($fromFunction),
$fromRequiredParameters,
$toRequiredParameters
),
]);
true
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFun
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The return value of %s changed from %s to %s',
$this->formatFunction->__invoke($fromFunction),
$this->referenceToString($fromReturnsReference),
$this->referenceToString($toReturnsReference)
),
true
return Changes::fromList(Change::changed(
sprintf(
'The return value of %s changed from %s to %s',
$this->formatFunction->__invoke($fromFunction),
$this->referenceToString($fromReturnsReference),
$this->referenceToString($toReturnsReference)
),
]);
true
));
}

private function referenceToString(bool $reference) : string
Expand Down
18 changes: 8 additions & 10 deletions src/DetectChanges/BCBreak/FunctionBased/ReturnTypeChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFun
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The return type of %s changed from %s to %s',
$this->formatFunction->__invoke($fromFunction),
$fromReturnType,
$toReturnType
),
true
return Changes::fromList(Change::changed(
sprintf(
'The return type of %s changed from %s to %s',
$this->formatFunction->__invoke($fromFunction),
$fromReturnType,
$toReturnType
),
]);
true
));
}

private function typeToString(?ReflectionType $type) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFun
return Changes::empty();
}

return Changes::fromArray([
Change::changed(
sprintf(
'The return type of %s changed from %s to the non-covariant %s',
$this->formatFunction->__invoke($fromFunction),
$this->typeToString($fromReturnType),
$this->typeToString($toReturnType)
),
true
return Changes::fromList(Change::changed(
sprintf(
'The return type of %s changed from %s to the non-covariant %s',
$this->formatFunction->__invoke($fromFunction),
$this->typeToString($fromReturnType),
$this->typeToString($toReturnType)
),
]);
true
));
}

private function typeToString(?ReflectionType $type) : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Interface %s became a class', $fromClass->getName()),
true
),
]);
));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) :
return Changes::empty();
}

return Changes::fromArray([Change::changed(
return Changes::fromList(Change::changed(
sprintf('Interface %s became a trait', $fromClass->getName()),
true
),
]);
));
}
}
Loading