Filesystem.php 1019 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-code-coverage.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  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. use function is_dir;
  12. use function mkdir;
  13. use function sprintf;
  14. /**
  15. * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
  16. */
  17. final class Filesystem
  18. {
  19. /**
  20. * @throws DirectoryCouldNotBeCreatedException
  21. */
  22. public static function createDirectory(string $directory): void
  23. {
  24. $success = !(!is_dir($directory) && !@mkdir($directory, 0o777, true) && !is_dir($directory));
  25. if (!$success) {
  26. throw new DirectoryCouldNotBeCreatedException(
  27. sprintf(
  28. 'Directory "%s" could not be created',
  29. $directory,
  30. ),
  31. );
  32. }
  33. }
  34. }