cs and phpstan fixes

This commit is contained in:
Dennis Eichhorn 2020-10-24 17:52:23 +02:00
parent f75fafd6cb
commit ab5ce734c2

View File

@ -36,7 +36,7 @@ final class SearchController extends Controller
* @param ResponseAbstract $response Response * @param ResponseAbstract $response Response
* @param mixed $data Generic data * @param mixed $data Generic data
* *
* @return array * @return void
* *
* @api * @api
* *
@ -61,61 +61,67 @@ final class SearchController extends Controller
) + 1 ) + 1
); );
$files = []; $files = [];
$activeModules = $this->app->moduleManager->getActiveModules();
/** @var array<array{name:array{internal:string, external:string}}> @activeModules */
$activeModules = $this->app->moduleManager->getActiveModules();
foreach ($activeModules as $module) { foreach ($activeModules as $module) {
$path = __DIR__ . '/../../' . $module['name']['internal'] . '/Docs/Help/' . $lang; $path = __DIR__ . '/../../' . $module['name']['internal'] . '/Docs/Help/' . $lang;
/** @var string[] $toCheck */
$toCheck = Directory::listByExtension($path, 'md'); $toCheck = Directory::listByExtension($path, 'md');
foreach ($toCheck as $file) { foreach ($toCheck as $file) {
// @todo: create better matching // @todo: create better matching
$content = \file_get_contents($path . '/' . $file); $content = \file_get_contents($path . '/' . $file);
if (($found = \stripos($content, $pattern)) !== false) {
$contentLength = \strlen($content);
$headline = \strtok($content, "\n");
$t1 = \strripos($content, "\n", -$contentLength + $found); if ($content === false || ($found = \stripos($content, $pattern)) === false) {
$t2 = \strripos($content, '.', -$contentLength + $found); continue;
$summaryStart = ($t1 !== false && $t2 !== false) || $t1 === $t2 }
? \min(
$t1 === false ? 0 : $t1,
$t2 === false ? 0 : $t2,
) : \max(
$t1 === false ? 0 : $t1,
$t2 === false ? 0 : $t2,
);
$t1 = \stripos($content, "\n", $found); $contentLength = \strlen($content);
$t2 = \stripos($content, '.', $found); $headline = \strtok($content, "\n");
$summaryEnd = ($t1 !== false && $t2 !== false) || $t1 === $t2 ? \max(
$t1 === false ? $contentLength : $t1,
$t2 === false ? $contentLength : $t2,
) : \min(
$t1 === false ? $contentLength : $t1,
$t2 === false ? $contentLength : $t2,
);
$summary = \substr( $t1 = \strripos($content, "\n", -$contentLength + $found);
$content, $t2 = \strripos($content, '.', -$contentLength + $found);
$summaryStart + 1, $summaryStart = ($t1 !== false && $t2 !== false) || $t1 === $t2
$summaryEnd - $summaryStart ? \min(
$t1 === false ? 0 : $t1,
$t2 === false ? 0 : $t2,
) : \max(
$t1 === false ? 0 : $t1,
$t2 === false ? 0 : $t2,
); );
$files[$module['name']['internal']][] = [ $t1 = \stripos($content, "\n", $found);
'title' => $module['name']['external'] . ': ' . \trim($headline, " #\r\n\t"), $t2 = \stripos($content, '.', $found);
'summary' => \trim($summary, " #\r\n\t"), $summaryEnd = ($t1 !== false && $t2 !== false) || $t1 === $t2 ? \max(
'link' => $path . '/' . $file, $t1 === false ? $contentLength : $t1,
'account' => '', $t2 === false ? $contentLength : $t2,
'createdAt' => \max( ) : \min(
\filectime($path . '/' . $file), $t1 === false ? $contentLength : $t1,
\filemtime($path . '/' . $file) $t2 === false ? $contentLength : $t2,
), );
'image' => '',
'tags' => [], $summary = \substr(
'type' => 'list_links', $content,
]; $summaryStart + 1,
// @todo: add match score for sorted return $summaryEnd - $summaryStart
} );
$files[$module['name']['internal']][] = [
'title' => $module['name']['external'] . ': ' . \trim($headline, " #\r\n\t"),
'summary' => \trim($summary, " #\r\n\t"),
'link' => $path . '/' . $file,
'account' => '',
'createdAt' => \max(
\filectime($path . '/' . $file),
\filemtime($path . '/' . $file)
),
'image' => '',
'tags' => [],
'type' => 'list_links',
];
// @todo: add match score for sorted return
} }
} }