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

Add testsand implementation for property types changing from docblock-only to native type #340

Merged
merged 3 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Roave\BackwardCompatibility\Formatter\ReflectionPropertyName;
use Roave\BetterReflection\Reflection\ReflectionProperty;

use function array_merge;

/**
* Type declarations for properties are invariant: you can't restrict the type because the consumer may
* write invalid values to it, and you cannot widen the type because the consumer may expect a specific
Expand All @@ -27,12 +29,18 @@ public function __construct()

public function __invoke(ReflectionProperty $fromProperty, ReflectionProperty $toProperty): Changes
{
$toNativeType = [];
$toType = $toProperty->getType();
if ($toType !== null) {
$toNativeType[] = $toType->getName();
}

if ($fromProperty->getDocComment() === '') {
return Changes::empty();
}

$fromTypes = Vec\sort($fromProperty->getDocBlockTypeStrings());
$toTypes = Vec\sort($toProperty->getDocBlockTypeStrings());
$toTypes = Vec\sort(array_merge($toNativeType, $toProperty->getDocBlockTypeStrings()));

if ($fromTypes === $toTypes) {
return Changes::empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ class TheClass {
* @var GenericType<T1, T2>
*/
public $propertyWithComplexDocblockThatCannotBeParsed;

/**
* @var int
tomasnorre marked this conversation as resolved.
Show resolved Hide resolved
*/
public $propertyWithDocblockTypeHintChangeToNativeTypeHint;

/**
* @var int
*/
public $propertyWithDocblockTypeHintChangeToNativeTypeHintAndTypeChange;
}
PHP
,
Expand Down Expand Up @@ -182,6 +192,10 @@ class TheClass {
* @var GenericType<T1, T2>
*/
public $propertyWithComplexDocblockThatCannotBeParsed;

public int $propertyWithDocblockTypeHintChangeToNativeTypeHint;

public float $propertyWithDocblockTypeHintChangeToNativeTypeHintAndTypeChange;
}
PHP
,
Expand All @@ -207,6 +221,8 @@ class TheClass {
'duplicatePropertyTypesBeingDeduplicatedAreNotBcBreaks' => [],
'propertyTypeBeingDuplicatedAreNotBcBreaks' => [],
'propertyWithComplexDocblockThatCannotBeParsed' => [],
'propertyWithDocblockTypeHintChangeToNativeTypeHint' => [],
'propertyWithDocblockTypeHintChangeToNativeTypeHintAndTypeChange' => ['[BC] CHANGED: Type documentation for property TheClass#$propertyWithDocblockTypeHintChangeToNativeTypeHintAndTypeChange changed from int to float'],
];

return array_combine(
Expand Down