Skip to content

Commit

Permalink
Add $name property in SetupResult and improve API
Browse files Browse the repository at this point in the history
Keys for check results are not locale dependent anymore, the name of the
 setup check is instead stored in the setup result object.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Nov 7, 2023
1 parent 00d3856 commit 2a12f0b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/Command/SetupChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
default:
foreach ($results as $category => $checks) {
$output->writeln("\t{$category}:");
foreach ($checks as $title => $check) {
foreach ($checks as $check) {
$styleTag = match ($check->getSeverity()) {
'success' => 'info',
'error' => 'error',
Expand All @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"\t\t".
($styleTag !== null ? "<{$styleTag}>" : '').
"{$emoji} ".
$title.
$check->getName().

Check notice

Code scanning / Psalm

PossiblyNullOperand Note

Cannot concatenate with a possibly null null|string
($description !== null ? ': '.$description : '').
($styleTag !== null ? "</{$styleTag}>" : ''),
$verbosity
Expand All @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
foreach ($results as $category => $checks) {
foreach ($checks as $title => $check) {
foreach ($checks as $check) {
if ($check->getSeverity() !== 'success') {
return self::FAILURE;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/SetupCheck/SetupCheckManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public function runAll(): array {
$setupCheckObject = Server::get($setupCheck->getService());
$this->logger->debug('Running check '.get_class($setupCheckObject));
$setupResult = $setupCheckObject->run();
$setupResult->setName($setupCheckObject->getName());
$category = $setupCheckObject->getCategory();
$results[$category] ??= [];
$results[$category][$setupCheckObject->getName()] = $setupResult;
$results[$category][$setupCheckObject::class] = $setupResult;
}
return $results;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/public/SetupCheck/ISetupCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
interface ISetupCheck {
/**
* @since 28.0.0
* @return string Category id, one of security/system/accounts, or a custom one which will be merged in system
*/
public function getCategory(): string;

/**
* @since 28.0.0
* @return string Translated name to display to the user
*/
public function getName(): string;

Expand Down
32 changes: 32 additions & 0 deletions lib/public/SetupCheck/SetupResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class SetupResult implements \JsonSerializable {
public const WARNING = 'warning';
public const ERROR = 'error';

/**
* @param string $name Translated name to display to the user
*/
private ?string $name = null;

/**
* @brief Private constructor, use success()/info()/warning()/error() instead
* @param self::SUCCESS|self::INFO|self::WARNING|self::ERROR $severity
Expand All @@ -51,6 +56,8 @@ private function __construct(

/**
* @brief Create a success result object
* @param ?string $description Translated detailed description to display to the user
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
* @since 28.0.0
*/
public static function success(?string $description = null, ?string $linkToDoc = null): self {
Expand All @@ -59,6 +66,8 @@ public static function success(?string $description = null, ?string $linkToDoc =

/**
* @brief Create an info result object
* @param ?string $description Translated detailed description to display to the user
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
* @since 28.0.0
*/
public static function info(?string $description = null, ?string $linkToDoc = null): self {
Expand All @@ -67,6 +76,8 @@ public static function info(?string $description = null, ?string $linkToDoc = nu

/**
* @brief Create a warning result object
* @param ?string $description Translated detailed description to display to the user
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
* @since 28.0.0
*/
public static function warning(?string $description = null, ?string $linkToDoc = null): self {
Expand All @@ -75,6 +86,8 @@ public static function warning(?string $description = null, ?string $linkToDoc =

/**
* @brief Create an error result object
* @param ?string $description Translated detailed description to display to the user
* @param ?string $linkToDoc URI of related relevent documentation, be it from Nextcloud or another project
* @since 28.0.0
*/
public static function error(?string $description = null, ?string $linkToDoc = null): self {
Expand All @@ -100,6 +113,24 @@ public function getDescription(): ?string {
return $this->description;
}

/**
* @brief Get the name for the setup check
*
* @since 28.0.0
*/
public function getName(): ?string {
return $this->name;
}

/**
* @brief Set the name from the setup check
*
* @since 28.0.0
*/
public function setName(string $name): void {
$this->name = $name;
}

/**
* @brief Get a link to the doc for the explanation.
*
Expand All @@ -116,6 +147,7 @@ public function getLinkToDoc(): ?string {
*/
public function jsonSerialize(): array {
return [
'name' => $this->name,
'severity' => $this->severity,
'description' => $this->description,
'linkToDoc' => $this->linkToDoc,
Expand Down

0 comments on commit 2a12f0b

Please sign in to comment.