Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment PHPStan to strictness level 2 #1488

Merged
merged 10 commits into from
Apr 27, 2023

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Apr 27, 2023

PHPStan has "rule levels" https://phpstan.org/user-guide/rule-levels that determine which sorts of type errors they detect. I was surprised to discover we were on rule level 1. This PR adds type fixes and error suppressions to get us to rule level 2.

Almost everything is docstring-only changes, with the exception of

Fix unsafe static:: references. PHPStan doesn't like static:: references to private methods. I'm not 100% sure why but I think it's because

<?php
class Foo {
    private static function abc(){
        return "hello";
    }
    public static function xyz() {
        return static::abc();
    }
}
class Bar extends Foo {
    private static function abc() {
        return "world";
    }
}
print Bar::xyz();

will result in an error like

Fatal error: Uncaught Error: Call to private method Bar::abc() from scope Foo 

In any case, doing self:: instead makes it so that the private method defined in the parent class is always called, and prevents subclasses from re-implementing it, which I think is what is intended, anyway.

@richardm-stripe richardm-stripe requested review from a team and anniel-stripe and removed request for a team April 27, 2023 19:52
lib/Account.php Show resolved Hide resolved
lib/Account.php Show resolved Hide resolved
lib/Service/AbstractService.php Show resolved Hide resolved
lib/Service/AbstractService.php Show resolved Hide resolved
lib/Service/AbstractService.php Show resolved Hide resolved
@richardm-stripe richardm-stripe merged commit f176a54 into master Apr 27, 2023
22 checks passed
@richardm-stripe richardm-stripe deleted the richardm-phpstan-stricter branch May 1, 2023 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants