Skip to content

Commit

Permalink
Eliminate code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 15, 2019
1 parent 7c89093 commit d197ab3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/Util/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public static function classNameToFilename(string $className): string
$className
) . '.php';
}

public static function createDirectory(string $directory): bool
{
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
}
}
7 changes: 1 addition & 6 deletions src/Util/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct($out = null)

$this->out = \fsockopen($out[0], $out[1]);
} else {
if (\strpos($out, 'php://') === false && !$this->createDirectory(\dirname($out))) {
if (\strpos($out, 'php://') === false && !Filesystem::createDirectory(\dirname($out))) {
throw new Exception(\sprintf('Directory "%s" was not created', \dirname($out)));
}

Expand Down Expand Up @@ -132,9 +132,4 @@ public function setAutoFlush(bool $autoFlush): void
{
$this->autoFlush = $autoFlush;
}

private function createDirectory(string $directory): bool
{
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
}
}
8 changes: 2 additions & 6 deletions src/Util/TestResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PHPUnit\Runner;

use PHPUnit\Framework\Test;
use PHPUnit\Util\Filesystem;

class TestResultCache implements \Serializable, TestResultCacheInterface
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function saveToFile(): void
return;
}

if (!$this->createDirectory(\dirname($this->cacheFilename))) {
if (!Filesystem::createDirectory(\dirname($this->cacheFilename))) {
throw new Exception(
\sprintf(
'Cannot create directory "%s" for result cache file',
Expand Down Expand Up @@ -187,9 +188,4 @@ public function unserialize($serialized): void
}
}
}

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

0 comments on commit d197ab3

Please sign in to comment.