[WIP] Fix PHPStan errors with systematic resolution plan #212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>PHPStan Error Analysis: 6349 Errors - Systematic Resolution Plan</issue_title>
<issue_description># PHPStan Error Analysis Report
Executive Summary
The PHPStan analysis of the codebase revealed a total of 6349 file errors. While this number appears high, a significant portion of these errors are related to missing type information and dynamic property access, which can be systematically addressed. There are also critical issues related to nullability and incorrect data types that pose a direct threat to the operational stability of the application. The new "enterprise transformation" features appear to contribute to these errors, indicating a need for more rigorous static analysis and typing within these modules.
Error Categorization and Impact
The errors can be broadly categorized as follows:
1. Missing Type Information (High Count, Medium Severity)
Examples:
App\Actions\Application\GenerateConfig::handle()has no return type specified. (Numerous occurrences, 574/574 files have errors related to this)App\Livewire\Project\Application\General::$parsedServiceswith generic classIlluminate\Support\Collectiondoes not specify its types: TKey, TValue (Numerous occurrences)Analysis: This category represents a large portion of the errors. While PHP itself might run without explicit type declarations, static analysis tools like PHPStan rely heavily on them for accurate checks. The lack of return type declarations, generic type specifications for collections, and un-typed properties lead to PHPStan being unable to fully verify code correctness.
Operational Impact:
2. Access to Undefined Properties (High Count, High Severity)
Examples:
App\Models\Server::$settings. (175 occurrences)App\Models\Application::$settings. (143 occurrences)App\Models\Organization::$activeLicense. (28 occurrences)Analysis: This is a critical category. It often arises when Eloquent models dynamically provide properties (e.g., through relationships) that are not explicitly declared in the class. Without
@propertyannotations or explicit property declarations, PHPStan cannot confirm their existence, leading to errors. This can also indicate actual typos or incorrect property access.Operational Impact:
3. Nullability Issues (Medium Count, High Severity)
Examples:
currentTeam()onApp\Models\User|null. (66 occurrences)Illuminate\Database\Eloquent\Model|null. (13 occurrences)Analysis: These errors occur when methods are called or operations are performed on variables that might be null, but the context expects a non-null value. This is a common source of TypeError or "Call to a member function on null" runtime exceptions.
Operational Impact:
4. Incorrect Type Usage / Type Mismatches (Medium Count, Medium Severity)
Examples:
OpenApi\Attributes\Schemaconstructor expectsarray<OpenApi\Attributes\Property>|null,array<string, array<string, string>>given. (66 occurrences)App\Models\Server::$port(int) does not accept string. (1 occurrence)Analysis: These indicate that a function or method is being called with arguments ...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.