CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

VSCode intelephense finds `CLIRequest` instead of `IncomingRequest`

Open bunnyhu opened this issue 3 years ago • 5 comments

PHP Version

8.2

CodeIgniter4 Version

4.4.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

In Visual Studio Code got intelephense(1006) error when I try to use getPost() as string, because it is found the method from CodeIgniter\HTTP\CLIRequest::getPost that return only array or null. Are you sure that is correct? If i give an index even in CLI, why I get array?

The CodeIgniter\HTTP\IncomingRequest::getPost give a correct return type list, but unfortunately the intelliphense found the CLI first.

Steps to Reproduce

$json = json_decode($this->request->getPost('json'), true);

"Expected type 'string'. Found 'array|null'.intelephense(1006)"

Expected Output

@return array|bool|float|int|object|string|null

Anything else?

No response

bunnyhu avatar Sep 16 '23 18:09 bunnyhu

If i give an index even in CLI, why I get array?

If you give an index in CLI, you will get null. There is no $_POST data in CLI.

I don't know why your IDE find CodeIgniter\HTTP\CLIRequest.

kenjis avatar Sep 16 '23 21:09 kenjis

I don't know why your IDE find CodeIgniter\HTTP\CLIRequest.

It is common problem with intelephense: if it found more than one method, using only the first. The order is maybe ABC order ... I do know how many ppl using VSC but this is problem for all of us. I need to rewrite the CI core after every update ...

bunnyhu avatar Sep 16 '23 21:09 bunnyhu

Try to remove CLIRequest from: https://github.com/codeigniter4/CodeIgniter4/blob/689c93377b7125b5358a6093b2efecd132d20e70/app/Controllers/BaseController.php#L27

kenjis avatar Sep 16 '23 23:09 kenjis

I've seen it too. this is because of the BaseController. you can delete typehint if you don't run the controller in the console

neznaika0 avatar Sep 17 '23 03:09 neznaika0

Try to remove CLIRequest from:

https://github.com/codeigniter4/CodeIgniter4/blob/689c93377b7125b5358a6093b2efecd132d20e70/app/Controllers/BaseController.php#L27

Hey, You give me an idea and it is working. On the same line, change the order: * @var IncomingRequest|CLIRequest Or remove CLIRequest like you suggest. Thanks mate!

bunnyhu avatar Sep 17 '23 05:09 bunnyhu