Skip to content

Add PHPStan stub for ResponseFactory::image() macro#28

Open
k1rana wants to merge 1 commit intoIntervention:developfrom
k1rana:phpstan-observation
Open

Add PHPStan stub for ResponseFactory::image() macro#28
k1rana wants to merge 1 commit intoIntervention:developfrom
k1rana:phpstan-observation

Conversation

@k1rana
Copy link

@k1rana k1rana commented Mar 9, 2026

Summary

Resolves #24

Larastan reports Call to an undefined method Illuminate\Contracts\Routing\ResponseFactory::image() because the image() macro is registered at runtime via ServiceProvider::boot(), which static analysis tools cannot detect.

This PR adds a PHPStan stub and extension config so PHPStan/Larastan recognizes the image() method on ResponseFactory

Changes

  • stubs/ResponseFactory.stub — Declares image() via @method PHPDoc on Illuminate\Contracts\Routing\ResponseFactory, matching the macro signature in ServiceProvider.php
  • extension.neon— Registers the stub with PHPStan
  • composer.json — Added extra.phpstan.includes for auto-discovery (zero user config needed)

Verification

vendor/bin/phpstan analyse fixture.php -c extension.neon --level=max
// fixture.php
<?php

use Illuminate\Contracts\Routing\ResponseFactory;
use Intervention\Image\Image;

function test(ResponseFactory $factory, Image $image): void
{
    $factory->image($image);
    $factory->image($image, 'webp');
    $factory->image($image, null, quality: 80);
}

Expected Result

Screenshot_2026-03-09_10-27-50

Adds a PHPStan stub file and extension.neon to resolve Larastan
reporting 'Call to an undefined method' for the image() response
macro registered at runtime by the ServiceProvider.

Fixes Intervention#24
Copy link
Member

@olivervogel olivervogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I wonder if this could be solved more easily with a hint in a comment without having to go through phpstan. I also have a few questions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this file is very ambiguous. Could you make it more clear, that this file belongs to phpstan?

"Image": "Intervention\\Image\\Laravel\\Facades\\Image"
}
},
"phpstan": {
Copy link
Member

@olivervogel olivervogel Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this will cause problems, since phpstan is part of the dependencies. Also: Where is phpstan defined in the composer.json schema? I can't find anything about it. It's included in extra, I missed that.

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.

Call to undefined method detected by Larastan

2 participants