Skip to content

Commit

Permalink
Fixed further nullability issues around ReflectionClass#getMethod()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Oct 10, 2022
1 parent 12b6aff commit 6ed452a
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BackwardCompatibility\Change;
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterDefaultValueChanged;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -17,6 +18,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterDefaultValueChanged */
Expand Down Expand Up @@ -131,16 +133,26 @@ function changed2($a = 2) {}
),
[
'C::changed1' => [
$fromReflector->reflectClass('C')->getMethod('changed1'),
$toReflector->reflectClass('C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('C'), 'changed1'),
self::getMethod($toReflector->reflectClass('C'), 'changed1'),
['[BC] CHANGED: Default parameter value for parameter $a of C::changed1() changed from 1 to 2'],
],
'C#changed2' => [
$fromReflector->reflectClass('C')->getMethod('changed2'),
$toReflector->reflectClass('C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('C'), 'changed2'),
self::getMethod($toReflector->reflectClass('C'), 'changed2'),
['[BC] CHANGED: Default parameter value for parameter $a of C#changed2() changed from 1 to 2'],
],
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BackwardCompatibility\Change;
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterTypeChanged;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -17,6 +18,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterTypeChanged */
Expand Down Expand Up @@ -166,17 +168,17 @@ function changed2(int $a, int $b) {}
),
[
'N4\C::changed1' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed1'),
$toReflector->reflectClass('N4\C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed1'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed1'),
[
'[BC] CHANGED: The parameter $a of N4\C::changed1() changed from no type to int',
'[BC] CHANGED: The parameter $b of N4\C::changed1() changed from no type to int',

],
],
'N4\C#changed2' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed2'),
$toReflector->reflectClass('N4\C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed2'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed2'),
[
'[BC] CHANGED: The parameter $a of N4\C#changed2() changed from no type to int',
'[BC] CHANGED: The parameter $b of N4\C#changed2() changed from no type to int',
Expand All @@ -185,4 +187,14 @@ function changed2(int $a, int $b) {}
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterTypeContravarianceChanged;
use Roave\BackwardCompatibility\DetectChanges\Variance\TypeIsContravariant;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -18,6 +19,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ParameterTypeContravarianceChanged */
Expand Down Expand Up @@ -167,17 +169,17 @@ function changed2(int $a, int $b) {}
),
[
'N4\C::changed1' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed1'),
$toReflector->reflectClass('N4\C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed1'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed1'),
[
'[BC] CHANGED: The parameter $a of N4\C::changed1() changed from no type to a non-contravariant int',
'[BC] CHANGED: The parameter $b of N4\C::changed1() changed from no type to a non-contravariant int',

],
],
'N4\C#changed2' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed2'),
$toReflector->reflectClass('N4\C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed2'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed2'),
[
'[BC] CHANGED: The parameter $a of N4\C#changed2() changed from no type to a non-contravariant int',
'[BC] CHANGED: The parameter $b of N4\C#changed2() changed from no type to a non-contravariant int',
Expand All @@ -186,4 +188,14 @@ function changed2(int $a, int $b) {}
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BackwardCompatibility\Change;
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\RequiredParameterAmountIncreased;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -17,6 +18,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\RequiredParameterAmountIncreased */
Expand Down Expand Up @@ -140,16 +142,26 @@ function changed2($a, $b, $c, $d) {}
),
[
'N1\C::changed1' => [
$fromReflector->reflectClass('N1\C')->getMethod('changed1'),
$toReflector->reflectClass('N1\C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('N1\C'), 'changed1'),
self::getMethod($toReflector->reflectClass('N1\C'), 'changed1'),
['[BC] CHANGED: The number of required arguments for N1\C::changed1() increased from 3 to 4'],
],
'N1\C#changed2' => [
$fromReflector->reflectClass('N1\C')->getMethod('changed2'),
$toReflector->reflectClass('N1\C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('N1\C'), 'changed2'),
self::getMethod($toReflector->reflectClass('N1\C'), 'changed2'),
['[BC] CHANGED: The number of required arguments for N1\C#changed2() increased from 3 to 4'],
],
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BackwardCompatibility\Change;
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ReturnTypeByReferenceChanged;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -17,6 +18,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ReturnTypeByReferenceChanged */
Expand Down Expand Up @@ -122,16 +124,26 @@ function & changed2() {}
),
[
'N1\C::changed1' => [
$fromReflector->reflectClass('N1\C')->getMethod('changed1'),
$toReflector->reflectClass('N1\C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('N1\C'), 'changed1'),
self::getMethod($toReflector->reflectClass('N1\C'), 'changed1'),
['[BC] CHANGED: The return value of N1\C::changed1() changed from by-value to by-reference'],
],
'N1\C#changed2' => [
$fromReflector->reflectClass('N1\C')->getMethod('changed2'),
$toReflector->reflectClass('N1\C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('N1\C'), 'changed2'),
self::getMethod($toReflector->reflectClass('N1\C'), 'changed2'),
['[BC] CHANGED: The return value of N1\C#changed2() changed from by-value to by-reference'],
],
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Roave\BackwardCompatibility\Change;
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ReturnTypeChanged;
use Roave\BetterReflection\BetterReflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
use Roave\BetterReflection\Reflector\DefaultReflector;
Expand All @@ -17,6 +18,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function assert;
use function iterator_to_array;

/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ReturnTypeChanged */
Expand Down Expand Up @@ -156,16 +158,26 @@ function changed2() {}
),
[
'N4\C::changed1' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed1'),
$toReflector->reflectClass('N4\C')->getMethod('changed1'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed1'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed1'),
['[BC] CHANGED: The return type of N4\C::changed1() changed from int to no type'],
],
'N4\C#changed2' => [
$fromReflector->reflectClass('N4\C')->getMethod('changed2'),
$toReflector->reflectClass('N4\C')->getMethod('changed2'),
self::getMethod($fromReflector->reflectClass('N4\C'), 'changed2'),
self::getMethod($toReflector->reflectClass('N4\C'), 'changed2'),
['[BC] CHANGED: The return type of N4\C#changed2() changed from int to no type'],
],
],
);
}

/** @param non-empty-string $name */
private static function getMethod(ReflectionClass $class, string $name): ReflectionMethod
{
$method = $class->getMethod($name);

assert($method !== null);

return $method;
}
}

0 comments on commit 6ed452a

Please sign in to comment.