shahriar_shaon's avatar

PHPStan Level 9 is killing me with DTOs — please roast my code (GitHub link inside)

I’m extremely confused about my code structure and I’m hoping a senior developer can help me out.

My confusion: I’m using PHPStan at the maximum level, which means I have to write a lot of heavy annotations just to satisfy PHPStan. Also, I’ve never used DTOs before — this is my first project using them — so I’m not even sure if I’m following the correct approach.

What’s troubling me the most is that after validating the data, when I pass it into the DTO, PHPStan keeps giving warnings because of mixed values.

I’m sharing my project’s GitHub link below. If anyone kind-hearted could take a look at my code, point out where I’m going wrong, and guide me toward the proper way to structure things, I would really appreciate it.

github.com/shahriarshaon1993/myfinance

0 likes
6 replies
krisi_gjika's avatar

since you are using max level I really hope you are actually using larastan

shahriar_shaon's avatar

Yes, I am using larastan, but I’m extremely confused about my code structure. Will you help me? To review my code.

krisi_gjika's avatar

you have a lot of code there, can you give a specific example you are having trouble with?

shahriar_shaon's avatar

I'm confused about my code structure. Am I on the right track?

I need to know more. When I use PHPStan Max Level, do I have to use annotations in this way?


public function store(StoreUserRequest $request, CreateUser $action): RedirectResponse
    {
        Gate::authorize('create', User::class);

        /** @var array{name: string, email: string, phone: string, is_active: string, password: string|null, avatar: UploadedFile|null, avatar_removed: bool, roles: array<int>, permissions: array<int>} $data */
        $data = $request->validated();
shahriar_shaon's avatar

I actually gave the GitHub link first, but I wasn't getting a good response, so I'll post another one with the direct code.

Please or to participate in this conversation.