PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/dzakiafif/cokelatklasik
PHP | 158 lines | 91 code | 18 blank | 49 comment | 12 complexity | 4b0139aaea8f34e11034348b0ac1c4df MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the PHPUnit_MockObject package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use SebastianBergmann\Exporter\Exporter;
  11. /**
  12. * Represents a static invocation.
  13. *
  14. * @package PHPUnit_MockObject
  15. * @author Sebastian Bergmann <sebastian@phpunit.de>
  16. * @copyright Sebastian Bergmann <sebastian@phpunit.de>
  17. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  18. * @version Release: @package_version@
  19. * @link http://github.com/sebastianbergmann/phpunit-mock-objects
  20. * @since Class available since Release 1.0.0
  21. */
  22. class PHPUnit_Framework_MockObject_Invocation_Static implements PHPUnit_Framework_MockObject_Invocation, PHPUnit_Framework_SelfDescribing
  23. {
  24. /**
  25. * @var array
  26. */
  27. protected static $uncloneableExtensions = array(
  28. 'mysqli' => true,
  29. 'SQLite' => true,
  30. 'sqlite3' => true,
  31. 'tidy' => true,
  32. 'xmlwriter' => true,
  33. 'xsl' => true
  34. );
  35. /**
  36. * @var array
  37. */
  38. protected static $uncloneableClasses = array(
  39. 'Closure',
  40. 'COMPersistHelper',
  41. 'IteratorIterator',
  42. 'RecursiveIteratorIterator',
  43. 'SplFileObject',
  44. 'PDORow',
  45. 'ZipArchive'
  46. );
  47. /**
  48. * @var string
  49. */
  50. public $className;
  51. /**
  52. * @var string
  53. */
  54. public $methodName;
  55. /**
  56. * @var array
  57. */
  58. public $parameters;
  59. /**
  60. * @param string $className
  61. * @param string $methodname
  62. * @param array $parameters
  63. * @param boolean $cloneObjects
  64. */
  65. public function __construct($className, $methodName, array $parameters, $cloneObjects = false)
  66. {
  67. $this->className = $className;
  68. $this->methodName = $methodName;
  69. $this->parameters = $parameters;
  70. if (!$cloneObjects) {
  71. return;
  72. }
  73. foreach ($this->parameters as $key => $value) {
  74. if (is_object($value)) {
  75. $this->parameters[$key] = $this->cloneObject($value);
  76. }
  77. }
  78. }
  79. /**
  80. * @return string
  81. */
  82. public function toString()
  83. {
  84. $exporter = new Exporter;
  85. return sprintf(
  86. "%s::%s(%s)",
  87. $this->className,
  88. $this->methodName,
  89. join(
  90. ', ',
  91. array_map(
  92. array($exporter, 'shortenedExport'),
  93. $this->parameters
  94. )
  95. )
  96. );
  97. }
  98. /**
  99. * @param object $original
  100. * @return object
  101. */
  102. protected function cloneObject($original)
  103. {
  104. $cloneable = null;
  105. $object = new ReflectionObject($original);
  106. // Check the blacklist before asking PHP reflection to work around
  107. // https://bugs.php.net/bug.php?id=53967
  108. if ($object->isInternal() &&
  109. isset(self::$uncloneableExtensions[$object->getExtensionName()])) {
  110. $cloneable = false;
  111. }
  112. if ($cloneable === null) {
  113. foreach (self::$uncloneableClasses as $class) {
  114. if ($original instanceof $class) {
  115. $cloneable = false;
  116. break;
  117. }
  118. }
  119. }
  120. if ($cloneable === null && method_exists($object, 'isCloneable')) {
  121. $cloneable = $object->isCloneable();
  122. }
  123. if ($cloneable === null && $object->hasMethod('__clone')) {
  124. $method = $object->getMethod('__clone');
  125. $cloneable = $method->isPublic();
  126. }
  127. if ($cloneable === null) {
  128. $cloneable = true;
  129. }
  130. if ($cloneable) {
  131. try {
  132. return clone $original;
  133. } catch (Exception $e) {
  134. return $original;
  135. }
  136. } else {
  137. return $original;
  138. }
  139. }
  140. }