Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Restored color variable options to style.css to maintain backwards co…
…mpatibility.
  • Loading branch information
gammamatrix committed May 8, 2024
commit ba3047f872113a15df70f8e5d246b0524681f98c
1 change: 1 addition & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
'generator' => $this->generator,
'low_upper_bound' => $this->thresholds->lowUpperBound(),
'high_lower_bound' => $this->thresholds->highLowerBound(),
'theme' => $this->theme,
]]]></code>
</InvalidArgument>
<PossiblyUndefinedArrayOffset>
Expand Down
22 changes: 18 additions & 4 deletions src/Report/Html/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ final class Colors
private readonly string $successHigh;
private readonly string $warning;
private readonly string $danger;
private readonly string $theme;

public static function default(): self
{
return new self('#dff0d8', '#c3e3b5', '#99cb84', '#fcf8e3', '#f2dede');
return new self(
'rgb(from var(--bs-success) r g b / 0.25)',
'rgb(from var(--bs-success) r g b / 0.5)',
'rgb(from var(--bs-success) r g b / 0.75)',
'rgb(from var(--bs-warning) r g b / 0.25)',
'rgb(from var(--bs-danger) r g b / 0.25)',
// 'dark', // or any other theme name defined in customCssFile
);
}

public static function from(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger): self
public static function from(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger, string $theme = ''): self
{
return new self($successLow, $successMedium, $successHigh, $warning, $danger);
return new self($successLow, $successMedium, $successHigh, $warning, $danger, $theme);
}

private function __construct(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger)
private function __construct(string $successLow, string $successMedium, string $successHigh, string $warning, string $danger, string $theme = '')
{
$this->successLow = $successLow;
$this->successMedium = $successMedium;
$this->successHigh = $successHigh;
$this->warning = $warning;
$this->danger = $danger;
$this->theme = $theme;
}

public function successLow(): string
Expand All @@ -63,4 +72,9 @@ public function danger(): string
{
return $this->danger;
}

public function theme(): string
{
return $this->theme;
}
}
3 changes: 3 additions & 0 deletions src/Report/Html/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$directory = new Directory(
Expand All @@ -59,6 +60,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$file = new File(
Expand All @@ -67,6 +69,7 @@ public function process(CodeCoverage $coverage, string $target): void
$date,
$this->thresholds,
$coverage->collectsBranchAndPathCoverage(),
$this->colors->theme(),
);

$directory->render($report, $target . 'index.html');
Expand Down
5 changes: 4 additions & 1 deletion src/Report/Html/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ abstract class Renderer
protected Thresholds $thresholds;
protected bool $hasBranchCoverage;
protected string $version;
protected string $theme;

public function __construct(string $templatePath, string $generator, string $date, Thresholds $thresholds, bool $hasBranchCoverage)
public function __construct(string $templatePath, string $generator, string $date, Thresholds $thresholds, bool $hasBranchCoverage, string $theme)
{
$this->templatePath = $templatePath;
$this->generator = $generator;
$this->date = $date;
$this->thresholds = $thresholds;
$this->version = Version::id();
$this->hasBranchCoverage = $hasBranchCoverage;
$this->theme = $theme;
}

protected function renderItemTemplate(Template $template, array $data): string
Expand Down Expand Up @@ -173,6 +175,7 @@ protected function setCommonTemplateVariables(Template $template, AbstractNode $
'generator' => $this->generator,
'low_upper_bound' => $this->thresholds->lowUpperBound(),
'high_lower_bound' => $this->thresholds->highLowerBound(),
'theme' => $this->theme,
],
);
}
Expand Down
41 changes: 10 additions & 31 deletions src/Report/Html/Renderer/Template/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,27 @@ body {
}

.table tbody tr.covered-by-large-tests td, li.covered-by-large-tests, tr.success, td.success, li.success, span.success {
/* background-color: {{success-low}}; */
/* background-color: var(--bs-success-border-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.25);
background-color: {{success-low}};
}

.table tbody tr.covered-by-medium-tests td, li.covered-by-medium-tests {
/* background-color: {{success-medium}}; */
/* background-color: var(--bs-success-bg-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.5);
background-color: {{success-medium}};
}

.table tbody tr.covered-by-small-tests td, li.covered-by-small-tests {
/* background-color: {{success-high}}; */
/* background-color: var(--bs-success-bg-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.75);
background-color: {{success-high}};
}

.table tbody tr.warning td, .table tbody td.warning, li.warning, span.warning {
/* background-color: {{warning}}; */
/* background-color: var(--bs-warning-bg-subtle); */
background-color: rgb(from var(--bs-warning) r g b / 0.25);
background-color: {{warning}};
}

.table tbody tr.danger td, .table tbody td.danger, li.danger, span.danger {
/* background-color: {{danger}}; */
/* background-color: var(--bs-danger-bg-subtle); */
background-color: rgb(from var(--bs-danger) r g b / 0.25);
background-color: {{danger}};
}

.table tbody td.info {
/* background-color: #d9edf7; */
/* background-color: var(--bs-info-bg-subtle); */
background-color: rgb(from var(--bs-info) r g b / 0.25);
}

Expand Down Expand Up @@ -160,31 +149,21 @@ table + .structure-heading {
}

.covered-by-small-tests, tr.covered-by-small-tests td {
/* background-color: {{success-high}}; */
/* background-color: var(--bs-success-bg-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.75);
background-color: {{success-high}};
}

.covered-by-medium-tests, tr.covered-by-medium-tests td {
/* background-color: {{success-medium}}; */
/* background-color: var(--bs-success-bg-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.5);
background-color: {{success-medium}};
}

.covered-by-large-tests, tr.covered-by-large-tests td {
/* background-color: {{success-low}}; */
/* background-color: var(--bs-success-border-subtle); */
background-color: rgb(from var(--bs-success) r g b / 0.25);
background-color: {{success-low}};
}

.not-covered, tr.not-covered td {
/* background-color: {{danger}}; */
/* background-color: var(--bs-danger-bg-subtle); */
background-color: rgb(from var(--bs-danger) r g b / 0.25);
background-color: {{danger}};
}

.not-coverable, tr.not-coverable td {
/* background-color: {{warning}}; */
/* background-color: var(--bs-warning-bg-subtle); */
background-color: rgb(from var(--bs-warning) r g b / 0.25);
background-color: {{warning}};
}
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/dashboard.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Dashboard for {{full_path}}</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Dashboard for {{full_path}}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/directory.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/file.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/Report/Html/Renderer/Template/file_branch.html.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="{{theme}}">
<head>
<meta charset="UTF-8">
<title>Code Coverage for {{full_path}}</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%eBankAccount.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Dashboard for %s</title>
Expand Down
2 changes: 1 addition & 1 deletion tests/_files/Report/HTML/CoverageForBankAccount/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Dashboard for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%esource_with_class_and_anonymous_function.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Dashboard for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%esource_with_ignore.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%eBankAccount.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%eBankAccount.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s%eBankAccount.php</title>
Expand Down Expand Up @@ -394,6 +394,22 @@ <h5 class="structure-heading"><a name="BankAccount-&gt;withdrawMoney">BankAccoun

</tbody>
</table>
%a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is correct way to fix this test by adding the footer.



<footer>
<hr/>
<h4>Legend</h4>
<p><span class="success"><strong>Fully covered</strong></span><span class="warning"><strong>Partially covered</strong></span><span class="danger"><strong>Not covered</strong></span></p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage %s</a> using <a href="%s" target="_top">%s</a> at %s.</small>
</p>
<a title="Back to the top" id="toplink" href="#">
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="16" viewBox="0 0 12 16"><path fill-rule="evenodd" d="M12 11L6 5l-6 6h12z"/></svg>
</a>
</footer>
</div>
<script src="_js/jquery.min.js?v=%s" type="text/javascript"></script>
<script src="_js/bootstrap.bundle.min.js?v=%s" type="text/javascript"></script>
<script src="_js/file.js?v=%s" type="text/javascript"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Dashboard for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Dashboard for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %s</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %ssource_without_namespace.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %ssource_without_namespace.php</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<html lang="en" data-bs-theme="%S">
<head>
<meta charset="UTF-8">
<title>Code Coverage for %ssource_without_namespace.php</title>
Expand Down
Loading