Skip to content

Commit

Permalink
"No errors found!" message is now printed within a nice green block
Browse files Browse the repository at this point in the history
  • Loading branch information
SMAtaurRahman committed Dec 13, 2021
1 parent fb07d58 commit 20d6a1c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Psalm/IssueBuffer.php
Expand Up @@ -686,7 +686,7 @@ function (IssueData $d1, IssueData $d2): int {
: $error_count . ' errors'
) . ' found' . "\n";
} else {
echo 'No errors found!' . "\n";
self::printSuccessMessage();
}

$show_info = $project_analyzer->stdout_report_options->show_info;
Expand Down Expand Up @@ -777,6 +777,34 @@ function (IssueData $d1, IssueData $d2): int {
}
}

public static function printSuccessMessage(): void
{
// this message will be printed
$message = "No errors found!";

// color block will contain this amount of characters
$blockSize = 30;

// message with prepended and appended whitespace to be same as $blockSize
$messageWithPadding = str_repeat(' ', 7) . $message . str_repeat(' ', 7);

// top side of the color block
$paddingTop = str_repeat(' ', $blockSize);

// bottom side of the color block
$paddingBottom = str_repeat(' ', $blockSize);

// background color, 42 = green
$background = "42";

// text style, 1 = bold
$style = "1";

echo "\e[{$background};{$style}m{$paddingTop}\e[0m" . "\n";
echo "\e[{$background};{$style}m{$messageWithPadding}\e[0m" . "\n";
echo "\e[{$background};{$style}m{$paddingBottom}\e[0m" . "\n";
}

/**
* @param array<string, array<int, IssueData>> $issues_data
* @param array{int, int} $mixed_counts
Expand Down
9 changes: 9 additions & 0 deletions tests/IssueBufferTest.php
Expand Up @@ -110,4 +110,13 @@ public function testFinishDoesNotCorruptInternalState(): void
$this->assertStringNotContainsString("ERROR", $output, "all issues baselined");
IssueBuffer::clear();
}

public function testPrintSuccessMessageWorks(): void
{
ob_start();
IssueBuffer::printSuccessMessage();
$output = ob_get_clean();

$this->assertStringContainsString('No errors found!', $output);
}
}

0 comments on commit 20d6a1c

Please sign in to comment.