Skip to content

Commit c491254

Browse files
Add option to disable the generation of the class-oriented HTML report
1 parent 6971cac commit c491254

3 files changed

Lines changed: 55 additions & 6 deletions

File tree

src/Report/Html/Facade.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
private Colors $colors;
4444
private Thresholds $thresholds;
4545
private CustomCssFile $customCssFile;
46+
private bool $classView;
4647

47-
public function __construct(string $generator = '', ?Colors $colors = null, ?Thresholds $thresholds = null, ?CustomCssFile $customCssFile = null)
48+
public function __construct(string $generator = '', ?Colors $colors = null, ?Thresholds $thresholds = null, ?CustomCssFile $customCssFile = null, bool $classView = true)
4849
{
4950
$this->generator = $generator;
5051
$this->colors = $colors ?? Colors::default();
5152
$this->thresholds = $thresholds ?? Thresholds::default();
5253
$this->customCssFile = $customCssFile ?? CustomCssFile::default();
54+
$this->classView = $classView;
5355
$this->templatePath = __DIR__ . '/Renderer/Template/';
5456
}
5557

@@ -60,12 +62,19 @@ public function process(DirectoryNode $report, string $target): void
6062
$hasBranchCoverage = $report->numberOfExecutableBranches() > 0;
6163
$hasPathCoverage = $report->numberOfExecutablePaths() > 0;
6264

63-
$builder = new Builder;
64-
$rootNamespace = $builder->build($report);
65-
$fileToClassMap = $this->buildFileToClassMap($rootNamespace);
65+
$fileToClassMap = [];
66+
67+
if ($this->classView) {
68+
$rootNamespace = new Builder()->build($report);
69+
$fileToClassMap = $this->buildFileToClassMap($rootNamespace);
70+
}
6671

6772
$this->renderFileView($report, $target, $date, $hasBranchCoverage, $hasPathCoverage, $fileToClassMap);
68-
$this->renderClassView($rootNamespace, $target, $date, $hasBranchCoverage, $hasPathCoverage);
73+
74+
if (isset($rootNamespace)) {
75+
$this->renderClassView($rootNamespace, $target, $date, $hasBranchCoverage, $hasPathCoverage);
76+
}
77+
6978
$this->copyFiles($target);
7079
$this->renderCss($target);
7180
}
@@ -81,6 +90,12 @@ private function renderFileView(DirectoryNode $report, string $target, string $d
8190

8291
$file->setFileToClassMap($fileToClassMap);
8392

93+
if (!$this->classView) {
94+
$dashboard->disableClassView();
95+
$directory->disableClassView();
96+
$file->disableClassView();
97+
}
98+
8499
$directory->render($report, $target . 'index.html');
85100
$dashboard->render($report, $target . 'dashboard.html');
86101

src/Report/Html/Renderer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ abstract class Renderer
7777
* @var array<string, string>
7878
*/
7979
private array $fileToClassMap = [];
80+
private bool $classView = true;
8081

8182
public function __construct(string $templatePath, string $generator, string $date, Thresholds $thresholds, bool $hasBranchCoverage, bool $hasPathCoverage)
8283
{
@@ -98,6 +99,11 @@ public function setFileToClassMap(array $map): void
9899
$this->fileToClassMap = $map;
99100
}
100101

102+
public function disableClassView(): void
103+
{
104+
$this->classView = false;
105+
}
106+
101107
/**
102108
* @return non-empty-string
103109
*/
@@ -263,7 +269,7 @@ protected function setCommonTemplateVariables(Template $template, AbstractNode $
263269
'generator' => $this->generator,
264270
'low_upper_bound' => (string) $this->thresholds->lowUpperBound(),
265271
'high_lower_bound' => (string) $this->thresholds->highLowerBound(),
266-
'view_switcher' => $this->viewSwitcher($pathToRoot, 'files', 'index.html', $classesTarget),
272+
'view_switcher' => $this->classView ? $this->viewSwitcher($pathToRoot, 'files', 'index.html', $classesTarget) : '',
267273
],
268274
);
269275
}

tests/tests/Report/Html/FacadeTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ public function testProcessRendersFilesInSubdirectoriesAndClassesInNestedNamespa
6464
$this->assertStringContainsString('_classes/App/Models/User.html', $fileHtml);
6565
}
6666

67+
public function testProcessCanSkipTheClassView(): void
68+
{
69+
$target = TEST_FILES_PATH . 'tmp' . DIRECTORY_SEPARATOR;
70+
$report = $this->buildReportWithNestedNamespacesAndSubdirectory();
71+
72+
(new Facade('', null, null, null, false))->process($report, $target);
73+
74+
$this->assertDirectoryDoesNotExist($target . '_classes');
75+
76+
$index = file_get_contents($target . 'index.html');
77+
78+
$this->assertNotFalse($index);
79+
$this->assertStringNotContainsString('_classes/', $index);
80+
$this->assertStringNotContainsString('nav-tabs', $index);
81+
82+
$fileHtml = file_get_contents($target . 'sub/User.php.html');
83+
84+
$this->assertNotFalse($fileHtml);
85+
$this->assertStringNotContainsString('_classes/', $fileHtml);
86+
$this->assertStringNotContainsString('nav-tabs', $fileHtml);
87+
88+
$dashboard = file_get_contents($target . 'dashboard.html');
89+
90+
$this->assertNotFalse($dashboard);
91+
$this->assertStringNotContainsString('_classes/', $dashboard);
92+
$this->assertStringNotContainsString('nav-tabs', $dashboard);
93+
}
94+
6795
private function buildReportWithNestedNamespacesAndSubdirectory(): DirectoryNode
6896
{
6997
$rootPath = TEST_FILES_PATH . 'FacadeNested';

0 commit comments

Comments
 (0)