Skip to content

[generator] ignore benevolence properly #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions generated/8.1/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function date_parse(string $datetime): ?array
* @param int $timestamp Unix timestamp.
* @param float $latitude Latitude in degrees.
* @param float $longitude Longitude in degrees.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool}|false Returns array on success.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool} Returns array on success.
* The structure of the array is detailed in the following list:
*
*
Expand Down Expand Up @@ -603,13 +603,13 @@ function idate(string $format, ?int $timestamp = null): int
* 1970-2000. On systems where time_t is a 32bit signed integer, as
* most common today, the valid range for year
* is somewhere between 1901 and 2038.
* @return int|false mktime returns the Unix timestamp of the arguments
* @return int mktime returns the Unix timestamp of the arguments
* given.
* If the arguments are invalid, the function returns FALSE.
* @throws DatetimeException
*
*/
function mktime(int $hour, ?int $minute = null, ?int $second = null, ?int $month = null, ?int $day = null, ?int $year = null): int|false
function mktime(int $hour, ?int $minute = null, ?int $second = null, ?int $month = null, ?int $day = null, ?int $year = null): int
{
error_clear_last();
if ($year !== null) {
Expand Down
2 changes: 1 addition & 1 deletion generated/8.1/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ function tempnam(string $directory, string $prefix): string
* the file handle returned by tmpfile), or when the
* script ends.
*
* @return resource|false Returns a file handle, similar to the one returned by
* @return resource Returns a file handle, similar to the one returned by
* fopen, for the new file.
* @throws FilesystemException
*
Expand Down
4 changes: 2 additions & 2 deletions generated/8.1/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ function imagecopyresized(\GdImage $dst_image, \GdImage $src_image, int $dst_x,
*
* @param int $width The image width.
* @param int $height The image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -1033,7 +1033,7 @@ function imagecreatefromxpm(string $filename)
*
* @param int $width Image width.
* @param int $height Image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/8.1/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ function dl(string $extension_filename): void
/**
*
*
* @return string|false Returns the path, as a string.
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string|false
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
Expand Down Expand Up @@ -323,7 +323,7 @@ function getmyuid(): int
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array|false This function will return an array of option / argument pairs.
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/8.2/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function date_parse(string $datetime): ?array
* @param int $timestamp Unix timestamp.
* @param float $latitude Latitude in degrees.
* @param float $longitude Longitude in degrees.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool}|false Returns array on success.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool} Returns array on success.
* The structure of the array is detailed in the following list:
*
*
Expand Down
2 changes: 1 addition & 1 deletion generated/8.2/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ function tempnam(string $directory, string $prefix): string
* the file handle returned by tmpfile), or when the
* script ends.
*
* @return resource|false Returns a file handle, similar to the one returned by
* @return resource Returns a file handle, similar to the one returned by
* fopen, for the new file.
* @throws FilesystemException
*
Expand Down
4 changes: 2 additions & 2 deletions generated/8.2/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function imagecopyresized(\GdImage $dst_image, \GdImage $src_image, int $dst_x,
*
* @param int $width The image width.
* @param int $height The image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -1012,7 +1012,7 @@ function imagecreatefromxpm(string $filename)
*
* @param int $width Image width.
* @param int $height Image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/8.2/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ function dl(string $extension_filename): void
/**
*
*
* @return string|false Returns the path, as a string.
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string|false
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
Expand Down Expand Up @@ -323,7 +323,7 @@ function getmyuid(): int
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array|false This function will return an array of option / argument pairs.
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/8.3/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function date_parse(string $datetime): ?array
* @param int $timestamp Unix timestamp.
* @param float $latitude Latitude in degrees.
* @param float $longitude Longitude in degrees.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool}|false Returns array on success.
* @return array{sunrise: int|bool,sunset: int|bool,transit: int|bool,civil_twilight_begin: int|bool,civil_twilight_end: int|bool,nautical_twilight_begin: int|bool,nautical_twilight_end: int|bool,astronomical_twilight_begin: int|bool,astronomical_twilight_end: int|bool} Returns array on success.
* The structure of the array is detailed in the following list:
*
*
Expand Down
2 changes: 1 addition & 1 deletion generated/8.3/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ function tempnam(string $directory, string $prefix): string
* the file handle returned by tmpfile), or when the
* script ends.
*
* @return resource|false Returns a file handle, similar to the one returned by
* @return resource Returns a file handle, similar to the one returned by
* fopen, for the new file.
* @throws FilesystemException
*
Expand Down
4 changes: 2 additions & 2 deletions generated/8.3/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function imagecopyresized(\GdImage $dst_image, \GdImage $src_image, int $dst_x,
*
* @param int $width The image width.
* @param int $height The image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -1012,7 +1012,7 @@ function imagecreatefromxpm(string $filename)
*
* @param int $width Image width.
* @param int $height Image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/8.3/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ function dl(string $extension_filename): void
/**
*
*
* @return string|false Returns the path, as a string.
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string|false
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
Expand Down Expand Up @@ -323,7 +323,7 @@ function getmyuid(): int
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array|false This function will return an array of option / argument pairs.
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/8.4/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ function tempnam(string $directory, string $prefix): string
* the file handle returned by tmpfile), or when the
* script ends.
*
* @return resource|false Returns a file handle, similar to the one returned by
* @return resource Returns a file handle, similar to the one returned by
* fopen, for the new file.
* @throws FilesystemException
*
Expand Down
4 changes: 2 additions & 2 deletions generated/8.4/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function imagecopyresized(\GdImage $dst_image, \GdImage $src_image, int $dst_x,
*
* @param int $width The image width.
* @param int $height The image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -1012,7 +1012,7 @@ function imagecreatefromxpm(string $filename)
*
* @param int $width Image width.
* @param int $height Image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/8.4/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function dl(string $extension_filename): void
/**
*
*
* @return string|false Returns the path, as a string.
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string|false
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
Expand Down Expand Up @@ -206,7 +206,7 @@ function getmyuid(): int
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array|false This function will return an array of option / argument pairs.
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/8.5/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ function tempnam(string $directory, string $prefix): string
* the file handle returned by tmpfile), or when the
* script ends.
*
* @return resource|false Returns a file handle, similar to the one returned by
* @return resource Returns a file handle, similar to the one returned by
* fopen, for the new file.
* @throws FilesystemException
*
Expand Down
4 changes: 2 additions & 2 deletions generated/8.5/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function imagecopyresized(\GdImage $dst_image, \GdImage $src_image, int $dst_x,
*
* @param int $width The image width.
* @param int $height The image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -1012,7 +1012,7 @@ function imagecreatefromxpm(string $filename)
*
* @param int $width Image width.
* @param int $height Image height.
* @return resource|false Returns an image object on success.
* @return resource Returns an image object on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/8.5/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function dl(string $extension_filename): void
/**
*
*
* @return string|false Returns the path, as a string.
* @return string Returns the path, as a string.
* @throws InfoException
*
*/
function get_include_path(): string|false
function get_include_path(): string
{
error_clear_last();
$safeResult = \get_include_path();
Expand Down Expand Up @@ -206,7 +206,7 @@ function getmyuid(): int
* @param string $short_options
* @param array $long_options
* @param int|null $rest_index
* @return array|array|array|false This function will return an array of option / argument pairs.
* @return array|array|array This function will return an array of option / argument pairs.
* @throws InfoException
*
*/
Expand Down
2 changes: 0 additions & 2 deletions generator/src/PhpStanFunctions/PhpStanParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Safe\PhpStanFunctions;

use Safe\XmlDocParser\Type;

class PhpStanParameter
{
private readonly string $name;
Expand Down
8 changes: 4 additions & 4 deletions generator/src/PhpStanFunctions/PhpStanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class PhpStanType

public function __construct(string $data, bool $writeOnly = false)
{
if (\preg_match('/__benevolent\<(.*)\>/', $data, $regs)) {
$data = $regs[1];
}

//weird case: null|false => null
if ($data === 'null|false') {
$this->nullable = false;
Expand Down Expand Up @@ -97,10 +101,6 @@ public function __construct(string $data, bool $writeOnly = false)
$returnType = 'int';
}

if (\preg_match('/__benevolent\<(.*)\>/', $returnType, $regs)) {
$returnType = $regs[1];
}

$returnType = Type::toRootNamespace($returnType);
}
$this->types = array_unique($returnTypes);
Expand Down
16 changes: 11 additions & 5 deletions generator/tests/PhpStanFunctions/PhpStanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public function testVoid(): void
{
$param = new PhpStanType('');
$this->assertEquals('', $param->getDocBlockType());
if (PHP_VERSION_ID >= 80200) {
$this->assertEquals('void', $param->getSignatureType());
} else {
$this->assertEquals('', $param->getSignatureType());
}
if (PHP_VERSION_ID >= 80200) {
$this->assertEquals('void', $param->getSignatureType());
} else {
$this->assertEquals('', $param->getSignatureType());
}

$param = new PhpStanType('void');
$this->assertEquals('void', $param->getDocBlockType());
Expand Down Expand Up @@ -197,4 +197,10 @@ public function testNumbersAreRemoved(): void
$this->assertEquals('int', $param->getSignatureType());
}

public function testIgnoreBenevolence(): void
{
$param = new PhpStanType('__benevolent<string|false>');
$this->assertEquals('string', $param->getDocBlockType(Method::FALSY_TYPE));
$this->assertEquals('string', $param->getSignatureType(Method::FALSY_TYPE));
}
}