for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased;
use Roave\ApiCompare\Change;
use Roave\ApiCompare\Changes;
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
use Roave\BetterReflection\Reflection\ReflectionMethod;
final class MethodVisibilityReduced implements MethodBased
{
private const VISIBILITY_PRIVATE = 'private';
private const VISIBILITY_PROTECTED = 'protected';
private const VISIBILITY_PUBLIC = 'public';
public function compare(ReflectionMethod $fromMethod, ReflectionMethod $toMethod) : Changes
$visibilityFrom = $this->methodVisibility($fromMethod);
$visibilityTo = $this->methodVisibility($toMethod);
if ($visibilityFrom <= $visibilityTo) {
return Changes::new();
}
return Changes::fromArray([Change::changed(
sprintf(
'Method %s() of class %s visibility reduced from %s to %s',
$fromMethod->getName(),
$fromMethod->getDeclaringClass()->getName(),
$visibilityFrom,
$visibilityTo
),
true
)]);
private function methodVisibility(ReflectionMethod $method) : string
if ($method->isPublic()) {
return self::VISIBILITY_PUBLIC;
if ($method->isProtected()) {
return self::VISIBILITY_PROTECTED;
return self::VISIBILITY_PRIVATE;