bmewburn / vscode-intelephense

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

Expected 2 Arguments, found 1 even though method has default values (and 4 arguments…) #753

Closed finn-matti closed 4 years ago

finn-matti commented 5 years ago

Describe the bug In one of our classes (which I don't mean to imply its an isolated case, just that I noticed it in one class) intelephense complains about a method being called with 1 argument, even though two were expected. BUT: The method in question has 4 args and three of those have a default.

To Reproduce

/**
     * List available email templates
     */
    public function actionTemplates()
    {
        return $this->sendRequest('email/templates');
    }

    /**
     * Send a request and display the response
     *
     * @param string $url the request URL
     * @param string $params optional the URL params to append with '?'.
     * @param string $type the request type. Default is 'GET'.
     * @param string[] $data the data to send
     * @return int the exit code to return
     */
    protected function sendRequest($url, $params = '', $type = 'GET', $data = [])
    {
        if (!empty($params)) {
            $url .= '?' . $params;
        }
        $emarsys = Yii::$app->emarsys;
        try {
            $response = $emarsys->send($url, $type, $data);
        } catch (Exception $e) {
            $this->stderr($e->getMessage() . "\n", Console::BOLD);
            return self::EXIT_CODE_ERROR;
        }
        $request = $emarsys->httpRequest;
        $this->echoOptions($request, $response);
        if (!$response->isOk) {
            $this->handleError($request, $response);
            return self::EXIT_CODE_ERROR;
        }
        $this->stdout(PrettyPrint::json($response->content) . "\n");
        return self::EXIT_CODE_NORMAL;
    }

Expected behavior It shouldn't complain about this.

Screenshots An here's a screenshot showing the wrong(?) error:

Screenshot 2019-11-14 at 11 25 59

Platform and version macOs 10.14.6 and Intelephense version 1.2.3

bmewburn commented 5 years ago

Is sendRequest an override of a base method?

finn-matti commented 4 years ago

No it doesn't seem like it. This class extends Controller which doesn't implement a sendRequest method: https://www.yiiframework.com/doc/api/2.0/yii-base-controller

finn-matti commented 4 years ago

Any ideas? Any way I can help with this?

KapitanOczywisty commented 4 years ago

@finn-matti Have you tried Peek definition Alt+F12 on $this->sendRequest('email/templates')? This should show what definition intelephense is using.

finn-matti commented 4 years ago

Hm. Maybe we changed something, but the error doesn't show up anymore.

719media commented 4 years ago

I'm getting this same problem with intelliphense 1.3.6 and the php built-in \DatePeriod function

Expected 5 arguments. Found 3. But the constructors for DatePeriod don't have anything with 5 required arguments: https://www.php.net/manual/en/class.dateperiod.php

I'm using PHP 7.3.11

719media commented 4 years ago
Screen Shot 2019-12-18 at 1 24 50 PM Screen Shot 2019-12-18 at 1 25 46 PM
bmewburn commented 4 years ago

@719media , I've opened #904 for this. Closing this ticket because I was unable to reproduce the original issue and it's no longer a problem for the author.