/**
* The Constructor.
*
* @param mixed $reference An instance or a fully-namespaced class name.
*/
public function __construct($reference)
{
$reference = $this->_reference($reference);
$isString = is_string($reference);
if ($isString) {
if (!class_exists($reference)) {
throw new InvalidArgumentException("Can't Stub the unexisting class `{$reference}`.");
}
$reference = ltrim($reference, '\\');
$reflection = Inspector::inspect($reference);
} else {
$reflection = Inspector::inspect(get_class($reference));
}
if (!$reflection->isInternal()) {
$this->_reference = $reference;
return;
}
if (!$isString) {
throw new InvalidArgumentException("Can't Stub built-in PHP instances, create a test double using `Double::instance()`.");
}
$this->_needToBePatched = true;
return $this->_reference = $reference;
}