PhpStorm 2017.2 code inspections & Laravel

Hi!

The upgrade to 2017.2 introduced few new problems:

- Laravel Model::find(), Model::create() etc. inspections suddenly alert "Non-static method ... should not be called statically";

- Markdown (.md) files preview does not work when JavaFX WebView is selected in the configuration.

 

Can anyone please advise?

Thank you!

14 comments
Comment actions Permalink

Hello,

1. Please provide a complete code sample so the issue could be reproduced.

2. JavaFX still works fine for me. What OS do you run? Is the plugin up to date?

0
Comment actions Permalink

Hello!

Here's the simple example where both lines are marked by the inspection and it says "Non-static method 'find' should not be called statically".

public function create()
{
$userDefaults = cfg_get_prefix('users');

return view('users.create', [
'country' => Country::find($userDefaults['users.default_country']);
'currency' => Currency::find($userDefaults['users.default_currency']);
]);
}

I use Linux Mint.

#cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=18.1
DISTRIB_CODENAME=serena
DISTRIB_DESCRIPTION="Linux Mint 18.1 Serena"


Plugins are up to date, I did update everything immediately after the upgrade, as suggested by the notification.

 

0
Comment actions Permalink

I've just noticed another issue - a keyboard shortcut Ctrl-Shift-N (to open an existing file in editor) does not move the focus to the input field for filename search, but stays in the currently active editor tab, so I continue messing up my code. I need to click on the search input to be able to enter the text there.

1
Comment actions Permalink

Yes, all PHP parent classes that have fields declared in them that are used by their children are now reporting that the child use of the field is dynamically declared.  Wasn't happening in the previous version (and shouldn't happen in this version). I've submitted a support request (the email I received contains links back to my support request and all those links lead to 404 errors; logging into my account shows that I've submitted no support requests; not pretty).

 This reproduces the error:

class parent_class
{
protected $field;
}

class child_class extends parent_class
{
public function __construct()
{
$this->field = 'Use of field in child.';
}
}
0
Comment actions Permalink

This does look like it might be a bug in PhpStorm...

The "Non-static method 'find' should not be called statically" inspection error is being caused by a change to the Laravel Model class introduced in 5.4.29: https://github.com/laravel/framework/commit/77d8c23fed764e6a38cc8608c28f0ad7c39deee4 adding a new @mixin comment to the base Model class.

If you remove that @mixin from the Laravel Model class, things return to 'normal', but only because of a "@mixin \Eloquent" comment added by ide_helper to all Eloquent models. Adding this @mixin to the parent model fixes the problem, but this change was rejected because I assume it was too specific to PhpStorm/ide_helper: https://github.com/laravel/framework/pull/20044

There's a related issue here: https://github.com/barryvdh/laravel-ide-helper/issues/541 but I think it's probably a PhpStorm problem.

This seems to be a case of PhpStorm picking up the"@mixin \Eloquent" comment on the abstract parent class, but not when it's added to the instances of that class. It may be that the instance @mixins are overwritten by the parent @mixins rather than added to them?

It looks like there a couple of related bug reports:

Allow Inspections to Recognize Non-Static Methods Called as Static as Valid

Methods from @mixin do not override parent methods

And this fix in 2017.2:

Property/constants are not shown in completion list for @mixin

 

1
Comment actions Permalink

Thank you very much, @Jon Phipps, this solves it! :) 

0
Comment actions Permalink

Thank you so much @Jon Phipps this really saved me from tearing my hair out at this annoying behavior in my projects!

0
Comment actions Permalink

I have the same problem that Kootsoop. Any news on that?

0
Comment actions Permalink

"Fixed, should be available in next EAP"

With PhpStorm 2017.2.3 Build #PS-172.4155.25, built on September 5, 2017 the problem is the same.

 
0
Comment actions Permalink

@Sergey, could you provide a code sample where this can be reproduced for you in 2017.2.3? I cannot reproduce it there.

0
Comment actions Permalink

@Vladimir Luchansky 

Laravel Framework 5.5.3

Laravel IDE Helper v2.4.1

PhpStorm 2017.2.3 Build #PS-172.4155.25.

 

If we are using model static methods:

\App\Models\SomeModel::find($id);

We have a tooltip: 'Non-static method 'find' should not be called statically'

This problem more described in issue https://github.com/barryvdh/laravel-ide-helper/issues/541

 

0
Comment actions Permalink

The only reason I use PHPStorm is because it helped me so much with laravel programming, but now I have the same problem as you guys, and now phpstorm for me is like any other code editor !

It doesn't even read the ide Helper that I generated from https://github.com/barryvdh/laravel-ide-helper , I tried adding the Laravel-plugin , Laravel insight from  the plugins reposetory in phpstorm preferences too, but that didn't help me at all !

0

Please sign in to leave a comment.