Skip to content

Commit 4e8f840

Browse files
authored
Merge pull request #123 from Kharhamel/moreFallsyCases
added support for more fallsy functions: gethostname and getimagesize
2 parents 8e8d99e + f904ee7 commit 4e8f840

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

generated/functionsList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
'iconv_get_encoding',
259259
'iconv_set_encoding',
260260
'iconv',
261+
'getimagesize',
261262
'image2wbmp',
262263
'imageaffine',
263264
'imageaffinematrixconcat',
@@ -555,6 +556,7 @@
555556
'closelog',
556557
'dns_get_record',
557558
'fsockopen',
559+
'gethostname',
558560
'getprotobyname',
559561
'getprotobynumber',
560562
'header_register_callback',

generated/image.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,79 @@
44

55
use Safe\Exceptions\ImageException;
66

7+
/**
8+
* The getimagesize function will determine the
9+
* size of any supported given image file and return the dimensions along with
10+
* the file type and a height/width text string to be used inside a
11+
* normal HTML IMG tag and the
12+
* correspondent HTTP content type.
13+
*
14+
* getimagesize can also return some more information
15+
* in imageinfo parameter.
16+
*
17+
* @param string $filename This parameter specifies the file you wish to retrieve information
18+
* about. It can reference a local file or (configuration permitting) a
19+
* remote file using one of the supported streams.
20+
* @param array $imageinfo This optional parameter allows you to extract some extended
21+
* information from the image file. Currently, this will return the
22+
* different JPG APP markers as an associative array.
23+
* Some programs use these APP markers to embed text information in
24+
* images. A very common one is to embed
25+
* IPTC information in the APP13 marker.
26+
* You can use the iptcparse function to parse the
27+
* binary APP13 marker into something readable.
28+
*
29+
* The imageinfo only supports
30+
* JFIF files.
31+
* @return array Returns an array with up to 7 elements. Not all image types will include
32+
* the channels and bits elements.
33+
*
34+
* Index 0 and 1 contains respectively the width and the height of the image.
35+
*
36+
* Index 2 is one of the IMAGETYPE_XXX constants indicating
37+
* the type of the image.
38+
*
39+
* Index 3 is a text string with the correct
40+
* height="yyy" width="xxx" string that can be used
41+
* directly in an IMG tag.
42+
*
43+
* mime is the correspondant MIME type of the image.
44+
* This information can be used to deliver images with the correct HTTP
45+
* Content-type header:
46+
*
47+
* getimagesize and MIME types
48+
*
49+
*
50+
* ]]>
51+
*
52+
*
53+
*
54+
* channels will be 3 for RGB pictures and 4 for CMYK
55+
* pictures.
56+
*
57+
* bits is the number of bits for each color.
58+
*
59+
* For some image types, the presence of channels and
60+
* bits values can be a bit
61+
* confusing. As an example, GIF always uses 3 channels
62+
* per pixel, but the number of bits per pixel cannot be calculated for an
63+
* animated GIF with a global color table.
64+
*
65+
* On failure, FALSE is returned.
66+
* @throws ImageException
67+
*
68+
*/
69+
function getimagesize(string $filename, array &$imageinfo = null): array
70+
{
71+
error_clear_last();
72+
$result = \getimagesize($filename, $imageinfo);
73+
if ($result === false) {
74+
throw ImageException::createFromPhpError();
75+
}
76+
return $result;
77+
}
78+
79+
780
/**
881
* image2wbmp outputs or save a WBMP
982
* version of the given image.

generated/network.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,26 @@ function fsockopen(string $hostname, int $port = -1, ?int &$errno = null, ?strin
315315
}
316316

317317

318+
/**
319+
* gethostname gets the standard host name for
320+
* the local machine.
321+
*
322+
* @return string Returns a string with the hostname on success, otherwise FALSE is
323+
* returned.
324+
* @throws NetworkException
325+
*
326+
*/
327+
function gethostname(): string
328+
{
329+
error_clear_last();
330+
$result = \gethostname();
331+
if ($result === false) {
332+
throw NetworkException::createFromPhpError();
333+
}
334+
return $result;
335+
}
336+
337+
318338
/**
319339
* getprotobyname returns the protocol number
320340
* associated with the protocol name as per

generator/src/DocPage.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public function detectFalsyFunction(): bool
9393
if (preg_match('/Upon\s+failure,?\s+\<function\>[\w_]{1,15}?\<\/function\>\s+returns\s+&false;/m', $file)) {
9494
return true;
9595
}
96+
if (preg_match('/On\s+failure,\s+&false;\s+is\s+returned/m', $file)) {
97+
return true;
98+
}
99+
if (preg_match('/on\s+success,\s+otherwise\s+&false;\s+is\s+returned/m', $file)) {
100+
return true;
101+
}
96102

97103
return false;
98104
}

rector-migrate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ services:
261261
iconv_get_encoding: 'Safe\iconv_get_encoding'
262262
iconv_set_encoding: 'Safe\iconv_set_encoding'
263263
iconv: 'Safe\iconv'
264+
getimagesize: 'Safe\getimagesize'
264265
image2wbmp: 'Safe\image2wbmp'
265266
imageaffine: 'Safe\imageaffine'
266267
imageaffinematrixconcat: 'Safe\imageaffinematrixconcat'
@@ -558,6 +559,7 @@ services:
558559
closelog: 'Safe\closelog'
559560
dns_get_record: 'Safe\dns_get_record'
560561
fsockopen: 'Safe\fsockopen'
562+
gethostname: 'Safe\gethostname'
561563
getprotobyname: 'Safe\getprotobyname'
562564
getprotobynumber: 'Safe\getprotobynumber'
563565
header_register_callback: 'Safe\header_register_callback'

0 commit comments

Comments
 (0)