klesun / deep-assoc-completion

A phpstorm plugin for associative array key typing and completion
Other
266 stars 17 forks source link

FQCN as a key for argumentsSet does not work as expected #195

Open mialex opened 2 years ago

mialex commented 2 years ago

Hi.

I faced an issue when I need to use the FQCN of my classes as a key for argumentsSet. When it is defined with FQCN in the way \Worker\Fixtures\UserFixture::class it does not work as expected, as in this case it takes all possible arguments, regardless of the key. Once it's set up as a string '\Worker\Fixtures\UserFixture' it works ex expected. It would be great if it's possible to use class constant instead fo the string. Here are examples of the source code

.phpstorm.meta.php

<?php

namespace PHPSTORM_META {

    use Worker\Fixtures;

    function fixture_data_set(array $attributes = []) {
        return [
            'attributes' => $attributes,
        ];
    }

    function fixture_set() {
        return [
            Fixtures\UserFixture::class => \PHPSTORM_META\fixture_data_set([
                'firstName' => '',
                'lastName' => '',
            ]),
            Fixtures\DeviceFixture::class => \PHPSTORM_META\fixture_data_set([
                'deviceStatusId' => '',
                'externalId' => '',
            ]),
        ];
    }

    registerArgumentsSet('fixturesSet', ...\PHPSTORM_META\fixture_set());

    expectedArguments(\Worker\Provider::add(), 0, argumentsSet('fixturesSet'));
}

worker.php

<?php

namespace Worker\Fixtures {
    class UserFixture {
        // accept some data
    }

    class DeviceFixture {
        // accept some data
    }
}

namespace Worker {
    class Provider
    {
        public function add(array $data) {
            return $this;
        }
    }
}

namespace {
    use Worker\Fixtures;

    $provider = new \Worker\Provider();
    $provider
        ->add([
            Fixtures\UserFixture::class => [
                'attributes' => [
                    '', // get 4 unexpected fields (`firstName`, `lastName`, `deviceStatusId`, `externalId`)
                ]
            ]
        ])
    ;
}

In my example, if you try to add a new attribute, you will get the list of all 4 available attributes in the suggestion list (firstName, lastName, deviceStatusId, externalId) and it's not expected, as I need to see only 2 (firstName, lastName) by the key, which is Worker\Fixtures\UserFixture::class. If I change it to be simple string, it works as expected and I get the list of 2 expected elements (firstName, lastName). See the shortened samples of code with the string keys below:

<?php

namespace PHPSTORM_META {

    // same as above

    function fixture_set() {
        return [
            'Fixtures\UserFixture' => \PHPSTORM_META\fixture_data_set([
                'firstName' => '',
                'lastName' => '',
            ]),
            'Fixtures\DeviceFixture' => \PHPSTORM_META\fixture_data_set([
                'deviceStatusId' => '',
                'externalId' => '',
            ]),
        ];
    }

    // same as above
}

worker.php


// same as above

namespace {

    $provider = new \Worker\Provider();
    $provider
        ->add([
            'Fixtures\UserFixture'' => [
                'attributes' => [
                    '', // get 2 expected fields (`firstName`, `lastName`)
                ]
            ]
        ])
    ;
}
mialex commented 2 years ago

Are there any updates?

klesun commented 2 years ago

Hi. Sadly no, need a PR.