Skip to content

MongoDB\BSON\UTCDateTime::__construct returns wrong reflection information #683

@alcaeus

Description

@alcaeus

The method reflection for MongoDB\BSON\UTCDateTime::__construct reports that the $milliseconds argument does not have a default value:

php > var_dump(phpversion('mongodb'));
php shell code:1:
string(5) "1.3.3"

php > $reflection = new ReflectionMethod(MongoDB\BSON\UTCDateTime::class, '__construct');

php > var_dump($reflection->getParameters()[0]);
php shell code:1:
class ReflectionParameter#2 (1) {
  public $name =>
  string(12) "milliseconds"
}

php > var_dump($reflection->getParameters()[0]->isDefaultValueAvailable());
php shell code:1:
bool(false)

This creates issues when running static analyzers like phpstan on the code, which erroneously reports the following error when running new MongoDB\BSON\UTCDateTime():

Class MongoDB\BSON\UTCDateTime constructor invoked with 0 parameters, 1 required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions