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

Support no-seal-properties/no-seal-methods on classes to avoid emitting UndefinedMagicMethod #2588

Closed
TysonAndre opened this issue Jan 10, 2020 · 6 comments
Labels
easy problems Issues that can be fixed without background knowledge of Psalm

Comments

@TysonAndre
Copy link
Contributor

Some use cases, such as test frameworks, may rely on supporting unknown magic methods, while still having a few of their own magic methods.

It'd be useful if those classes could indicate psalm shouldn't emit UndefinedMagicMethod for any of their use cases.

@psalm-no-seal-methods would be one way to do this. (or @no-seal-methods

https://github.com/ifwe/phockito/blob/bd1849468daf9539e052a3af9d11d981008397a8/Phockito.php#L617-L626 is one example of this - it supports both of the following syntaxes for the returned value of Phockito::when(...) (return() has a known type, someMethod() doesn't).

Phockito::when($mockObj)->someMethod()->return($value);
Phockito::when($mockObj->someMethod())->return($value);
@psalm-github-bot
Copy link

Hey @TysonAndre, can you reproduce the issue on https://psalm.dev ?

@muglug muglug added the easy problems Issues that can be fixed without background knowledge of Psalm label Apr 26, 2020
@jarstelfox
Copy link
Contributor

jarstelfox commented Aug 7, 2020

This just came up for us using Faker

Faker allows for a plugin-based approach by:

Note: The library has @method annotations to define the behaviour of the "built-in" plugins

Due to df33405 this third party library is becoming sealed, which means psalm complains about the methods defined in any plugins.

We cannot unseal the library without editing the source. If I remove the @method annotations psalm no longer complains

@edudobay
Copy link

I have the same problem with queue-interop, or specifically amqp-interop. In the base Context, createMessage returns a Message, but AmqpContext narrows the return type to AmqpMessage using a @method annotation. Psalm doesn't take that into account and I need to add a @var annotation if I need AmqpMessage-specific methods.

Are those kinds of overrides by design not meant to work with Psalm?

PHPStorm on the other hand honors the @method annotation and complains that the @var specifies the type that is already inferred. (The obvious fix is to use @psalm-var.)

use Interop\Amqp\AmqpContext;
use Interop\Amqp\AmqpMessage;

function sendMessage(AmqpContext $context, string $body, string $routingKey) {
    /** @var AmqpMessage $amqpMessage */
    $amqpMessage = $this->context->createMessage($body);
    $amqpMessage->setRoutingKey($routingKey);
    // ...
}

@rzvc
Copy link

rzvc commented May 23, 2022

I would also need a @no-seal-properties annotation, for when sealAllProperties is true, but you still have a class with magic properties that should not be sealed (I guess this goes for methods too).

@robchett
Copy link
Contributor

robchett commented Nov 3, 2023

This can be closed now.

@weirdan
Copy link
Collaborator

weirdan commented Feb 10, 2024

Fixed in #9681

@weirdan weirdan closed this as completed Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm
Projects
None yet
Development

No branches or pull requests

7 participants