CodeIgniter Forums
PHPStorm yellow "Method not found in" notices - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: PHPStorm yellow "Method not found in" notices (/showthread.php?tid=76084)



PHPStorm yellow "Method not found in" notices - Leo - 04-13-2020

Does anyone use PHPStorm? How do I fix the annoying method not found warnings\errors when using singleton instance of class across functions in controller?

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\ProductsModel;

class 
Products extends BaseController
{
    protected $model;

    public function product_filters()
    {
        $this->model = new ProductsModel();
        $this->model->setTable('filters');
        $this->data['filters'] = $this->model->findAll();
////////////find all is lit up, declaration can be found

        if(isset($_POST)) {
            if (isset($_POST['add'])) {
                $this->new_filter();
            }
            return redirect()->to(current_url('products/product_filters'));
        }

        echo view('admin'$this->data);
        return null;
    }

    private function new_filter()
    {
        $name trim_and_filter('name');
        //check for existing, if no then insert
        if(!$this->model->where('name'$name)->first()) {
//////////here i keep getting yellow error method not found - but it works fine! How to fix this?? Its so annoying.
            $this->model->save(['name' => $name]);
        }
    }





RE: PHPStorm yellow "Method not found in" notices - cyberstunts - 04-13-2020

I don't have the solution but can suggest clicking on the small "man in the hat" icon at the bottom right. There you can configure code inspection.

I do have plugin installed "CodeIgniter" by Martynas Sateika. (Press CTRL+ALT+S > Plugins).

Don't have resolution problems, and didn't have to configure them.

Also in settings you could go to "Languages & Frameowrks > PHP > CodeIgniter" and tick checkbox "Enable CodeIgniter Integration".


RE: PHPStorm yellow "Method not found in" notices - Leo - 04-14-2020

The codeigniter plugin didn't help. I figured it out after digging the internet for a while - heres to any other newb, like me, looking.
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\MediaModel;

class 
Media extends BaseController
{
    /* @var $model MediaModel */
    protected $model;

    public function doSomething()
    {
        $this->model = new MediaModel();
        $this->model->setTable('table');
        
$stuff $this->doSomethingElse();
    }
    
    
private function doSomethingElse()
    {
        return $this->model->findAll(); //NO MORE TEARS! PHPSTORM FINDS THE METHOD
    }



So basically do this:
/* @var $model MediaModel */
protected $model;


RE: PHPStorm yellow "Method not found in" notices - atsanna - 04-14-2020

(04-14-2020, 04:43 AM)Leo Wrote: The codeigniter plugin didn't help. I figured it out after digging the internet for a while - heres to any other newb, like me, looking.
PHP Code:
<?php namespace App\Controllers;

use 
App\Models\MediaModel;

class 
Media extends BaseController
{
    /* @var $model MediaModel */
    protected $model;

    public function doSomething()
    {
        $this->model = new MediaModel();
        $this->model->setTable('table');
        $stuff $this->doSomethingElse();
    }
    
    
private function doSomethingElse()
    {
        return $this->model->findAll(); //NO MORE TEARS! PHPSTORM FINDS THE METHOD
    }



So basically do this:
/* @var $model MediaModel */
protected $model;

The plugin supports Codeigniter 3. For CodeIgniter 4 you can use this method:
Copy the attached file to the app folder: this should enable automatic completion in PhpStorm
The file is an experiment and is not complete.
I hope it is useful.