Skip to content

Add PHPStan at level 6 for static analysis #21

@francescobianco

Description

@francescobianco

Problem

The codebase currently has no static analysis. Some methods return mixed without strict typing enforcement, which hides potential bugs.

For example in src/OauthClient.php:

private function request(string $method, string $url, ?array $body = null): string
{
    // $response could be false on curl failure — currently not typed strictly
    $response = curl_exec($ch);
    ...
}

Running phpstan analyse src/ --level=6 already reports issues like:

 ------ -------------------------------------------------------
  Line   src/OauthClient.php
 ------ -------------------------------------------------------
  78     Variable $ch might not be defined.
  83     Parameter #1 $ch of function curl_setopt expects resource, CurlHandle|false given.
 ------ -------------------------------------------------------

Proposal

  • Add phpstan/phpstan to require-dev
  • Add a phpstan.neon config targeting level 6
  • Add a composer run analyse script

Open questions

  • Level 6 or level 8? Level 8 requires full generics annotation which may be too strict for now.
  • Should PHPStan run in CI on every PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions