Fix Return Type Mismatches¶
Priority: 🟡 P2 - MEDIUM Status: Planning Related Analysis: phpstan-rector-analysis-overview.md
Problem Statement¶
10 PHPStan errors for return type mismatches - where declared return type doesn't match actual returned value.
Impact¶
- Bug Risk: Medium - could indicate logic errors
- Type Safety: Functions returning unexpected types
- May Hide Bugs: Mismatches often reveal hidden issues
PHPStan Error Category¶
- Error ID:
return.type - Count: 10
- Priority: Medium - could reveal bugs
Investigation Required¶
Each mismatch needs investigation:
- Is the return type wrong?
- Is the implementation wrong?
- Is there a logic bug?
- Is PHPStan inference incorrect?
Implementation Plan¶
Step 1: Get Complete List¶
Step 2: Categorize Issues¶
For each mismatch:
- Declared return type
- Actual return type
- Location of return statement
- Context
Step 3: Fix Strategies¶
Strategy A: Fix Return Type
// Before
public function getId(): string
{
return $this->id; // returns int
}
// After
public function getId(): int
{
return $this->id;
}
Strategy B: Fix Implementation
// Before
public function getName(): string
{
return null; // wrong!
}
// After
public function getName(): string
{
return $this->name ?? '';
}
Strategy C: Make Nullable
// Before
public function getOptional(): string
{
return $this->optional; // can be null
}
// After
public function getOptional(): ?string
{
return $this->optional;
}
Success Criteria¶
- All return type mismatches resolved
- No logic bugs introduced
- Return types accurately reflect behavior
Risk Assessment¶
Medium Risk:
- May reveal actual bugs
- Changing return types can affect callers
- May require nullable types
Mitigation:
- Analyze all call sites
- Add tests for edge cases
- Review carefully
Estimated Effort¶
Per Mismatch:
- Investigation: 15-30 min
- Fix: 15-30 min
- Testing: 15-30 min
- Average: 1 hour per mismatch
Total for 10 mismatches:
- Estimate: 8-12 hours
Notes¶
Needs complete list to be specific. May reveal interesting bugs!