Skip to content

Commit

Permalink
Merge pull request #84 from moufmouf/fsockopen
Browse files Browse the repository at this point in the history
Adding fsockopen to list of supported functions
  • Loading branch information
moufmouf committed Jan 23, 2019
2 parents 5687cf3 + ff04234 commit a1de956
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 24 deletions.
1 change: 1 addition & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@
'mysqlnd_qc_set_storage_handler',
'closelog',
'dns_get_record',
'fsockopen',
'getprotobyname',
'getprotobynumber',
'header_register_callback',
Expand Down
59 changes: 59 additions & 0 deletions generated/network.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,65 @@ function dns_get_record(string $hostname, int $type = DNS_ANY, array &$authns =
}


/**
* Initiates a socket connection to the resource specified by
* hostname.
*
* PHP supports targets in the Internet and Unix domains as described in
* . A list of supported transports can also be
* retrieved using stream_get_transports.
*
* The socket will by default be opened in blocking mode. You can
* switch it to non-blocking mode by using
* stream_set_blocking.
*
* The function stream_socket_client is similar but
* provides a richer set of options, including non-blocking connection and the
* ability to provide a stream context.
*
* @param string $hostname If OpenSSL support is
* installed, you may prefix the hostname
* with either ssl:// or tls:// to
* use an SSL or TLS client connection over TCP/IP to connect to the
* remote host.
* @param int $port The port number. This can be omitted and skipped with
* -1 for transports that do not use ports, such as
* unix://.
* @param int $errno If provided, holds the system level error number that occurred in the
* system-level connect() call.
*
* If the value returned in errno is
* 0 and the function returned FALSE, it is an
* indication that the error occurred before the
* connect() call. This is most likely due to a
* problem initializing the socket.
* @param string $errstr The error message as a string.
* @param float $timeout The connection timeout, in seconds.
*
* If you need to set a timeout for reading/writing data over the
* socket, use stream_set_timeout, as the
* timeout parameter to
* fsockopen only applies while connecting the
* socket.
* @return resource fsockopen returns a file pointer which may be used
* together with the other file functions (such as
* fgets, fgetss,
* fwrite, fclose, and
* feof). If the call fails, it will return FALSE
* @throws NetworkException
*
*/
function fsockopen(string $hostname, int $port = -1, int &$errno = null, string &$errstr = null, float $timeout = null)
{
error_clear_last();
$result = \fsockopen($hostname, $port, $errno, $errstr, $timeout);
if ($result === false) {
throw NetworkException::createFromPhpError();
}
return $result;
}


/**
* getprotobyname returns the protocol number
* associated with the protocol name as per
Expand Down
7 changes: 5 additions & 2 deletions generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function detectFalsyFunction(): bool

if (preg_match('/&warn\.deprecated\.function-(\d+-\d+-\d+)\.removed-(\d+-\d+-\d+)/', $file, $matches)) {
$removedVersion = $matches[2];
[$major, $minor, $fix] = explode('-', $removedVersion);
[$major, $minor] = explode('-', $removedVersion);
if ($major < 7 || ($major == 7 && $minor == 0)) {
// Ignore function if it was removed before PHP 7.1
return false;
}
}
if (preg_match('/&warn\.removed\.function-(\d+-\d+-\d+)/', $file, $matches) && isset($matches[2])) {
$removedVersion = $matches[2];
[$major, $minor, $fix] = explode('-', $removedVersion);
[$major, $minor] = explode('-', $removedVersion);
if ($major < 7 || ($major == 7 && $minor == 0)) {
// Ignore function if it was removed before PHP 7.1
return false;
Expand Down Expand Up @@ -77,6 +77,9 @@ public function detectFalsyFunction(): bool
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)) {
return true;
}
if (preg_match('/If\s+the\s+call\s+fails,\s+it\s+will\s+return\s+&false;/m', $file)) {
return true;
}

return false;
}
Expand Down
6 changes: 0 additions & 6 deletions generator/src/FileCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
use function file_exists;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use function ucfirst;

class FileCreator
{
public function __construct()
{
}

/**
* This function generate an xls file
*
Expand All @@ -25,7 +20,6 @@ public function generateXlsFile(array $protoFunctions, string $path): void
{
$spreadsheet = new Spreadsheet();
$numb = 1;
$status = '';

$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Function name');
Expand Down
2 changes: 1 addition & 1 deletion generator/src/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getParams(): array

if (preg_match('/This parameter has been removed in PHP (\d+\.\d+\.\d+)/', $notes, $matches)) {
$removedVersion = $matches[1];
[$major, $minor, $fix] = explode('.', $removedVersion);
[$major, $minor] = explode('.', $removedVersion);
if ($major < 7 || ($major == 7 && $minor == 0)) {
// Ignore parameter if it was removed before PHP 7.1
continue;
Expand Down
1 change: 0 additions & 1 deletion generator/src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Safe;

use Safe\PhpStanFunctions\PhpStanFunction;
use Safe\PhpStanFunctions\PhpStanFunctionMapReader;

class Parameter
{
Expand Down
2 changes: 0 additions & 2 deletions generator/src/PhpStanFunctions/PhpStanFunctionMapReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Safe\PhpStanFunctions;

use Safe\PhpStanFunctions\PhpStanFunction;

class PhpStanFunctionMapReader
{
/**
Expand Down
1 change: 0 additions & 1 deletion generator/src/ScanObjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

class ScanObjectsCommand extends Command
{
Expand Down
9 changes: 1 addition & 8 deletions generator/src/WritePhpFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

namespace Safe;

use function in_array;
use function is_numeric;
use function strtolower;
use function strtoupper;
use function var_export;

class WritePhpFunction
{
/**
Expand All @@ -27,9 +21,8 @@ public function getPhpPrototypeFunction(): string
{
if ($this->method->getFunctionName()) {
return 'function '.$this->method->getFunctionName().'('.$this->displayParamsWithType($this->method->getParams()).')'.': '.$this->method->getReturnType().'{}';
} else {
return '';
}
return '';
}

/*
Expand Down
2 changes: 2 additions & 0 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testDetectFalsyFunction() {
$filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/filesystem/functions/filesize.xml');
$sessionRegister = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/session/functions/session-register.xml');
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');

$this->assertTrue($pregMatch->detectFalsyFunction());
$this->assertFalse($implode->detectFalsyFunction());
Expand All @@ -22,5 +23,6 @@ public function testDetectFalsyFunction() {
$this->assertTrue($filesize->detectFalsyFunction());
$this->assertFalse($sessionRegister->detectFalsyFunction());
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
$this->assertTrue($fsockopen->detectFalsyFunction());
}
}
5 changes: 2 additions & 3 deletions lib/special_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,22 @@ function apcu_fetch($key)
* -1 (no limit).
* @param int $count If specified, this variable will be filled with the number of
* replacements done.
* @return string|array|null preg_replace returns an array if the
* @return string|array preg_replace returns an array if the
* subject parameter is an array, or a string
* otherwise.
*
* If matches are found, the new subject will
* be returned, otherwise subject will be
* returned unchanged.
*
* Returns a file pointer resource on success, .
* @throws PcreException
*
*/
function preg_replace($pattern, $replacement, $subject, int $limit = -1, int &$count = null)
{
error_clear_last();
$result = \preg_replace($pattern, $replacement, $subject, $limit, $count);
if (preg_last_error() !== PREG_NO_ERROR) {
if (preg_last_error() !== PREG_NO_ERROR || $result === null) {
throw PcreException::createFromPhpError();
}
return $result;
Expand Down
1 change: 1 addition & 0 deletions rector-migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ services:
mysqlnd_qc_set_storage_handler: 'Safe\mysqlnd_qc_set_storage_handler'
closelog: 'Safe\closelog'
dns_get_record: 'Safe\dns_get_record'
fsockopen: 'Safe\fsockopen'
getprotobyname: 'Safe\getprotobyname'
getprotobynumber: 'Safe\getprotobynumber'
header_register_callback: 'Safe\header_register_callback'
Expand Down

0 comments on commit a1de956

Please sign in to comment.