Skip to content

Commit f3ea9c6

Browse files
Wrap exceptions from php-text-template
1 parent 00fbf1d commit f3ea9c6

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\CodeCoverage\Util;
11+
12+
use RuntimeException;
13+
use SebastianBergmann\CodeCoverage\Exception;
14+
15+
final class FileCouldNotBeWrittenException extends RuntimeException implements Exception
16+
{
17+
}

src/Report/Html/Facade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
use SebastianBergmann\CodeCoverage\CodeCoverage;
1818
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
1919
use SebastianBergmann\CodeCoverage\Report\Thresholds;
20+
use SebastianBergmann\CodeCoverage\Util\FileCouldNotBeWrittenException;
2021
use SebastianBergmann\CodeCoverage\Util\Filesystem;
22+
use SebastianBergmann\Template\Exception;
2123
use SebastianBergmann\Template\Template;
2224

2325
final class Facade
@@ -127,7 +129,15 @@ private function renderCss(string $target): void
127129
]
128130
);
129131

130-
$template->renderTo($this->directory($target . '_css') . 'style.css');
132+
try {
133+
$template->renderTo($this->directory($target . '_css') . 'style.css');
134+
} catch (Exception $e) {
135+
throw new FileCouldNotBeWrittenException(
136+
$e->getMessage(),
137+
$e->getCode(),
138+
$e
139+
);
140+
}
131141
}
132142

133143
private function directory(string $directory): string

src/Report/Html/Renderer/Dashboard.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use function str_replace;
2121
use SebastianBergmann\CodeCoverage\Node\AbstractNode;
2222
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
23+
use SebastianBergmann\CodeCoverage\Util\FileCouldNotBeWrittenException;
24+
use SebastianBergmann\Template\Exception;
2325
use SebastianBergmann\Template\Template;
2426

2527
/**
@@ -58,7 +60,15 @@ public function render(DirectoryNode $node, string $file): void
5860
]
5961
);
6062

61-
$template->renderTo($file);
63+
try {
64+
$template->renderTo($file);
65+
} catch (Exception $e) {
66+
throw new FileCouldNotBeWrittenException(
67+
$e->getMessage(),
68+
$e->getCode(),
69+
$e
70+
);
71+
}
6272
}
6373

6474
protected function activeBreadcrumb(AbstractNode $node): string

src/Report/Html/Renderer/Directory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use function str_repeat;
1515
use SebastianBergmann\CodeCoverage\Node\AbstractNode as Node;
1616
use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
17+
use SebastianBergmann\CodeCoverage\Util\FileCouldNotBeWrittenException;
18+
use SebastianBergmann\Template\Exception;
1719
use SebastianBergmann\Template\Template;
1820

1921
/**
@@ -45,7 +47,15 @@ public function render(DirectoryNode $node, string $file): void
4547
]
4648
);
4749

48-
$template->renderTo($file);
50+
try {
51+
$template->renderTo($file);
52+
} catch (Exception $e) {
53+
throw new FileCouldNotBeWrittenException(
54+
$e->getMessage(),
55+
$e->getCode(),
56+
$e
57+
);
58+
}
4959
}
5060

5161
private function renderItem(Node $node, bool $total = false): string

src/Report/Html/Renderer/File.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
use function token_get_all;
9999
use function trim;
100100
use SebastianBergmann\CodeCoverage\Node\File as FileNode;
101+
use SebastianBergmann\CodeCoverage\Util\FileCouldNotBeWrittenException;
101102
use SebastianBergmann\CodeCoverage\Util\Percentage;
103+
use SebastianBergmann\Template\Exception;
102104
use SebastianBergmann\Template\Template;
103105

104106
/**
@@ -197,7 +199,15 @@ public function render(FileNode $node, string $file): void
197199
]
198200
);
199201

200-
$template->renderTo($file . '.html');
202+
try {
203+
$template->renderTo($file . '.html');
204+
} catch (Exception $e) {
205+
throw new FileCouldNotBeWrittenException(
206+
$e->getMessage(),
207+
$e->getCode(),
208+
$e
209+
);
210+
}
201211

202212
if ($this->hasBranchCoverage) {
203213
$template->setVar(
@@ -209,7 +219,15 @@ public function render(FileNode $node, string $file): void
209219
]
210220
);
211221

212-
$template->renderTo($file . '_branch.html');
222+
try {
223+
$template->renderTo($file . '_branch.html');
224+
} catch (Exception $e) {
225+
throw new FileCouldNotBeWrittenException(
226+
$e->getMessage(),
227+
$e->getCode(),
228+
$e
229+
);
230+
}
213231

214232
$template->setVar(
215233
[
@@ -220,7 +238,15 @@ public function render(FileNode $node, string $file): void
220238
]
221239
);
222240

223-
$template->renderTo($file . '_path.html');
241+
try {
242+
$template->renderTo($file . '_path.html');
243+
} catch (Exception $e) {
244+
throw new FileCouldNotBeWrittenException(
245+
$e->getMessage(),
246+
$e->getCode(),
247+
$e
248+
);
249+
}
224250
}
225251
}
226252

0 commit comments

Comments
 (0)