Skip to content

VS Code complains about getPost as unknown method using ResponseTrait #9650

@Turecky

Description

@Turecky

PHP Version

8.2

CodeIgniter4 Version

4.6.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

When use first Example Usage from https://codeigniter.com/user_guide/outgoing/api_responses.html
VS Code complains about Call to unknown method: CodeIgniter\HTTP\RequestInterface::getPost() at line:

$user  = $model->save($this->request->getPost());

When remove use ResponseTrait; then property $this->request changes
from: \CodeIgniter\HTTP\RequestInterface $request
to: \CodeIgniter\HTTP\CLIRequest|\CodeIgniter\HTTP\IncomingRequest

At runtime it works correctly only annoying VS Code highlights.

Steps to Reproduce

In test controller:

<?php

namespace App\Controllers;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;

class Users extends Controller
{
    use ResponseTrait;

    public function createUser()
    {
        $model = new UserModel();
        /**
        VS code popup on `$this->request`
        CodeIgniter\API\ResponseTrait::$request

        <?php
        public $request;
        @var \CodeIgniter\HTTP\RequestInterface $request
        */
        $user  = $model->save($this->request->getPost());

        // Respond with 201 status code
        return $this->respondCreated();
    }
}

Expected Output

Do no complain about unknow method getPost and is

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions