Skip to content

Commit

Permalink
Create directory in PHP report
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and sebastianbergmann committed Jul 18, 2018
1 parent 8656625 commit f4181f5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Report/PHP.php
Expand Up @@ -46,6 +46,10 @@ public function process(CodeCoverage $coverage, ?string $target = null): string
);

if ($target !== null) {
if (!$this->createDirectory(\dirname($target))) {
throw new \RuntimeException(\sprintf('Directory "%s" was not created', \dirname($target)));
}

if (@\file_put_contents($target, $buffer) === false) {
throw new RuntimeException(
\sprintf(
Expand All @@ -58,4 +62,9 @@ public function process(CodeCoverage $coverage, ?string $target = null): string

return $buffer;
}

private function createDirectory(string $directory): bool
{
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
}
}

0 comments on commit f4181f5

Please sign in to comment.