stefanzweifel,
@stefanzweifel@phpc.social avatar

While making my PHP packages compatible with Laravel 11 the last few weeks, I've also spent some time and added PHPStan to all of them.

The more simpler ones are already on level 9. The more complex are still on level 5 or 6. I'm still a novice when it comes to proper type documentation. Goal is to increase levels throughout the year.

Links to all packages:
https://stefanzweifel.dev/projects

#php #phpstan

regis,
@regis@phpc.social avatar

@stefanzweifel I’ve tried the level max on my projects and it’s just impossible.
I think even a default Laravel app doesn’t pass it.

mitelg,
@mitelg@phpc.social avatar

@regis @stefanzweifel tip: use the baseline feature! this ensures that new added code has the desired level 🙂👍

stefanzweifel,
@stefanzweifel@phpc.social avatar

@regis yeah, max is basically impossible to fulfill in Laravel apps. In packages it’s manageable. A couple of doc blocks are usually enough.

thgs,
@thgs@phpc.social avatar

@stefanzweifel @regis what makes it hard to go max level in Laravel? I haven’t written any code related to laravel since version 5 but I wasn’t doing psalm/phpstan back then.

I usually try to go max and anything less is just “temporary” these days.

stefanzweifel,
@stefanzweifel@phpc.social avatar

@thgs @regis The problem is Laravel's magic.
Tools like Larastan or the laravel-ide-helper can help here.

The core problem is that for example in this User model, there are no $name or $email properties, but one can use $user->name = ‘Foo’;
https://github.com/laravel/laravel/blob/11.x/app/Models/User.php

As mentioned, I’m a novice when it comes to phpstan and currently don't see the need to go to level 9 in my projects.
My app code these days are often strictly typed PHP classes "outside" of Laravel anyway.

thgs,
@thgs@phpc.social avatar

@stefanzweifel @regis yea I see, I was just curious about what is the obstacle. Also way more competent with psalm than phpstan myself, magic properties are still possible but you would need to define a lot of psalm types. I think more or less the same for phpstan too.

It’s quite a bit of difference in the code in level 5 and then level 3 and then level 1 (reverse these for phpstan).

I tend to like the way you need to write the code in the max level because it ends up being guided a lot.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • ethstaker
  • DreamBathrooms
  • everett
  • magazineikmin
  • Durango
  • InstantRegret
  • rosin
  • Youngstown
  • love
  • slotface
  • GTA5RPClips
  • kavyap
  • mdbf
  • ngwrru68w68
  • megavids
  • thenastyranch
  • tacticalgear
  • cubers
  • modclub
  • osvaldo12
  • cisconetworking
  • tester
  • khanakhh
  • normalnudes
  • provamag3
  • anitta
  • Leos
  • JUstTest
  • All magazines