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

Hard to get symbol in some issues for plugins #8886

Closed
jack-worman opened this issue Dec 11, 2022 · 4 comments
Closed

Hard to get symbol in some issues for plugins #8886

jack-worman opened this issue Dec 11, 2022 · 4 comments
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement Help wanted plugins

Comments

@jack-worman
Copy link
Contributor

I am trying to write a plugin that will suppress UnusedProperty if it is a doctrine column. But I am struggling to retrieve the symbol (class name and property name) to do the reflection to achieve this.

My code would looks something like this:

<?php

declare(strict_types=1);

namespace App\Psalm\Hook;

use Psalm\Issue\UnusedProperty;
use Psalm\Plugin\EventHandler\BeforeAddIssueInterface;
use Psalm\Plugin\EventHandler\Event\BeforeAddIssueEvent;

class DoctrinePropertySuppressUnusedHook implements BeforeAddIssueInterface
{
    public static function beforeAddIssue(BeforeAddIssueEvent $event): ?bool
    {
        $codeIssue = $event->getIssue();
        if ($codeIssue instanceof UnusedProperty) {
            // $class = ...
            // $property = ...
            // TODO: Use reflection to test for ORM attributes
        }
        return null;
    }
}

Is there a better way to do this?
Or should fully qualified symbol names be added to issues?

@psalm-github-bot
Copy link

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

@orklah
Copy link
Collaborator

orklah commented Dec 11, 2022

Seems like UnusedProperty doesn't inherit PropertyIssue:

final class UnusedProperty extends CodeIssue

If it was, you'd be able to retrieve the property_id:

public $property_id;

You could PR that change if you want

@orklah orklah added enhancement easy problems Issues that can be fixed without background knowledge of Psalm plugins Help wanted labels Dec 11, 2022
@jack-worman
Copy link
Contributor Author

This was already done by @weirdan in another issue. :)

@weirdan
Copy link
Collaborator

weirdan commented Dec 12, 2022

Yep, in #8883

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 enhancement Help wanted plugins
Projects
None yet
Development

No branches or pull requests

3 participants