Skip to content

Commit

Permalink
Merge pull request #336 from thecodingmachine/removeNUmbers
Browse files Browse the repository at this point in the history
FIX: the generator now ignore the number typehints from phpstan
  • Loading branch information
Kharhamel authored Mar 30, 2022
2 parents 68096ae + 9865ec0 commit c4919cd
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 24 deletions.
29 changes: 29 additions & 0 deletions generated/exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ function exec(string $command, ?array &$output = null, ?int &$result_code = null
}


/**
* The passthru function is similar to the
* exec function in that it executes a
* command. This function
* should be used in place of exec or
* system when the output from the Unix command
* is binary data which needs to be passed directly back to the
* browser. A common use for this is to execute something like the
* pbmplus utilities that can output an image stream directly. By
* setting the Content-type to image/gif and
* then calling a pbmplus program to output a gif, you can create
* PHP scripts that output images directly.
*
* @param string $command The command that will be executed.
* @param int|null $result_code If the result_code argument is present, the
* return status of the Unix command will be placed here.
* @throws ExecException
*
*/
function passthru(string $command, ?int &$result_code = null): void
{
error_clear_last();
$result = \passthru($command, $result_code);
if ($result === false) {
throw ExecException::createFromPhpError();
}
}


/**
* proc_nice changes the priority of the current
* process by the amount specified in priority. A
Expand Down
34 changes: 17 additions & 17 deletions generated/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function fflush($stream): void
* @param resource $stream A valid file pointer to a file successfully opened by
* fopen, popen, or
* fsockopen.
* @param \0|int $length Must be greater than the longest line (in characters) to be found in
* @param int $length Must be greater than the longest line (in characters) to be found in
* the CSV file (allowing for trailing line-end characters). Otherwise the
* line is split in chunks of length characters,
* unless the split would occur inside an enclosure.
Expand All @@ -251,7 +251,7 @@ function fflush($stream): void
* @throws FilesystemException
*
*/
function fgetcsv($stream, $length = null, string $separator = ",", string $enclosure = "\"", string $escape = "\\")
function fgetcsv($stream, int $length = null, string $separator = ",", string $enclosure = "\"", string $escape = "\\")
{
error_clear_last();
if ($escape !== "\\") {
Expand Down Expand Up @@ -299,14 +299,14 @@ function fgetcsv($stream, $length = null, string $separator = ",", string $enclo
* Seeking (offset) is not supported with remote files.
* Attempting to seek on non-local files may work with small offsets, but this
* is unpredictable because it works on the buffered stream.
* @param \0|int $length Maximum length of data read. The default is to read until end
* @param int $length Maximum length of data read. The default is to read until end
* of file is reached. Note that this parameter is applied to the
* stream processed by the filters.
* @return string The function returns the read data.
* @throws FilesystemException
*
*/
function file_get_contents(string $filename, bool $use_include_path = false, $context = null, int $offset = 0, $length = null): string
function file_get_contents(string $filename, bool $use_include_path = false, $context = null, int $offset = 0, int $length = null): string
{
error_clear_last();
if ($length !== null) {
Expand Down Expand Up @@ -395,11 +395,11 @@ function file_get_contents(string $filename, bool $use_include_path = false, $co
*
* @param resource|null $context A valid context resource created with
* stream_context_create.
* @return \0|int This function returns the number of bytes that were written to the file.
* @return int This function returns the number of bytes that were written to the file.
* @throws FilesystemException
*
*/
function file_put_contents(string $filename, $data, int $flags = 0, $context = null)
function file_put_contents(string $filename, $data, int $flags = 0, $context = null): int
{
error_clear_last();
if ($context !== null) {
Expand Down Expand Up @@ -613,12 +613,12 @@ function fileperms(string $filename): int
* Gets the size for the given file.
*
* @param string $filename Path to the file.
* @return \0|int Returns the size of the file in bytes, or FALSE (and generates an error
* @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)
function filesize(string $filename): int
{
error_clear_last();
$result = \filesize($filename);
Expand Down Expand Up @@ -929,12 +929,12 @@ function fopen(string $filename, string $mode, bool $use_include_path = false, $
*
* @param resource $stream A file system pointer resource
* that is typically created using fopen.
* @param \0|int $length Up to length number of bytes read.
* @param int $length Up to length number of bytes read.
* @return string Returns the read string.
* @throws FilesystemException
*
*/
function fread($stream, $length): string
function fread($stream, int $length): string
{
error_clear_last();
$result = \fread($stream, $length);
Expand Down Expand Up @@ -998,7 +998,7 @@ function fsync($stream): void
* @param resource $stream The file pointer.
*
* The stream must be open for writing.
* @param \0|int $size The size to truncate to.
* @param int $size The size to truncate to.
*
* If size is larger than the file then the file
* is extended with null bytes.
Expand All @@ -1008,7 +1008,7 @@ function fsync($stream): void
* @throws FilesystemException
*
*/
function ftruncate($stream, $size): void
function ftruncate($stream, int $size): void
{
error_clear_last();
$result = \ftruncate($stream, $size);
Expand All @@ -1024,14 +1024,14 @@ function ftruncate($stream, $size): void
* @param resource $stream A file system pointer resource
* that is typically created using fopen.
* @param string $data The string that is to be written.
* @param \0|int $length If length is an integer, writing will stop
* @param int $length If length is an integer, writing will stop
* after length bytes have been written or the
* end of data is reached, whichever comes first.
* @return \0|int
* @return int
* @throws FilesystemException
*
*/
function fwrite($stream, string $data, $length = null)
function fwrite($stream, string $data, int $length = null): int
{
error_clear_last();
if ($length !== null) {
Expand Down Expand Up @@ -1356,11 +1356,11 @@ function parse_ini_string(string $ini_string, bool $process_sections = false, in
* you want to search for the file in the include_path, too.
* @param resource $context A context stream
* resource.
* @return \0|int Returns the number of bytes read from the file on success
* @return int Returns the number of bytes read from the file on success
* @throws FilesystemException
*
*/
function readfile(string $filename, bool $use_include_path = false, $context = null)
function readfile(string $filename, bool $use_include_path = false, $context = null): int
{
error_clear_last();
if ($context !== null) {
Expand Down
1 change: 1 addition & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@
'parse_ini_file',
'parse_ini_string',
'parse_url',
'passthru',
'pcntl_getpriority',
'pcntl_setpriority',
'pcntl_signal',
Expand Down
4 changes: 2 additions & 2 deletions generated/openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,12 @@ function openssl_spki_verify(string $spki): void
* @param int|string $algorithm int - one of these Signature Algorithms.
*
* string - a valid string returned by openssl_get_md_methods example, "sha1WithRSAEncryption" or "sha512".
* @return \-1|\0|\1 Returns 1 if the signature is correct, 0 if it is incorrect, and
* @return int Returns 1 if the signature is correct, 0 if it is incorrect, and
* -1.
* @throws OpensslException
*
*/
function openssl_verify(string $data, string $signature, $public_key, $algorithm = OPENSSL_ALGO_SHA1)
function openssl_verify(string $data, string $signature, $public_key, $algorithm = OPENSSL_ALGO_SHA1): int
{
error_clear_last();
$result = \openssl_verify($data, $signature, $public_key, $algorithm);
Expand Down
4 changes: 2 additions & 2 deletions generated/pcre.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ function preg_grep(string $pattern, array $array, int $flags = 0): array
*
*
* The above example will output:
* @return \0|int|null Returns the number of full pattern matches (which might be zero).
* @return int|null Returns the number of full pattern matches (which might be zero).
* @throws PcreException
*
*/
function preg_match_all(string $pattern, string $subject, ?array &$matches = null, int $flags = 0, int $offset = 0)
function preg_match_all(string $pattern, string $subject, ?array &$matches = null, int $flags = 0, int $offset = 0): ?int
{
error_clear_last();
$result = \preg_match_all($pattern, $subject, $matches, $flags, $offset);
Expand Down
4 changes: 2 additions & 2 deletions generated/zlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,11 @@ function inflate_init(int $encoding, array $options = [])
* contents written to standard output.
* @param int $use_include_path You can set this optional parameter to 1, if you
* want to search for the file in the include_path too.
* @return \0|int Returns the number of (uncompressed) bytes read from the file on success
* @return int Returns the number of (uncompressed) bytes read from the file on success
* @throws ZlibException
*
*/
function readgzfile(string $filename, int $use_include_path = 0)
function readgzfile(string $filename, int $use_include_path = 0): int
{
error_clear_last();
$result = \readgzfile($filename, $use_include_path);
Expand Down
4 changes: 3 additions & 1 deletion generator/src/PhpStanFunctions/PhpStanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ public function __construct(string $data, bool $writeOnly = false)
$returnType = 'string';
} elseif ($returnType === 'positive-int') {
$returnType = 'int';
} elseif (is_numeric($returnType)) {
$returnType = 'int';
}
if (\strpos($returnType, 'list<') !== false) {
$returnType = \str_replace('list', 'array', $returnType);
}
$returnType = Type::toRootNamespace($returnType);
}
$this->types = $returnTypes;
$this->types = array_unique($returnTypes);
$this->nullable = $nullable;
$this->falsable = $falsable;
}
Expand Down
7 changes: 7 additions & 0 deletions generator/tests/PhpStanFunctions/PhpStanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,11 @@ public function testListBecomingArray(): void
$this->assertEquals('array', $param->getSignatureType(Method::FALSY_TYPE));
}

public function testNumbersAreRemoved(): void
{
$param = new PhpStanType('0|positive-int');
$this->assertEquals('int', $param->getDocBlockType());
$this->assertEquals('int', $param->getSignatureType());
}

}
1 change: 1 addition & 0 deletions rector-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
'parse_ini_file' => 'Safe\parse_ini_file',
'parse_ini_string' => 'Safe\parse_ini_string',
'parse_url' => 'Safe\parse_url',
'passthru' => 'Safe\passthru',
'pcntl_getpriority' => 'Safe\pcntl_getpriority',
'pcntl_setpriority' => 'Safe\pcntl_setpriority',
'pcntl_signal' => 'Safe\pcntl_signal',
Expand Down

0 comments on commit c4919cd

Please sign in to comment.