Skip to content

Commit a1de956

Browse files
authored
Merge pull request #84 from moufmouf/fsockopen
Adding fsockopen to list of supported functions
2 parents 5687cf3 + ff04234 commit a1de956

File tree

12 files changed

+72
-24
lines changed

12 files changed

+72
-24
lines changed

generated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@
548548
'mysqlnd_qc_set_storage_handler',
549549
'closelog',
550550
'dns_get_record',
551+
'fsockopen',
551552
'getprotobyname',
552553
'getprotobynumber',
553554
'header_register_callback',

generated/network.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,65 @@ function dns_get_record(string $hostname, int $type = DNS_ANY, array &$authns =
253253
}
254254

255255

256+
/**
257+
* Initiates a socket connection to the resource specified by
258+
* hostname.
259+
*
260+
* PHP supports targets in the Internet and Unix domains as described in
261+
* . A list of supported transports can also be
262+
* retrieved using stream_get_transports.
263+
*
264+
* The socket will by default be opened in blocking mode. You can
265+
* switch it to non-blocking mode by using
266+
* stream_set_blocking.
267+
*
268+
* The function stream_socket_client is similar but
269+
* provides a richer set of options, including non-blocking connection and the
270+
* ability to provide a stream context.
271+
*
272+
* @param string $hostname If OpenSSL support is
273+
* installed, you may prefix the hostname
274+
* with either ssl:// or tls:// to
275+
* use an SSL or TLS client connection over TCP/IP to connect to the
276+
* remote host.
277+
* @param int $port The port number. This can be omitted and skipped with
278+
* -1 for transports that do not use ports, such as
279+
* unix://.
280+
* @param int $errno If provided, holds the system level error number that occurred in the
281+
* system-level connect() call.
282+
*
283+
* If the value returned in errno is
284+
* 0 and the function returned FALSE, it is an
285+
* indication that the error occurred before the
286+
* connect() call. This is most likely due to a
287+
* problem initializing the socket.
288+
* @param string $errstr The error message as a string.
289+
* @param float $timeout The connection timeout, in seconds.
290+
*
291+
* If you need to set a timeout for reading/writing data over the
292+
* socket, use stream_set_timeout, as the
293+
* timeout parameter to
294+
* fsockopen only applies while connecting the
295+
* socket.
296+
* @return resource fsockopen returns a file pointer which may be used
297+
* together with the other file functions (such as
298+
* fgets, fgetss,
299+
* fwrite, fclose, and
300+
* feof). If the call fails, it will return FALSE
301+
* @throws NetworkException
302+
*
303+
*/
304+
function fsockopen(string $hostname, int $port = -1, int &$errno = null, string &$errstr = null, float $timeout = null)
305+
{
306+
error_clear_last();
307+
$result = \fsockopen($hostname, $port, $errno, $errstr, $timeout);
308+
if ($result === false) {
309+
throw NetworkException::createFromPhpError();
310+
}
311+
return $result;
312+
}
313+
314+
256315
/**
257316
* getprotobyname returns the protocol number
258317
* associated with the protocol name as per

generator/src/DocPage.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public function detectFalsyFunction(): bool
3232

3333
if (preg_match('/&warn\.deprecated\.function-(\d+-\d+-\d+)\.removed-(\d+-\d+-\d+)/', $file, $matches)) {
3434
$removedVersion = $matches[2];
35-
[$major, $minor, $fix] = explode('-', $removedVersion);
35+
[$major, $minor] = explode('-', $removedVersion);
3636
if ($major < 7 || ($major == 7 && $minor == 0)) {
3737
// Ignore function if it was removed before PHP 7.1
3838
return false;
3939
}
4040
}
4141
if (preg_match('/&warn\.removed\.function-(\d+-\d+-\d+)/', $file, $matches) && isset($matches[2])) {
4242
$removedVersion = $matches[2];
43-
[$major, $minor, $fix] = explode('-', $removedVersion);
43+
[$major, $minor] = explode('-', $removedVersion);
4444
if ($major < 7 || ($major == 7 && $minor == 0)) {
4545
// Ignore function if it was removed before PHP 7.1
4646
return false;
@@ -77,6 +77,9 @@ public function detectFalsyFunction(): bool
7777
if (preg_match('/&false;\s+if\s+the\s+number\s+of\s+elements\s+for\s+each\s+array\s+isn\'t\s+equal/m', $file)) {
7878
return true;
7979
}
80+
if (preg_match('/If\s+the\s+call\s+fails,\s+it\s+will\s+return\s+&false;/m', $file)) {
81+
return true;
82+
}
8083

8184
return false;
8285
}

generator/src/FileCreator.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
use function file_exists;
88
use PhpOffice\PhpSpreadsheet\Spreadsheet;
99
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
10-
use function ucfirst;
1110

1211
class FileCreator
1312
{
14-
public function __construct()
15-
{
16-
}
17-
1813
/**
1914
* This function generate an xls file
2015
*
@@ -25,7 +20,6 @@ public function generateXlsFile(array $protoFunctions, string $path): void
2520
{
2621
$spreadsheet = new Spreadsheet();
2722
$numb = 1;
28-
$status = '';
2923

3024
$sheet = $spreadsheet->getActiveSheet();
3125
$sheet->setCellValue('A1', 'Function name');

generator/src/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getParams(): array
7575

7676
if (preg_match('/This parameter has been removed in PHP (\d+\.\d+\.\d+)/', $notes, $matches)) {
7777
$removedVersion = $matches[1];
78-
[$major, $minor, $fix] = explode('.', $removedVersion);
78+
[$major, $minor] = explode('.', $removedVersion);
7979
if ($major < 7 || ($major == 7 && $minor == 0)) {
8080
// Ignore parameter if it was removed before PHP 7.1
8181
continue;

generator/src/Parameter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Safe;
33

44
use Safe\PhpStanFunctions\PhpStanFunction;
5-
use Safe\PhpStanFunctions\PhpStanFunctionMapReader;
65

76
class Parameter
87
{

generator/src/PhpStanFunctions/PhpStanFunctionMapReader.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
namespace Safe\PhpStanFunctions;
55

6-
use Safe\PhpStanFunctions\PhpStanFunction;
7-
86
class PhpStanFunctionMapReader
97
{
108
/**

generator/src/ScanObjectsCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
9-
use Symfony\Component\Process\Process;
109

1110
class ScanObjectsCommand extends Command
1211
{

generator/src/WritePhpFunction.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
namespace Safe;
44

5-
use function in_array;
6-
use function is_numeric;
7-
use function strtolower;
8-
use function strtoupper;
9-
use function var_export;
10-
115
class WritePhpFunction
126
{
137
/**
@@ -27,9 +21,8 @@ public function getPhpPrototypeFunction(): string
2721
{
2822
if ($this->method->getFunctionName()) {
2923
return 'function '.$this->method->getFunctionName().'('.$this->displayParamsWithType($this->method->getParams()).')'.': '.$this->method->getReturnType().'{}';
30-
} else {
31-
return '';
3224
}
25+
return '';
3326
}
3427

3528
/*

generator/tests/DocPageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function testDetectFalsyFunction() {
1414
$filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/filesystem/functions/filesize.xml');
1515
$sessionRegister = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/session/functions/session-register.xml');
1616
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
17+
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');
1718

1819
$this->assertTrue($pregMatch->detectFalsyFunction());
1920
$this->assertFalse($implode->detectFalsyFunction());
@@ -22,5 +23,6 @@ public function testDetectFalsyFunction() {
2223
$this->assertTrue($filesize->detectFalsyFunction());
2324
$this->assertFalse($sessionRegister->detectFalsyFunction());
2425
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
26+
$this->assertTrue($fsockopen->detectFalsyFunction());
2527
}
2628
}

0 commit comments

Comments
 (0)