public static function generate($options = [])
{
$defaults = ['class' => 'Kahlan\\Spec\\Plugin\\Double\\Double' . static::$_index++, 'extends' => '', 'implements' => [], 'uses' => [], 'methods' => [], 'layer' => null, 'openTag' => true, 'closeTag' => true];
$options += $defaults;
if ($options['extends']) {
$options += ['magicMethods' => false];
} else {
$options += ['magicMethods' => true];
}
$class = $options['class'];
$namespace = '';
if (($pos = strrpos($class, '\\')) !== false) {
$namespace = substr($class, 0, $pos);
$class = substr($class, $pos + 1);
}
if ($namespace) {
$namespace = "namespace {$namespace};\n";
}
$uses = static::_generateUses($options['uses']);
$extends = static::_generateExtends($options['extends']);
$implements = static::_generateImplements($options['implements']);
$methods = static::_generateMethodStubs($options['methods'], $options['magicMethods']);
if ($options['extends']) {
$methods += static::_generateClassMethods($options['extends'], $options['layer']);
}
$methods += static::_generateInterfaceMethods($options['implements']);
$methods = $methods ? ' ' . join("\n ", $methods) : '';
$openTag = $options['openTag'] ? "<?php\n" : '';
$closeTag = $options['closeTag'] ? "?>" : '';
return $openTag . $namespace . <<<EOT
class {$class}{$extends}{$implements} {
{$uses}{$methods}
}
{$closeTag}
EOT;
}