Skip to content
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 @@ -88,13 +88,13 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
// already known type
if ($node->returnType instanceof Node) {
return null;
}

// already known type
if ($node->returnType instanceof Node) {
$scope = ScopeFetcher::fetch($node);
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -120,11 +125,6 @@ public function provideMinPhpVersion(): int
*/
private function shouldSkip(Node $node, Scope $scope): bool
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return true;
}

return $node instanceof ClassMethod
&& $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -114,11 +119,6 @@ public function provideMinPhpVersion(): int
*/
private function shouldSkip(Node $node, Scope $scope): bool
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return true;
}

return $node instanceof ClassMethod
&& $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -120,11 +125,6 @@ public function provideMinPhpVersion(): int
*/
private function shouldSkip(Node $node, Scope $scope): bool
{
// already has the type, skip
if ($node->returnType instanceof Node) {
return true;
}

return $node instanceof ClassMethod
&& $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// type is already known, skip
if ($node->returnType instanceof Node) {
return null;
}

// empty, nothing to find
if ($node->stmts === null || $node->stmts === []) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -130,16 +140,6 @@ public function provideMinPhpVersion(): int

private function shouldSkip(ClassMethod|Function_ $functionLike, Scope $scope): bool
{
// type is already known, skip
if ($functionLike->returnType instanceof Node) {
return true;
}

// empty, nothing to find
if ($functionLike->stmts === null || $functionLike->stmts === []) {
return true;
}

if (! $functionLike instanceof ClassMethod) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// type is already known, skip
if ($node->returnType instanceof Node) {
return null;
}

// empty, nothing to find
if ($node->stmts === null || $node->stmts === []) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -123,16 +133,6 @@ public function provideMinPhpVersion(): int

private function shouldSkip(ClassMethod|Function_ $functionLike, Scope $scope): bool
{
// type is already known, skip
if ($functionLike->returnType instanceof Node) {
return true;
}

// empty, nothing to find
if ($functionLike->stmts === null || $functionLike->stmts === []) {
return true;
}

if (! $functionLike instanceof ClassMethod) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function provideMinPhpVersion(): int
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// empty body, nothing to resolve
if ($node->stmts === null || $node->stmts === []) {
return null;
Expand All @@ -96,6 +95,7 @@ public function refactor(Node $node): ?Node
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
$node,
$scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// type is already known
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if (! $this->isInsideTestCaseClass($scope)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// already has return type, skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
$node,
$scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// already filled
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
$node,
$scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
$returns = $this->betterNodeFinder->findReturnsScoped($node);
if (! $this->returnAnalyzer->hasOnlyReturnWithExpr($node, $returns)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public function provideMinPhpVersion(): int
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// already typed → skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->returnType instanceof Node) {
return null;
}

// private methods are handled by PrivateMethodReturnTypeFromStrictNewArrayRector
if ($node instanceof ClassMethod && $node->isPrivate()) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand All @@ -88,15 +97,6 @@ public function provideMinPhpVersion(): int

private function shouldSkip(ClassMethod|Function_ $node, Scope $scope): bool
{
if ($node->returnType instanceof Node) {
return true;
}

// private methods are handled by PrivateMethodReturnTypeFromStrictNewArrayRector
if ($node instanceof ClassMethod && $node->isPrivate()) {
return true;
}

return $node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
$node,
$scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function provideMinPhpVersion(): int
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
// already filled → skip
if ($node->returnType instanceof Node) {
return null;
Expand All @@ -116,6 +115,7 @@ public function refactor(Node $node): ?Node
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// type is already filled, skip
if ($node->returnType instanceof Node) {
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($this->shouldSkip($node, $scope)) {
return null;
Expand Down Expand Up @@ -133,11 +138,6 @@ public function provideMinPhpVersion(): int

private function shouldSkip(ClassMethod|Function_ $functionLike, Scope $scope): bool
{
// type is already filled, skip
if ($functionLike->returnType instanceof Node) {
return true;
}

$returnType = $this->returnTypeInferer->inferFunctionLike($functionLike);
$returnType = TypeCombinator::removeNull($returnType);
if ($returnType instanceof UnionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);

$yieldNodes = $this->yieldNodeFinder->find($node);
if ($yieldNodes === []) {
return null;
Expand All @@ -90,6 +88,7 @@ public function refactor(Node $node): ?Node
return null;
}

$scope = ScopeFetcher::fetch($node);
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod(
$node,
$scope
Expand Down
Loading