protected function createInstance(FixtureInterface $fixture)
{
$class = $fixture->getClassName();
try {
$constructRefl = new \ReflectionMethod($class, '__construct');
if (false === $constructRefl->isPublic()) {
throw InstantiationExceptionFactory::createForNonPublicConstructor($fixture);
}
if (0 === $constructRefl->getNumberOfRequiredParameters()) {
return new $class();
}
throw InstantiationExceptionFactory::createForConstructorIsMissingMandatoryParameters($fixture);
} catch (\ReflectionException $exception) {
// Thrown when __construct does not exist, i.e. is default constructor
if (1 !== preg_match('/Method (.+)__construct\\(.*\\) does not exist/', $exception->getMessage())) {
throw InstantiationExceptionFactory::createForCouldNotGetConstructorData($fixture, 0, $exception);
}
// Continue
}
return new $class();
}