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

#[Required] must supress PropertyNotSetInConstructor #140

Open
Punk-UnDeaD opened this issue Feb 9, 2021 · 1 comment
Open

#[Required] must supress PropertyNotSetInConstructor #140

Punk-UnDeaD opened this issue Feb 9, 2021 · 1 comment
Labels
feature New feature or request

Comments

@Punk-UnDeaD
Copy link
Contributor

Punk-UnDeaD commented Feb 9, 2021

Hello

we need something like this

<?php

declare(strict_types=1);

namespace App\Psalm;

use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use Psalm\Codebase;
use Psalm\FileSource;
use Psalm\Plugin\Hook\AfterClassLikeVisitInterface;
use Psalm\Storage\ClassLikeStorage;
use Symfony\Contracts\Service\Attribute\Required;

class RequiredPropertyHandler implements AfterClassLikeVisitInterface
{
    public static function afterClassLikeVisit(
        ClassLike $stmt,
        ClassLikeStorage $storage,
        FileSource $statements_source,
        Codebase $codebase,
        array &$file_replacements = []
    ) {
        if (!$stmt instanceof Class_) {
            return;
        }
        foreach ($storage->properties as $name => $property) {
            foreach ($property->attributes as $attribute) {
                if (Required::class === $attribute->fq_class_name) {
                    $storage->initialized_properties[$name] = true;
                    break;
                }
            }
        }
    }
}
@seferov
Copy link
Member

seferov commented Feb 11, 2021

hi @Punk-UnDeaD,

Thank you for the issue. The code seems valid. Can you please create a PR for it?

@seferov seferov added the feature New feature or request label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants