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

[SPEED-990] Fix Covariance Return Type bug with objects #87

Merged
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
4 changes: 4 additions & 0 deletions src/Checks/InterfaceCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ private function assertParentChildReturnTypesMatch(
private function getReturnTypesForMethod(MethodInterface $method) {
$returnTypes = [];
TypeComparer::forEachType($method->getComplexReturnType(), function($type) use (&$returnTypes) {
if ($type instanceof Node\Name) {
$type = TypeComparer::identifierFromName($type->toCodeString());
}

$returnTypes[] = $type;
});
$returnTypes = array_column($returnTypes, 'name');
Expand Down
9 changes: 9 additions & 0 deletions tests/units/Checks/TestData/TestInterfaceCheck.9.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php


class dataObject {
public $test;
}
interface parentClass {
public function method1(): bool;
public function method2(): mixed;
Expand All @@ -9,7 +13,9 @@ interface parentClass {
public function method6(): string|int|null;
public function method7(): ?int;
public function method8(): string|int|null;
public function method9() : ?dataObject;
}

class childClass implements parentClass {
/** This should not work because int is different than bool */
public function method1(): int {
Expand Down Expand Up @@ -37,4 +43,7 @@ class childClass implements parentClass {
public function method8(): ?bool {
return null;
}
public function method9(): dataObject {
return new dataObject();
}
}