kotfire/vscode-php-add-property

Problems when using anonymous classes

Closed this issue · 1 comments

If an anonymous class is used like this, no property is added:

<?php

namespace Blah;

class TraitUsageResolver
{
    /**
     * @var string
     */
    private $prop1;

    

    public function foo()
    {
        return new class {
            public function __construct()
            {
                
            }  
        };
    }
}

There is also an additional issue, where the property is added to the anonymous class instead of the main class. This happens in e.g. this situation:

<?php

namespace Blah;

class TraitUsageResolver
{
    /**
     * @var string
     */
    private $prop1;

    

    public function foo()
    {
        return new class {
            /**
             * @var string
             */
            private $prop2;

        };
    }
}

Fixed in 0.4.1