Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No errors found!" message is now printed within a nice green block #7150

Merged
merged 1 commit into from Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 32 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,37 @@ 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";

// foreground/text color, 30 = black
$foreground = "30";

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

echo "\e[{$background};{$style}m{$paddingTop}\e[0m" . "\n";
echo "\e[{$background};{$foreground};{$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);
}
}