psalm / psalm-plugin-symfony

Psalm Plugin for Symfony
MIT License
229 stars 53 forks source link

use ContainerAwareTrait must supress PropertyNotSetInConstructor #141

Open Punk-UnDeaD opened 3 years ago

Punk-UnDeaD commented 3 years ago

hello we need something like this

<?php

declare(strict_types=1);

namespace App\Psalm;

use PhpParser\Node\Stmt\ClassLike;
use Psalm\Codebase;
use Psalm\FileSource;
use Psalm\Plugin\Hook\AfterClassLikeVisitInterface;
use Psalm\Storage\ClassLikeStorage;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class ContainerAwareTraitHandler implements AfterClassLikeVisitInterface
{
    public static function afterClassLikeVisit(
        ClassLike $stmt,
        ClassLikeStorage $storage,
        FileSource $statements_source,
        Codebase $codebase,
        array &$file_replacements = []
    ) {
        if (ContainerAwareTrait::class === $storage->name) {
            $storage->initialized_properties['container'] = true;
        }
    }
}
seferov commented 3 years ago

hi @Punk-UnDeaD,

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