Welcome Guest, Not a member yet? Register   Sign In
CURLRequest getBody problem
#1

Hi everyone,
I'm using CURLRequest service, and I saw in documentation that I can use the getBody method.

I used that method, it worked, but it always shows an error on my VSCode, did any of you guys have this problem?

Here's my code:
PHP Code:
    private function getCountryCode() {
        if (array_key_exists('HTTP_CF_IPCOUNTRY'$_SERVER) && !in_array($_SERVER['HTTP_CF_IPCOUNTRY'], ['XX''T1'])) {
            return $_SERVER['HTTP_CF_IPCOUNTRY'];
        } else {
            $request = \Config\Services::curlrequest();

            $info json_decode($request->get('http://ip-api.com/json/' $this->request->getIPAddress())->getBody());

            if (isset($info->status) && $info->status == 'success') {
                return $info->countryCode;
            } else {
                return 'XX';
            }
        }
    

And here's the error that appears:
Undefined method 'getBody'. intelephense(1013)
Kind regards
Reply
#2

I'm having the same behaviour on my VSCode.

Code:
Undefined method 'getBody'.

Checking further I found this response on the VSCode Output Panel.


Code:
[{
"resource": "/c:/laragon/www/ci4dc/app/Controllers/MyLibraries.php",
"owner": "_generated_diagnostic_collection_name_#1",
"code": "1013",
"severity": 8,
"message": "Undefined method 'getBody'.",
"source": "intelephense",
"startLineNumber": 19,
"startColumn": 20,
"endLineNumber": 19,
"endColumn": 27
}]

The getBody() method works anyway while testing so seems to me like the problem is not on the Framework.
If someone can figure this out has to be somebody that knows better about VSCode or more especifically the intelephense extension.

Although in previous versions of the Framework this was sorted out by Adding to the BaseController.php:

use CodeIgniter\HTTP\IncomingRequest;

In the current version (CI 4.2.1 as I'm writing) this is something that was added by default on the BaseController so this was not supposed to be happening.

Anyway I found out this two references but modifying the core files of the framework its not the way to go (imho).

1. Modifying the main framework controller (Youtube Video)
2. Modifying the BaseController (Stack Overflow thread)

If only the notification is what is anoying you then one thing that you can do (if is not important to you) is disable the inteliphense extension of VSCode for the Workspace.
Machines obbey the software instructions, software instructions obbeys the logic of the developer.
Therefore is not the systems fault if the developer's logic is fudged up!  ¯\_(ツ)_/¯
Reply




Theme © iAndrew 2016 - Forum software by © MyBB