Коммит 5e7ecd96 создал по автору Коротков Данила's avatar Коротков Данила
Просмотр файлов

update

владелец ae1bacdd
......@@ -17,7 +17,7 @@ use Rudra\Markdown\Creators\DocumentationCreatorInterface;
class DocumentationCommand
{
protected DocumentationCreatorInterface $docCreator;
private DocumentationCreatorInterface $docCreator;
public function actionIndex(): void
{
......@@ -53,22 +53,27 @@ class DocumentationCommand
$this->scandir($inputPath, $outputPath);
$this->docCreator->createDocs($outputPath);
Cli::printer("Documentation: " . $outputPath . " created\n", "green");
Cli::printer("Documentation: " . $outputPath . " created\n", "green");
}
protected function scandir(string $inputPath, string $outputPath): void
/**
* Recursively scans a directory for PHP classes and processes files with uppercase filenames.
*
* @param string $inputPath
* @param string $outputPath
* @return void
*/
private function scandir(string $inputPath, string $outputPath): void
{
$directory = array_diff(scandir($inputPath), array('..', '.'));
foreach($directory as $item) {
if (str_contains($item, ".php")) {
if (ctype_upper($item[0])) {
$fileContent = file_get_contents($inputPath . '/' . $item);
$className = str_replace(".php", "", $item);
if (preg_match('/namespace[\\s]+([A-Za-z0-9\\\\]+?);/sm', $fileContent, $match)) {
$fullClassName = $match[1] . "\\" . $className;
if (class_exists($fullClassName) or interface_exists($fullClassName) or trait_exists($fullClassName)) {
......@@ -87,7 +92,14 @@ class DocumentationCommand
}
}
protected function setData(string $fullClassName, string $type = 'header'): void
/**
* Generates and appends documentation content for a class based on the specified type.
*
* @param string $fullClassName
* @param string $type
* @return void
*/
private function setData(string $fullClassName, string $type = 'header'): void
{
$methodName = "create" . ucfirst($type) . "String";
......
......@@ -9,7 +9,21 @@ namespace Rudra\Markdown\Creators;
interface DocumentationCreatorInterface
{
/**
* @param string $outputPath
* @return void
*/
public function createDocs(string $outputPath): void;
/**
* @param string $fullClassName
* @return string
*/
public function createHeaderString(string $fullClassName): string;
/**
* @param string $fullClassName
* @return string
*/
public function createBodyString(string $fullClassName): string;
}
......@@ -11,13 +11,20 @@ namespace Rudra\Markdown\Creators;
class HtmlCreator implements DocumentationCreatorInterface
{
protected string $frameworkType;
private string $frameworkType;
/**
* @param string $frameworkType
*/
public function __construct(string $frameworkType = 'bsp')
{
$this->frameworkType = $frameworkType;
}
/**
* @param string $outputPath
* @return void
*/
public function createDocs(string $outputPath): void
{
file_put_contents($outputPath, $this->setHtmlHeader(), FILE_APPEND);
......@@ -33,11 +40,19 @@ class HtmlCreator implements DocumentationCreatorInterface
file_put_contents($outputPath, $this->setHtmlFooter(), FILE_APPEND);
}
/**
* @param string $fullClassName
* @return string
*/
public function createHeaderString(string $fullClassName): string
{
return '<p><a href="#' . str_replace("\\", "_", strtolower($fullClassName)) . '">' . $fullClassName . '</a></p>';
}
/**
* @param string $fullClassName
* @return string
*/
public function createBodyString(string $fullClassName): string
{
$class = new \ReflectionClass($fullClassName);
......@@ -105,12 +120,19 @@ class HtmlCreator implements DocumentationCreatorInterface
return $header . $table . '</table>';
}
private function getAnchorName($className): string
/**
* @param string $className
* @return string
*/
private function getAnchorName(string $className): string
{
return str_replace("\\", "_", strtolower($className));
}
protected function setHtmlHeader(): string
/**
* @return string
*/
private function setHtmlHeader(): string
{
switch ($this->frameworkType) {
case 'ui':
......@@ -166,11 +188,13 @@ class HtmlCreator implements DocumentationCreatorInterface
}
}
protected function setHtmlFooter(): string
/**
* @return string
*/
private function setHtmlFooter(): string
{
switch ($this->frameworkType) {
case 'ui':
return '</div></body></html>';
case 'ui':
case 'f':
return '</div></body></html>';
default:
......@@ -183,7 +207,10 @@ class HtmlCreator implements DocumentationCreatorInterface
}
}
protected function setTableClass(): string
/**
* @return string
*/
private function setTableClass(): string
{
switch ($this->frameworkType) {
case 'ui':
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать