Skip to content

Commit d197ab3

Browse files
Eliminate code duplication
1 parent 7c89093 commit d197ab3

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/Util/Filesystem.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ public static function classNameToFilename(string $className): string
2727
$className
2828
) . '.php';
2929
}
30+
31+
public static function createDirectory(string $directory): bool
32+
{
33+
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
34+
}
3035
}

src/Util/Printer.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct($out = null)
5353

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

@@ -132,9 +132,4 @@ public function setAutoFlush(bool $autoFlush): void
132132
{
133133
$this->autoFlush = $autoFlush;
134134
}
135-
136-
private function createDirectory(string $directory): bool
137-
{
138-
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
139-
}
140135
}

src/Util/TestResultCache.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\Runner;
1111

1212
use PHPUnit\Framework\Test;
13+
use PHPUnit\Util\Filesystem;
1314

1415
class TestResultCache implements \Serializable, TestResultCacheInterface
1516
{
@@ -79,7 +80,7 @@ public function saveToFile(): void
7980
return;
8081
}
8182

82-
if (!$this->createDirectory(\dirname($this->cacheFilename))) {
83+
if (!Filesystem::createDirectory(\dirname($this->cacheFilename))) {
8384
throw new Exception(
8485
\sprintf(
8586
'Cannot create directory "%s" for result cache file',
@@ -187,9 +188,4 @@ public function unserialize($serialized): void
187188
}
188189
}
189190
}
190-
191-
private function createDirectory(string $directory): bool
192-
{
193-
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
194-
}
195191
}

0 commit comments

Comments
 (0)