Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesize method can return false but is not detected by Safe #54

Merged
merged 2 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions generated/pcre.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function preg_match_all(string $pattern, string $subject, array &$matches = null
*
*
* If this flag is passed, for every occurring match the appendant string
* offset will also be returned. Note that this changes the value of
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
Expand Down Expand Up @@ -461,7 +461,7 @@ function preg_match_all(string $pattern, string $subject, array &$matches = null
*
*
* If this flag is passed, for every occurring match the appendant string
* offset will also be returned. Note that this changes the value of
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
Expand Down Expand Up @@ -538,7 +538,7 @@ function preg_match_all(string $pattern, string $subject, array &$matches = null
*
* The above example will output:
* @param int $offset If this flag is passed, for every occurring match the appendant string
* offset will also be returned. Note that this changes the value of
* offset (in bytes) will also be returned. Note that this changes the value of
* matches into an array where every element is an
* array consisting of the matched string at offset 0
* and its string offset into subject at offset
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: 2 additions & 0 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ 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/filesystem/functions/filesize.xml');

$this->assertTrue($pregMatch->detectFalsyFunction());
$this->assertFalse($implode->detectFalsyFunction());
$this->assertTrue($getCwd->detectFalsyFunction());
$this->assertTrue($setTime->detectFalsyFunction());
$this->assertTrue($filesize->detectFalsyFunction());
}
}
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