False positive on access to protected/private properties and methods in macros
Bug report
Using PHPStan 0.12.71.
I am using macros like the following, annotating $this as described in https://github.com/nunomaduro/larastan/issues/166:
use GuzzleHttp\Client;
\opencensus_trace_method(Client::class, 'send', function ($request, $options) {
/** @var Client $this */
return [
'name' => 'Guzzle\Client::send',
'attributes' => [
'uri' => $this->buildUri($request->getUri(), $options),
],
'kind' => Span::KIND_CLIENT,
];
});
This results in the following warning:
Call to private method buildUri() of class GuzzleHttp\Client.
It seems like PHPStan is unable to recognize that $this has access to protected and private fields and methods in this context. Is it possible to inform it that those fields and methods are available?
This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.
I've experienced the same when creating macro for Laravel's Eloquent Builder - when trying to reference any protected property or method I get the Call to protected method / property ....
Example would be:
Builder::macro('testingProtectedAccess',function () {
/** @var Builder $this */
return $this->model->getPerPage();
});