diff --git a/make/genmethoddocs.php b/make/genmethoddocs.php
index b145747..be3cf6e 100644
--- a/make/genmethoddocs.php
+++ b/make/genmethoddocs.php
@@ -1,6 +1,7 @@
className;
}
+ /**
+ * Returns the base name of the current classname
+ *
+ * @return string
+ */
+ public function getClassBasename(): string
+ {
+ $classParts = explode('\\', $this->className);
+ return end($classParts);
+ }
+
/**
* Magic method __toString, String converstion
*
@@ -144,7 +158,8 @@ public function getArray(): array
'name' => $parameterName,
'type' => $parameterType ? $parameterType->getName() : 'mixed',
'isNullable' => $parameterType && $parameterType->allowsNull(),
- 'defaultValue' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : 'none') : 'none',
+ 'defaultValueavailable' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? true : false) : false,
+ 'defaultValue' => $parameter->isOptional() ? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null) : null,
'description' => $paramDescriptions[$parameterName]['description'] ?? ''
];
}
@@ -222,6 +237,9 @@ public function generateMarkdown(): MarkDownGenerator
$this->addLineH1($this->extractor->getClassName());
+ $phpPrinter = new Printer;
+ $phpClass = new ClassType($this->extractor->getClassBasename());
+
if (!empty($metaData['class']['summary'])) {
$this->addLine($metaData['class']['summary'] ?? "")->addEmptyLine();
}
@@ -230,8 +248,12 @@ public function generateMarkdown(): MarkDownGenerator
$this->addLine($metaData['class']['description'] ?? "")->addEmptyLine();
}
+ if (!empty($metaData['methods'])) {
+ $this->addLineH2("Methods");
+ }
+
foreach ($metaData['methods'] as $methodName => $methodData) {
- $this->addLineH2($methodName, $methodData["methodDetails"]["hasadditional"] === false);
+ $this->addLineH3($methodName, $methodData["methodDetails"]["hasadditional"] === false);
if ($methodData["methodDetails"]["static"] === true) {
$this->addToLastLine('``[static]``', " ");
@@ -241,10 +263,36 @@ public function generateMarkdown(): MarkDownGenerator
$this->addToLastLine('``[abstract]``', " ");
}
+ if ($methodData["methodDetails"]["final"] === true) {
+ $this->addToLastLine('``[final]``', " ");
+ }
+
if ($methodData["methodDetails"]["hasadditional"] === true) {
$this->addEmptyLine();
}
+ $phpMethod = $phpClass->addMethod($methodName);
+ $phpMethod->setPublic();
+ $phpMethod->setStatic($methodData["methodDetails"]["static"] === true);
+ $phpMethod->setAbstract($methodData["methodDetails"]["abstract"] === true);
+ $phpMethod->setFinal($methodData["methodDetails"]["final"] === true);
+ $phpMethod->setReturnType($methodData["return"]["type"]);
+
+ foreach ($methodData["parameters"] as $parameter) {
+ $phpParameter = $phpMethod
+ ->addParameter($parameter["name"])
+ ->setType($parameter["type"])
+ ->setNullable($parameter["isNullable"]);
+
+ if ($parameter['defaultValueavailable'] === true) {
+ $phpParameter->setDefaultValue($parameter["defaultValue"]);
+ }
+ }
+
+ $this->addLineRaw("```php");
+ $this->addLineRaw($phpPrinter->printMethod($phpMethod));
+ $this->addLineRaw("```");
+
if (!empty($methodData["methodDetails"]["summary"])) {
$this->addLine($methodData["methodDetails"]["summary"])->addEmptyLine();
}
@@ -253,10 +301,6 @@ public function generateMarkdown(): MarkDownGenerator
$this->addLine($methodData["methodDetails"]["description"])->addEmptyLine();
}
- if (!empty($methodData["return"]["type"])) {
- $this->addLine('__Returns__ %s', $methodData["return"]["type"])->addEmptyLine();
- }
-
if (!empty($methodData["parameters"])) {
$this->addLine("| Name | Type | Allows Null | Description");
$this->addLine("| :------ | :------ | :-----: | :------");
@@ -311,6 +355,24 @@ private function addLine(string $string, ...$args): MarkDownGenerator
return $this;
}
+ /**
+ * Add a line to internal container
+ *
+ * @param string $string
+ * @param mixed ...$args
+ * @return MarkDownGenerator
+ */
+ private function addLineRaw(string $string, ...$args): MarkDownGenerator
+ {
+ if (StringUtils::stringIsNullOrEmpty($string)) {
+ return $this;
+ }
+
+ $this->lines[] = sprintf($string, ...$args);
+
+ return $this;
+ }
+
/**
* Add an empty line to internal container
*
@@ -368,7 +430,7 @@ private function addLineH2(string $string, bool $newLine = true): MarkDownGenera
*/
private function addLineH3(string $string, bool $newLine = true): MarkDownGenerator
{
- $this->addLine("# %s", $string);
+ $this->addLine("### %s", $string);
if ($newLine) {
$this->addEmptyLine();
@@ -397,6 +459,26 @@ public function addToLastLine(string $string, string $delimiter = "", ...$args):
return $this;
}
+ /**
+ * Add a string to the latest line which was added (before)
+ *
+ * @param string $string
+ * @param string $delimiter
+ * @param mixed ...$args
+ * @return MarkDownGenerator
+ */
+ public function addToLastLineBefore(string $string, string $delimiter = "", ...$args): MarkDownGenerator
+ {
+ if (empty($this->lines)) {
+ return $this->addLine($string, ...$args);
+ }
+
+ $lastIndex = count($this->lines) - 1;
+ $this->lines[$lastIndex] = sprintf($string, ...$args) . $delimiter . $this->lines[$lastIndex];
+
+ return $this;
+ }
+
/**
* Sanatize a string
*
@@ -448,6 +530,7 @@ public static function generate(array $classes)
}
BatchMarkDownGenerator::generate([
+ ZugferdDocument::class => dirname(__FILE__) . '/ClassOverview-ZugferdDocument.md',
ZugferdSettings::class => dirname(__FILE__) . '/ClassOverview-ZugferdSettings.md',
ZugferdDocumentBuilder::class => dirname(__FILE__) . '/ClassOverview-ZugferdDocumentBuilder.md',
ZugferdDocumentReader::class => dirname(__FILE__) . '/ClassOverview-ZugferdDocumentReader.md',