FileUtils.php 764 B

1234567891011121314151617181920212223242526272829303132
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/diff.
  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\Diff\Utils;
  11. final class FileUtils
  12. {
  13. public static function getFileContent(string $file): string
  14. {
  15. $content = @\file_get_contents($file);
  16. if (false === $content) {
  17. $error = \error_get_last();
  18. throw new \RuntimeException(\sprintf(
  19. 'Failed to read content of file "%s".%s',
  20. $file,
  21. $error ? ' ' . $error['message'] : ''
  22. ));
  23. }
  24. return $content;
  25. }
  26. }