protected function buildClass(ClassDefinition $class)
{
$source = <<<EOF
<?php
namespace {$class->getNamespace()};
EOF;
if ($class->isFinal()) {
$source .= 'final ';
} elseif ($class->isAbstract()) {
$source .= 'abstract ';
}
$source .= $class->getType() . ' ' . $class->getName();
if ($extendsClassDefinition = $class->getExtendsClassDefinition()) {
$source .= ' extends \\' . $extendsClassDefinition->getCompleteName();
}
if ($implementedInterfaces = $class->getImplementedInterfaces()) {
$interfaces = array_map(function ($val) {
return '\\' . $val;
}, $implementedInterfaces);
$source .= ' implements ' . join(', ', $interfaces);
}
$source .= PHP_EOL . '{' . PHP_EOL;
foreach ($class->getConstants() as $constant) {
$source .= $this->buildConstant($constant) . PHP_EOL;
}
foreach ($class->getProperties() as $property) {
$source .= $this->buildProperty($property) . PHP_EOL;
}
$source .= PHP_EOL;
foreach ($class->getMethods() as $method) {
$source .= $this->buildMethod($method, $class->getType() === 'interface') . "\n\n";
}
return $source . '}' . PHP_EOL;
}