pbyrne84 / DynamicReturnTypePlugin

135 stars 7 forks source link

Feature Request - Autocompletion on string literals #38

Closed srosato closed 9 years ago

srosato commented 9 years ago

I wonder, would it be possible to use your same config structure in order to get fully qualified class names auto-completion on string literals?

Your plugin has already saved my life in order to stop type hinting when creating mocks, for example:

//from
use Mockery as m;

/* @var $mappingBuilderMock DataMapping|m\MockInterface */
$dataMappingMock = m::mock('Ez\Util\Data\Mapping\DataMapping');
$dataMappingMock ->shouldReceive('create')->once()->andReturn($map);

//to
$dataMappingMock = m::mock('Ez\Util\Data\Mapping\DataMapping');
$dataMappingMock ->shouldReceive('create')->once()->andReturn($map);

But I wonder if we could use the same configuration to provide autocompletion on the string literal, for example

{
  "methodCalls": [
    {
      "class" : "\\Mockery",
      "method": "mock",
      "position": 0,
      "autocomplete": true,
      "mask": "%s|\\Mockery\\MockInterface"
    }
  ]
}

Which would make it possible to autocomplete the fully qualified class name for mocks:

//would popup suggestion for classes, suggesting Ez\Util\Data\Mapping\DataMapping
$dataMappingMock = m::mock('Ez\ PRESS CTRL ENTER HERE');
srosato commented 9 years ago

In fact, I thought about it and your current config structure could very much help with other auto-completion use cases such as auto-completion on method names with string literals:

$dataProcessorMock = m::mock('Ez\Util\Data\Processor\DataProcessor');
$dataProcessorMock->shouldReceive('process')->once();

In this situation we would get auto-completion on shouldReceive('PRESS CTRL ENTER HERE');

srosato commented 9 years ago

Any update on this?

Danack commented 9 years ago

Wouldn't it be better just to stop using string literals for class names?

PHP have class name literals since PHP5.5. e.g. Ez\Util\Data\Processor\DataProcessor::class

Adding a feature that is only needed on versions of PHP that are in the end-of-support sequence seems....bad?

srosato commented 9 years ago

Oh wow. Ok I was unaware of that feature. I guess that is what happens when you are stuck on legacy systems.. I'm stuck on PHP5.3 and 5.4 on most of my projects for the production servers. I just tested with 5.5 and it really kills the need to implement such feature.

I am closing this issue, thanks for the advice and I will definitely be refactoring as soon as I am able to update.

pbyrne84 commented 9 years ago

Excellent, Thanks Dan :)