Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add phpStan stub file so #1574

Closed
NickStallman opened this issue Apr 21, 2022 · 5 comments · Fixed by #1942
Closed

[Feature] Add phpStan stub file so #1574

NickStallman opened this issue Apr 21, 2022 · 5 comments · Fixed by #1942

Comments

@NickStallman
Copy link

Is your feature request related to a problem? Please describe.
phpstan will statically analyse source code to find potential issues. Currently as ddtrace defines functions like trace_method and classes like SpanData that phpstan doesn't know about, it will complain loudly about any custom tracing code.

Describe the solution you'd like
An official stub file to give phpStan the information it needs would be fantastic.

An initial file I've been using is: ddtrace.stub

<?php

namespace DDTrace;

/**
 * @param array<mixed> $args
 */
function trace_method(\DDTrace\SpanData $span, array $args, mixed $retval, ?\Exception $exception): void
{
}

namespace DDTrace;
class SpanData
{
    public string $name;
    public string $resource;
    public string $service;
    public string $type;
    /** @var string[] $meta */
    public $meta;
    /** @var float[] $metrics */
    public $metrics;
}
@bwoebi
Copy link
Collaborator

bwoebi commented Apr 22, 2022

We have planned on moving towards PHP stub files (As a starting point I've begun experimenting with https://github.com/DataDog/dd-trace-php/blob/52106acf64fb45acd6c74f85fc58adead4a5ff4c/ext/hook/uhook.stub.php).

Expect to see this becoming reality in the coming months :-)

@ralphschindler
Copy link
Contributor

Looking forward to stub files, any movement here? Thanks!

@bwoebi
Copy link
Collaborator

bwoebi commented Jan 31, 2023

We are actively planning on doing this in the next 2-3 months.

@bwoebi
Copy link
Collaborator

bwoebi commented Mar 10, 2023

We now have the following .stub.php files (to be released soon as 0.85.0):

  • ext/ddtrace.stub.php
  • ext/hook/uhook.stub.php
  • ext/hook/uhook_attributes.stub.php

@ralphschindler and @NickStallman I hope that's solving all the doc and autocompletion issues you were having :-)

@NickStallman
Copy link
Author

Brilliant! Thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants