Skip to content

Commit e519626

Browse files
authored
Merge pull request #276 from ideag/enhancement/file-get-contents
Replace `fopen`/`fread` with `file_get_contents`
2 parents ea6d0c5 + d54de21 commit e519626

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

src/Loader/Loader.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ protected function createTranslation(?string $context, string $original, string
4545
*/
4646
protected static function readFile(string $file): string
4747
{
48-
$length = filesize($file);
49-
50-
if (!($fd = fopen($file, 'rb'))) {
48+
$content = @file_get_contents($file);
49+
50+
if (false === $content) {
5151
throw new Exception("Cannot read the file '$file', probably permissions");
5252
}
5353

54-
$content = $length ? fread($fd, $length) : '';
55-
fclose($fd);
56-
5754
return $content;
5855
}
5956
}

src/Scanner/Scanner.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,12 @@ protected function saveTranslation(
7777
*/
7878
protected static function readFile(string $file): string
7979
{
80-
$length = filesize($file);
80+
$content = @file_get_contents($file);
8181

82-
if (!($fd = fopen($file, 'rb'))) {
82+
if (false === $content) {
8383
throw new Exception("Cannot read the file '$file', probably permissions");
8484
}
85-
86-
$content = $length ? fread($fd, $length) : '';
87-
fclose($fd);
88-
85+
8986
return $content;
9087
}
9188
}

0 commit comments

Comments
 (0)