private function addCreateDiscoveryMethod(Clazz $class)
{
$method = new Method('createDiscovery');
$method->setDescription('Creates the resource discovery.');
$arg = new Argument(self::REPO_VAR_NAME);
$arg->setTypeHint('ResourceRepository');
$arg->setType('ResourceRepository');
$arg->setDescription('The resource repository to read from.');
$method->addArgument($arg);
$method->setReturnValue(new ReturnValue('$' . self::DISCOVERY_VAR_NAME, 'Discovery', 'The created discovery.'));
$method->addBody(<<<EOF
if (!interface_exists('Puli\\Discovery\\Api\\Discovery')) {
throw new RuntimeException('Please install puli/discovery to create Discovery instances.');
}
EOF
);
$class->addImport(new Import('Puli\\Repository\\Api\\ResourceRepository'));
$class->addImport(new Import('Puli\\Discovery\\Api\\Discovery'));
$class->addImport(new Import('RuntimeException'));
$class->addMethod($method);
// Add method body
$config = $this->config;
$type = $config->get(Config::DISCOVERY_TYPE);
$options = $this->camelizeKeys($config->get(Config::DISCOVERY));
$options['root-dir'] = $this->rootDir;
$generator = $this->generatorRegistry->getServiceGenerator(GeneratorRegistry::DISCOVERY, $type);
$generator->generateNewInstance(self::DISCOVERY_VAR_NAME, $method, $this->generatorRegistry, $options);
}