Skip to content

[TypeDeclarations] Add return try/catch fail rule #8646

@TomasVotruba

Description

@TomasVotruba

I've run Rector on one legacy project and noticed the type declaration set missed a try/catch case.

It's pretty straight forward so we should hook into 1st-level TryCatch node:

-public function some()
+public function some(): int
{
    try {
        return 100;
    } catch (Exception $exception) {
        // some logging
        throw $exception;
    }
}

It should handle any returns of known native value, e.g.:

return 100 + 5;

// or
return $this->getInteger();

// ...

public function getInteger()
{
     return 100;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions