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

PHPStan level 9 progress #155

Merged
merged 21 commits into from
Jun 27, 2023
Merged

PHPStan level 9 progress #155

merged 21 commits into from
Jun 27, 2023

Conversation

spaze
Copy link
Owner

@spaze spaze commented Jun 27, 2023

From 84 errors down to 25.

For #147

spaze added 21 commits June 24, 2023 14:23
Resolves these errors:
```
 ------ -------------------------------------------------
  Line   app/Www/Presenters/ErrorPresenter.php
 ------ -------------------------------------------------
  76     Cannot call method getParameter() on mixed.
  76     Cannot call method getPresenterName() on mixed.
  91     Cannot call method getParameters() on mixed.
 ------ -------------------------------------------------
```
Resolves these errors:
```
 ------ -------------------------------------------
  Line   app/Www/Presenters/BaseErrorPresenter.php
 ------ -------------------------------------------
  58     Cannot call method getCode() on mixed.
  58     Cannot call method getFile() on mixed.
  58     Cannot call method getLine() on mixed.
  58     Cannot call method getMessage() on mixed.
 ------ -------------------------------------------
```
…st what's needed at the moment

Resolves these errors:
```
 ------ ------------------------------------------------------------------------------------------------------------------
  Line   app/Tls/CertificateFactory.php
 ------ ------------------------------------------------------------------------------------------------------------------
  50     Cannot access offset 'commonName' on mixed.
  50     Parameter #1 $commonName of class MichalSpacekCz\Tls\Certificate constructor expects string, mixed given.
  52     Cannot cast mixed to string.
  53     Cannot cast mixed to string.
  55     Parameter #6 $serialNumber of class MichalSpacekCz\Tls\Certificate constructor expects string|null, mixed given.
 ------ ------------------------------------------------------------------------------------------------------------------
```
…ette\Schema

Resolves
```
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   app/Tls/CertificatesApiClient.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  69     Parameter #1 $details of method MichalSpacekCz\Tls\CertificateFactory::fromArray() expects array{commonName: string, commonNameExt: string|null, notBefore: string, notBeforeTz: string, notAfter: string, notAfterTz: string, expiringThreshold:
         int, serialNumber: string|null, ...}, mixed given.
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

```
This was easy, removes this:
```
 ------ ------------------------------------------------------------------------------------------------
  Line   app/Test/NoOpTranslator.php
 ------ ------------------------------------------------------------------------------------------------
  36     Method MichalSpacekCz\Test\NoOpTranslator::translate() should return string but returns mixed.
 ------ ------------------------------------------------------------------------------------------------
```
This is sort of a duplication of what's already defined in the schema but here we are. Solves these:
```
 ------ ----------------------------------------------------
  Line   app/Pulse/Passwords/AlgorithmAttributesFactory.php
 ------ ----------------------------------------------------
  37     Cannot access property $inner on mixed.
  37     Cannot access property $outer on mixed.
  37     Cannot access property $params on mixed.
 ------ ----------------------------------------------------
```
…the future

Right now, `Nette\Http\Request::getCookie()` returns mixed and would require we check for strings all the time
Currently, `$form->onValidate` and `$form->onSuccess` types for `$values` are specified as `mixed` and the type in the callbacks cannot be narrower as seen in errors like:

```
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   app/Form/TrainingApplicationAdminFormFactory.php
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  96     Property Nette\Forms\Form::$onSuccess (array<callable(Nette\Application\UI\Form, mixed): void>) does not accept non-empty-array<(callable(Nette\Application\UI\Form, mixed): void)|(Closure(Nette\Application\UI\Form, stdClass): void)>.
         💡 Type stdClass of parameter #2 $values of passed callable needs to be same or wider than parameter type mixed of accepting callable.
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
```
Resolves:
```
 ------ -----------------------------------------------------------------------
  Line   app/UpcKeys/Technicolor.php
 ------ -----------------------------------------------------------------------
  88     Parameter #2 $string of function explode expects string, mixed given.
 ------ -----------------------------------------------------------------------
```
This is kinda unrelated but I still like it.
Fix
```
 ------ ---------------------------------------------------------------
  Line   app/Test/Application/ApplicationPresenter.php
 ------ ---------------------------------------------------------------
  38     Parameter #2 $ of closure expects array<string>, array given.
 ------ ---------------------------------------------------------------
```
Fixes these errors:
```
 ------ --------------------------------------------------------------------------------------------
  Line   app/Training/Dates/TrainingDatesFormValidator.php
 ------ --------------------------------------------------------------------------------------------
  18     Parameter #1 $datetime of class DateTimeImmutable constructor expects string, mixed given.
  19     Parameter #1 $datetime of class DateTimeImmutable constructor expects string, mixed given.
 ------ --------------------------------------------------------------------------------------------
```
It was either PhpStorm complaining that the right part of `$slideNumber ?? ...` is useless, or PHPStan complaining that "Cannot access property $number on mixed." Or both.
Don't care if not because it's gonna be a string, trust me.
@spaze spaze self-assigned this Jun 27, 2023
@spaze spaze mentioned this pull request Jun 21, 2023
@spaze spaze merged commit 46fe51e into main Jun 27, 2023
@spaze spaze deleted the spaze/phpstan-level-9-progress branch June 27, 2023 18:35
spaze added a commit that referenced this pull request Jul 2, 2023
spaze added a commit that referenced this pull request Jul 2, 2023
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.

1 participant