Skip to content

Commit

Permalink
Adding filesize method
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Oct 30, 2018
1 parent d66f87f commit 31d2c13
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions generated/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ function fileowner(string $filename): int
}


/**
* Gets the size for the given file.
*
* @param string $filename Path to the file.
* @return int Returns the size of the file in bytes, or FALSE (and generates an error
* of level E_WARNING) in case of an error.
* @throws FilesystemException
*
*/
function filesize(string $filename): int
{
error_clear_last();
$result = \filesize($filename);
if ($result === false) {
throw FilesystemException::createFromPhpError();
}
return $result;
}


/**
* flock allows you to perform a simple reader/writer
* model which can be used on virtually every platform (including most Unix
Expand Down
1 change: 1 addition & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
'fileinode',
'filemtime',
'fileowner',
'filesize',
'flock',
'fopen',
'fputcsv',
Expand Down
3 changes: 3 additions & 0 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function detectFalsyFunction(): bool
if (preg_match('/&date.datetime.return.modifiedobjectorfalseforfailure;/m', $file)) {
return true;
}
if (preg_match('/ or &false; \\(and generates an error/m', $file)) {
return true;
}

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testDetectFalsyFunction() {
$implode = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/strings/functions/implode.xml');
$getCwd = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/dir/functions/getcwd.xml');
$setTime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/datetime/settime.xml');
$filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/filesystem/filesize.xml');
$filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/filesystem/functions/filesize.xml');

$this->assertTrue($pregMatch->detectFalsyFunction());
$this->assertFalse($implode->detectFalsyFunction());
Expand Down
1 change: 1 addition & 0 deletions rector-migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ services:
fileinode: 'Safe\fileinode'
filemtime: 'Safe\filemtime'
fileowner: 'Safe\fileowner'
filesize: 'Safe\filesize'
flock: 'Safe\flock'
fopen: 'Safe\fopen'
fputcsv: 'Safe\fputcsv'
Expand Down

0 comments on commit 31d2c13

Please # to comment.