Skip to content

Commit

Permalink
Fix: Initialize properties in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 28, 2021
1 parent f7170ad commit 735e059
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions test/Util/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,44 @@
final class File
{
private string $path;
private bool $exists = false;
private bool $exists;
private ?string $contents;

private function __construct()
{
private function __construct(
string $path,
bool $exists,
?string $contents
) {
$this->path = $path;
$this->exists = $exists;
$this->contents = $contents;
}

public static function fromPath(string $path): self
{
$file = new self();

$file->path = $path;

if (\file_exists($path)) {
$file->exists = true;
if (!\file_exists($path)) {
return new self(
$path,
false,
null,
);
}

$contents = \file_get_contents($path);
$contents = \file_get_contents($path);

if (\is_string($contents)) {
$file->contents = $contents;
}
if (!\is_string($contents)) {
return new self(
$path,
true,
null,
);
}

return $file;
return new self(
$path,
true,
$contents,
);
}

public function path(): string
Expand Down

0 comments on commit 735e059

Please sign in to comment.