You are here

protected function PHPUnit_Framework_MockObject_Invocation_Static::cloneObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php \PHPUnit_Framework_MockObject_Invocation_Static::cloneObject()

Parameters

object $original:

Return value

object

1 call to PHPUnit_Framework_MockObject_Invocation_Static::cloneObject()
PHPUnit_Framework_MockObject_Invocation_Static::__construct in vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php

File

vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php, line 108

Class

PHPUnit_Framework_MockObject_Invocation_Static
Represents a static invocation.

Code

protected function cloneObject($original) {
  $cloneable = null;
  $object = new ReflectionObject($original);

  // Check the blacklist before asking PHP reflection to work around
  // https://bugs.php.net/bug.php?id=53967
  if ($object
    ->isInternal() && isset(self::$uncloneableExtensions[$object
    ->getExtensionName()])) {
    $cloneable = false;
  }
  if ($cloneable === null) {
    foreach (self::$uncloneableClasses as $class) {
      if ($original instanceof $class) {
        $cloneable = false;
        break;
      }
    }
  }
  if ($cloneable === null && method_exists($object, 'isCloneable')) {
    $cloneable = $object
      ->isCloneable();
  }
  if ($cloneable === null && $object
    ->hasMethod('__clone')) {
    $method = $object
      ->getMethod('__clone');
    $cloneable = $method
      ->isPublic();
  }
  if ($cloneable === null) {
    $cloneable = true;
  }
  if ($cloneable) {
    try {
      return clone $original;
    } catch (Exception $e) {
      return $original;
    }
  }
  else {
    return $original;
  }
}