bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.64k stars 94 forks source link

CodeIgniter4 "Undefined method 'disableForeignKeyChecks'. intelephense(1013)" on defined method #2525

Closed Rasalas closed 1 year ago

Rasalas commented 1 year ago

Describe the bug VSCode shows "Undefined method 'disableForeignKeyChecks'. intelephense(1013)" on defined method inside a CodeIgniter4 Project even though the method is defined.

To Reproduce Use VSCode with intelephense installed. Create CodeIgniter4 Project:

composer create-project codeigniter4/appstarter example-project-folder
cd example-project-folder
php spark make:migration CreateTest

Go to example-project-folder/app/Database/Migrations/2023-02-26-234615_CreateTest.php and paste following code:

<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateTest extends Migration
{
    public function up()
    {
        $this->db->disableForeignKeyChecks(); // <- throws the error

        // START_IRRELEVANT - irrelevant but context
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'name' => [
                'type'    => 'BOOLEAN',
                'null'    => false,
                'default' => true
            ],
        ]);

        $this->forge->addPrimaryKey('id');

        $this->forge->createTable('test');
        // END_IRRELEVANT

        $this->db->enableForeignKeyChecks(); // <- throws the error
    }

    public function down()
    {
        $this->forge->dropTable('test');
    }
}

Not needed, but to "test" the file:

php spark migrate:rollback
php spark migrate

The methods enableForeignKeyChecks and disableForeignKeyChecks exists here: vendor/codeigniter4/framework/system/Database/BaseConnection.php

Expected behavior I expect Intelephense to find the method (vscode does) and not throw that 1013 error - the code runs perfectly fine. VSCode highlights the files red: "error in the file", which is annoying.

Screenshots The error:

image

VSCode finds everything and Intelephense doesn't seem to see a problem:

image image

The most annoying part:

image

Platform and version

bmewburn commented 1 year ago

Property $db has type ConnectionInterface which does not declare disableForeignKeyChecks. See https://github.com/bmewburn/vscode-intelephense/issues/2366#issuecomment-1344897859 on ways to resolve this.