Avoid direct check of class name (#4601)

* Avoid direct check of class name

So that subclasses are also ok

* Use type hint in function signature.
pull/4609/head
Paul Yang 7 years ago committed by GitHub
parent 5f9232b5e0
commit 5f7334f5f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      php/src/Google/Protobuf/Timestamp.php

@ -159,14 +159,10 @@ class Timestamp extends \Google\Protobuf\Internal\Message
/**
* Converts PHP DateTime to Timestamp.
*
* @param DateTime $datetime
* @param \DateTime $datetime
*/
public function fromDateTime($datetime)
public function fromDateTime(\DateTime $datetime)
{
if (get_class($datetime) !== \DateTime::class) {
trigger_error("Given parameter is not a DateTime.",
E_USER_ERROR);
}
$this->seconds = $datetime->format('U');
$this->nanos = 0;
}
@ -174,7 +170,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
/**
* Converts Timestamp to PHP DateTime. Nano second is ignored.
*
* @return DateTime $datetime
* @return \DateTime $datetime
*/
public function toDateTime()
{

Loading…
Cancel
Save