Skip to content

Commit

Permalink
Merge pull request #123 from Kharhamel/moreFallsyCases
Browse files Browse the repository at this point in the history
added support for more fallsy functions: gethostname and getimagesize
  • Loading branch information
Kharhamel authored Jun 25, 2019
2 parents 8e8d99e + f904ee7 commit 4e8f840
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
'iconv_get_encoding',
'iconv_set_encoding',
'iconv',
'getimagesize',
'image2wbmp',
'imageaffine',
'imageaffinematrixconcat',
Expand Down Expand Up @@ -555,6 +556,7 @@
'closelog',
'dns_get_record',
'fsockopen',
'gethostname',
'getprotobyname',
'getprotobynumber',
'header_register_callback',
Expand Down
73 changes: 73 additions & 0 deletions generated/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,79 @@

use Safe\Exceptions\ImageException;

/**
* The getimagesize function will determine the
* size of any supported given image file and return the dimensions along with
* the file type and a height/width text string to be used inside a
* normal HTML IMG tag and the
* correspondent HTTP content type.
*
* getimagesize can also return some more information
* in imageinfo parameter.
*
* @param string $filename This parameter specifies the file you wish to retrieve information
* about. It can reference a local file or (configuration permitting) a
* remote file using one of the supported streams.
* @param array $imageinfo This optional parameter allows you to extract some extended
* information from the image file. Currently, this will return the
* different JPG APP markers as an associative array.
* Some programs use these APP markers to embed text information in
* images. A very common one is to embed
* IPTC information in the APP13 marker.
* You can use the iptcparse function to parse the
* binary APP13 marker into something readable.
*
* The imageinfo only supports
* JFIF files.
* @return array Returns an array with up to 7 elements. Not all image types will include
* the channels and bits elements.
*
* Index 0 and 1 contains respectively the width and the height of the image.
*
* Index 2 is one of the IMAGETYPE_XXX constants indicating
* the type of the image.
*
* Index 3 is a text string with the correct
* height="yyy" width="xxx" string that can be used
* directly in an IMG tag.
*
* mime is the correspondant MIME type of the image.
* This information can be used to deliver images with the correct HTTP
* Content-type header:
*
* getimagesize and MIME types
*
*
* ]]>
*
*
*
* channels will be 3 for RGB pictures and 4 for CMYK
* pictures.
*
* bits is the number of bits for each color.
*
* For some image types, the presence of channels and
* bits values can be a bit
* confusing. As an example, GIF always uses 3 channels
* per pixel, but the number of bits per pixel cannot be calculated for an
* animated GIF with a global color table.
*
* On failure, FALSE is returned.
* @throws ImageException
*
*/
function getimagesize(string $filename, array &$imageinfo = null): array
{
error_clear_last();
$result = \getimagesize($filename, $imageinfo);
if ($result === false) {
throw ImageException::createFromPhpError();
}
return $result;
}


/**
* image2wbmp outputs or save a WBMP
* version of the given image.
Expand Down
20 changes: 20 additions & 0 deletions generated/network.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ function fsockopen(string $hostname, int $port = -1, ?int &$errno = null, ?strin
}


/**
* gethostname gets the standard host name for
* the local machine.
*
* @return string Returns a string with the hostname on success, otherwise FALSE is
* returned.
* @throws NetworkException
*
*/
function gethostname(): string
{
error_clear_last();
$result = \gethostname();
if ($result === false) {
throw NetworkException::createFromPhpError();
}
return $result;
}


/**
* getprotobyname returns the protocol number
* associated with the protocol name as per
Expand Down
6 changes: 6 additions & 0 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public function detectFalsyFunction(): bool
if (preg_match('/Upon\s+failure,?\s+\<function\>[\w_]{1,15}?\<\/function\>\s+returns\s+&false;/m', $file)) {
return true;
}
if (preg_match('/On\s+failure,\s+&false;\s+is\s+returned/m', $file)) {
return true;
}
if (preg_match('/on\s+success,\s+otherwise\s+&false;\s+is\s+returned/m', $file)) {
return true;
}

return false;
}
Expand Down
2 changes: 2 additions & 0 deletions rector-migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ services:
iconv_get_encoding: 'Safe\iconv_get_encoding'
iconv_set_encoding: 'Safe\iconv_set_encoding'
iconv: 'Safe\iconv'
getimagesize: 'Safe\getimagesize'
image2wbmp: 'Safe\image2wbmp'
imageaffine: 'Safe\imageaffine'
imageaffinematrixconcat: 'Safe\imageaffinematrixconcat'
Expand Down Expand Up @@ -558,6 +559,7 @@ services:
closelog: 'Safe\closelog'
dns_get_record: 'Safe\dns_get_record'
fsockopen: 'Safe\fsockopen'
gethostname: 'Safe\gethostname'
getprotobyname: 'Safe\getprotobyname'
getprotobynumber: 'Safe\getprotobynumber'
header_register_callback: 'Safe\header_register_callback'
Expand Down

0 comments on commit 4e8f840

Please sign in to comment.