function FileOutput::__construct

Same name and namespace in other branches
  1. 11.x core/tests/PHPStan/ErrorFormatter/FileOutput.php \Drupal\PHPStan\ErrorFormatter\FileOutput::__construct()

Constructs a FileOutput.

Parameters

string $filePath: The path to the output file.

\PHPStan\Command\OutputStyle $outputStyle: The output style.

File

core/tests/PHPStan/ErrorFormatter/FileOutput.php, line 32

Class

FileOutput
Output implementation that writes to a file.

Namespace

Drupal\PHPStan\ErrorFormatter

Code

public function __construct(string $filePath, private OutputStyle $outputStyle) {
  $directory = dirname($filePath);
  if ($directory && $directory !== 'php:' && !is_dir($directory)) {
    mkdir($directory, 0777, TRUE);
  }
  $handle = fopen($filePath, 'w');
  if ($handle === FALSE) {
    throw new \RuntimeException(sprintf('Unable to open file for writing: %s', $filePath));
  }
  $this->handle = $handle;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.