Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Command\DbDocs;
namespace Kitodo\Dlf\Command\DatabaseDocs;

use Doctrine\DBAL\Schema\Table;
use ReflectionClass;
use ReflectionProperty;
use RuntimeException;
use TYPO3\CMS\Core\Database\Schema\Parser\Lexer;
use TYPO3\CMS\Core\Database\Schema\Parser\Parser;
use TYPO3\CMS\Core\Database\Schema\SqlReader;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -91,7 +89,9 @@
* Collect information about relevant tables from `ext_tables.sql` and the
* Extbase classmap.
*
* @return mixed[] Array of objects with table information
* @access public
*
* @return mixed[] An array of objects with table information
*/
public function collectTables(): array
{
Expand All @@ -103,8 +103,8 @@
$result = [];

foreach ($createTableStatements as $statement) {
$parser = new Parser(new Lexer());

Check failure on line 106 in Classes/Command/DatabaseDocs/Generator.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (12.4, 8.2)

Parameter #1 $statement of class TYPO3\CMS\Core\Database\Schema\Parser\Parser constructor expects string, TYPO3\CMS\Core\Database\Schema\Parser\Lexer given.

Check failure on line 106 in Classes/Command/DatabaseDocs/Generator.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (12.4, 8.2)

Class TYPO3\CMS\Core\Database\Schema\Parser\Lexer constructor invoked with 0 parameters, 1 required.
list($table) = $parser->parse($statement);

Check failure on line 107 in Classes/Command/DatabaseDocs/Generator.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (12.4, 8.2)

Method TYPO3\CMS\Core\Database\Schema\Parser\Parser::parse() invoked with 1 parameter, 0 required.

$tableName = $table->getName();
if (!str_starts_with($tableName, 'tx_dlf_')) {
Expand All @@ -122,6 +122,8 @@
/**
* Get a map from database table names to their domain model class names.
*
* @access public
*
* @return mixed[] Map from table name to fully qualified class name
*/
public function getTableClassMap(): array
Expand Down Expand Up @@ -151,14 +153,15 @@
* @param Table $table The table to be analyzed
* @param string|null $className Fully qualified name of the domain model class
*
* @return object Object with table information
* @return object An object with table information
*/
protected function getTableInfo(Table $table, ?string $className): object
{
$tableName = $table->getName();

$isPrimary = [];
if (!is_null($primaryKey = $table->getPrimaryKey())) {
$primaryKey = $table->getPrimaryKey();
if ($primaryKey != null) {
foreach ($primaryKey->getUnquotedColumns() as $primaryColumn) {
$isPrimary[$primaryColumn] = true;
}
Expand Down Expand Up @@ -216,6 +219,15 @@
return $result;
}

/**
* Extract description from a property doc-comment.
*
* @access public
*
* @param string $docComment The doc-comment to be parsed
*
* @return string The extracted description
*/
protected function parsePropertyDocComment(string $docComment): string
{
$lines = explode("\n", $docComment);
Expand All @@ -230,6 +242,15 @@
return '';
}

/**
* Extract description from a class doc-comment
*
* @access protected
*
* @param string $docComment The doc-comment to be parsed
*
* @return string The extracted description
*/
protected function parseDocComment(string $docComment): string
{
// TODO: Consider using phpDocumentor (though that splits the docblock into summary and description)
Expand All @@ -255,7 +276,9 @@
/**
* Transform table structure into .rst page.
*
* @param mixed[] $tables Array of table information objects
* @access public
*
* @param mixed[] $tables An array of table information objects
*
* @return RstSection The generated .rst page
*/
Expand All @@ -270,9 +293,11 @@
RST);

// Sort tables alphabetically
usort($tables, function ($lhs, $rhs) {
return $lhs->name <=> $rhs->name;
});
usort(
$tables, function ($lhs, $rhs) {
return $lhs->name <=> $rhs->name;
}
);

foreach ($tables as $tableInfo) {
$section = $page->subsection();
Expand All @@ -297,21 +322,25 @@
'description' => 'Description',
]];

$rows = array_map(function ($column) use ($page) {
return [
'field' => (
$page->format($column->name, ['bold' => $column->isPrimary])
. "\u{00a0}\u{00a0}"
. $page->format($column->type->getName(), ['italic' => true])
),

'description' => $page->paragraphs([
$page->format($column->feComment, ['italic' => true]),
$column->fieldComment,
$column->sqlComment,
]),
];
}, $tableInfo->columns);
$rows = array_map(
function ($column) use ($page) {
return [
'field' => (
$page->format($column->name, ['bold' => $column->isPrimary])
. "\u{00a0}\u{00a0}"
. $page->format($column->type->getName(), ['italic' => true])
),

'description' => $page->paragraphs(
[
$page->format($column->feComment, ['italic' => true]),
$column->fieldComment,
$column->sqlComment,
]
),
];
}, $tableInfo->columns
);

$section->addTable($rows, $header);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Command\DbDocs;
namespace Kitodo\Dlf\Command\DatabaseDocs;

/**
* Simple utility to write .rst (reStructuredText).
Expand All @@ -36,6 +36,8 @@
*
* @access public
*
* @static
*
* @param string $text
* @param array<string, bool> $format
*
Expand All @@ -59,15 +61,19 @@
*
* @access public
*
* @static
*
* @param mixed[] $paragraphs
*
* @return string
*/
public static function paragraphs(array $paragraphs): string
{
$paragraphs = array_values(array_filter($paragraphs, function ($entry) {
return !empty($entry);
}));
$paragraphs = array_values(
array_filter($paragraphs, function ($entry) {

Check notice on line 73 in Classes/Command/DatabaseDocs/RstSection.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DatabaseDocs/RstSection.php#L73

Opening parenthesis of a multi-line function call must be the last content on the line
return !empty($entry);
})

Check notice on line 75 in Classes/Command/DatabaseDocs/RstSection.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Command/DatabaseDocs/RstSection.php#L75

Closing parenthesis of a multi-line function call must be on a line by itself
);

return implode("\n\n", $paragraphs);
}
Expand Down Expand Up @@ -117,7 +123,7 @@
}

/**
* Add a field list table to section.
* Add a field list table to the section.
*
* @access public
*
Expand Down Expand Up @@ -196,13 +202,13 @@
/**
* Render header of given level.
*
* @access protected
* @access private
*
* @param int $level
*
* @return string
*/
protected function renderHeader(int $level): string
private function renderHeader(int $level): string
{
$result = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Kitodo\Dlf\Command;

use Kitodo\Dlf\Command\DbDocs\Generator;
use Kitodo\Dlf\Command\DatabaseDocs\Generator;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -31,7 +31,7 @@
*
* @access public
*/
class DbDocsCommand extends Command
class DatabaseDocsGenerateCommand extends Command
{
protected Generator $generator;

Expand Down
4 changes: 2 additions & 2 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ services:
Kitodo\Dlf\:
resource: '../Classes/*'

Kitodo\Dlf\Command\DbDocsCommand:
Kitodo\Dlf\Command\DatabaseDocsGenerateCommand:
tags:
- name: console.command
command: 'kitodo:dbdocs'
command: 'kitodo:databaseDocsGenerate'
description: 'Generate database rst file.'

Kitodo\Dlf\Command\DeleteCommand:
Expand Down
Loading
Loading