Sorien / silex-idea-plugin

Idea plugin for Silex Framework - plugin is not compatible with PHPStorm 2016.2
MIT License
26 stars 8 forks source link

Array element type inference break #36

Closed bburnichon closed 8 years ago

bburnichon commented 8 years ago

Probably linked to #35. But easier to reproduce. I thought it was a phpstorm issue first.

https://youtrack.jetbrains.com/issue/WI-31170

/** @var int[] $array */
$array = [1, 2, 3];
$index = 0;

$myInt = $array[0];
$myOtherInt = $array[$index];

var_dump($myInt, $myOtherInt);

myint myotherint

Sorien commented 8 years ago

i'll try to look at it and publish new version that should contain fix for #35 as well

bburnichon commented 8 years ago

Another issue is the way typehints are interpreted in defining closures:

class MyContainer extends Pimple
{
}

class MyServiceProvider
{
    public function register(Pimple $container)
    {
        $container['foo'] = 'foo value';
        $container['bar'] = function (MyContainer $container) {
            return $container['foo'];
        };
        $container['baz'] = $container::share(function (MyContainer $container) {
            return $container['foo'];
        });
    }
}

$provider = new MyServiceProvider();
$container = new MyContainer();

$provider->register($container);

Type is not inferred for factories: image

Type is inferred to type calling Pimple::share() instead of defined in closure image

Sorien commented 8 years ago

pls could you try to install plugin based on master http://silex.sorien.sk/download/master and recheck

i've just found out that i need to setup whole build env :/

bburnichon commented 8 years ago

@Sorien I retested on the initial issue. There are no changes ($myOtherInt has no type hint). For the Silex Service Providers, both case are now type hinted as Pimple even though I explicitly type hinted as MyContainer

Sorien commented 8 years ago

@Haehnchen pls is there any way how PhpTypeProvider2.getBySignature can return simple (int) php element

when i call

        Collection<? extends PhpNamedElement> collection = phpIndex.getBySignature('#C\int', null, 0);
        return collection; 

it returns empty collection ... (it's causing bug in first example)

Haehnchen commented 8 years ago

you can add string values. hopefully this should also work with primitives types; just try to use int[]. doing same with class returns Foo[]

fr.adrienbrault.idea.symfony2plugin.doctrine.ObjectRepositoryResultTypeProvider#getBySignature
        String name = method.getName();
        if(name.equals("findAll") || name.equals("findBy")) {
            method.getType().add(phpClass.getFQN() + "[]");
            return phpNamedElementCollections;
        }
Sorien commented 8 years ago

@bburnichon first issue should be hopefully fixed at master (with tests) if you want to test it just download from http://silex.sorien.sk/download/master (this plugin build is autogenerated by Travis after each commit)

bburnichon commented 8 years ago

@Sorien I confirm that first issue is resolved.

Sorien commented 8 years ago

@bburnichon second issue should be fixed with last commit as well

bburnichon commented 8 years ago

@Sorien checked second issue is also fixed.

I checked #34 & #35 on my setup. Both issues are solved.

Great work!

Sorien commented 8 years ago

ok i'll wait few days in no other bugs are found i'll release new version