update cs-fixer to latest stable version

This commit is contained in:
Ivan Fedorov 2021-05-09 00:25:50 +03:00 committed by Ivan Fedorov
parent 7d3f0e8be0
commit f25c9fa807
38 changed files with 526 additions and 253 deletions

View File

@ -804,7 +804,12 @@ final class EvPeriodic extends EvWatcher
* @param int $priority
*/
public function __construct(
$offset, $interval, ?callable $reschedule_cb = null, callable $callback, $data = null, $priority = 0
$offset,
$interval,
?callable $reschedule_cb,
callable $callback,
$data = null,
$priority = 0
) {}
/**
@ -847,7 +852,12 @@ final class EvPeriodic extends EvWatcher
* @return EvPeriodic
*/
final public static function createStopped(
$offset, $interval, ?callable $reschedule_cb = null, callable $callback, $data = null, $priority = 0
$offset,
$interval,
?callable $reschedule_cb,
callable $callback,
$data = null,
$priority = 0
) {}
/**
@ -1516,6 +1526,9 @@ final class EvLoop
* @param float $timeout_interval
*/
public static function defaultLoop(
$flags = Ev::FLAG_AUTO, $data = null, $io_interval = 0.0, $timeout_interval = 0.0
$flags = Ev::FLAG_AUTO,
$data = null,
$io_interval = 0.0,
$timeout_interval = 0.0
) {}
}

View File

@ -808,11 +808,13 @@ class Phar extends RecursiveDirectoryIterator implements RecursiveIterator, Seek
* </p>
* @return void No value is returned.
*/
final public static function webPhar(?string $alias = null,
?string $index = "index.php",
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $fileNotFoundScript = null,
array $mimeTypes = null,
?callable $rewrite = null) {}
final public static function webPhar(
?string $alias = null,
?string $index = "index.php",
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $fileNotFoundScript = null,
array $mimeTypes = null,
?callable $rewrite = null
) {}
/**
* Returns whether current entry is a directory and not '.' or '..'

View File

@ -1271,8 +1271,12 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator
* @param int $cachingIteratorFlags [optional] Flags to affect the behavior of the {@see RecursiveCachingIterator} used internally.
* @param int $mode [optional] Flags to affect the behavior of the {@see RecursiveIteratorIterator} used internally.
*/
public function __construct($iterator, $flags = self::BYPASS_KEY, $cachingIteratorFlags = CachingIterator::CATCH_GET_CHILD,
$mode = self::SELF_FIRST) {}
public function __construct(
$iterator,
$flags = self::BYPASS_KEY,
$cachingIteratorFlags = CachingIterator::CATCH_GET_CHILD,
$mode = self::SELF_FIRST
) {}
/**
* Rewind iterator
@ -1555,7 +1559,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
/**
* Sort the entries with a user-defined comparison function and maintain key association
* @link https://php.net/manual/en/arrayobject.uasort.php
* @param callback $callback <p>
* @param callable $callback <p>
* Function <i>cmp_function</i> should accept two
* parameters which will be filled by pairs of entries.
* The comparison function must return an integer less than, equal
@ -1570,7 +1574,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
/**
* Sort the entries by keys using a user-defined comparison function
* @link https://php.net/manual/en/arrayobject.uksort.php
* @param callback $callback <p>
* @param callable $callback <p>
* The callback comparison function.
* </p>
* <p>

View File

@ -46,7 +46,7 @@ function spl_autoload_extensions(?string $file_extensions): string {}
/**
* Register given function as __autoload() implementation
* @link https://php.net/manual/en/function.spl-autoload-register.php
* @param callback|null $callback [optional] <p>
* @param callable|null $callback [optional] <p>
* The autoload function being registered.
* If no parameter is provided, then the default implementation of
* spl_autoload will be registered.
@ -166,7 +166,7 @@ function iterator_count(Traversable $iterator): int {}
* @param Traversable $iterator <p>
* The class to iterate over.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* The callback function to call on every element.
* The function must return true in order to
* continue iterating over the iterator.

View File

@ -1103,10 +1103,10 @@ function sqlite_unbuffered_query($dbhandle, $query, $result_type = SQLITE_BOTH,
* @param string $function_name <p>
* The name of the function used in SQL statements.
* </p>
* @param callback $step_func <p>
* @param callable $step_func <p>
* Callback function called for each row of the result set.
* </p>
* @param callback $finalize_func <p>
* @param callable $finalize_func <p>
* Callback function to aggregate the "stepped" data from each row.
* </p>
* @param int $num_args [optional] <p>
@ -1127,7 +1127,7 @@ function sqlite_create_aggregate($dbhandle, $function_name, $step_func, $finaliz
* @param string $function_name <p>
* The name of the function used in SQL statements.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* Callback function to handle the defined SQL function.
* </p>
* Callback functions should return a type understood by SQLite (i.e.

View File

@ -192,9 +192,9 @@ function enchant_dict_suggest($dict, $word) {}
* @see enchant_dict_add()
*/
#[Deprecated(
reason: 'Use enchant_dict_add instead',
replacement: 'enchant_dict_add(%parameter0%, %parameter1%)',
since: '8.0'
reason: 'Use enchant_dict_add instead',
replacement: 'enchant_dict_add(%parameter0%, %parameter1%)',
since: '8.0'
)]
function enchant_dict_add_to_personal($dict, $word) {}
@ -241,9 +241,9 @@ function enchant_dict_add($dictionary, $word) {}
* @see enchant_dict_is_added
*/
#[Deprecated(
reason: 'Use enchant_dict_is_added instead',
replacement: 'enchant_dict_is_added(%parameter0%, %parameter1%)',
since: '8.0'
reason: 'Use enchant_dict_is_added instead',
replacement: 'enchant_dict_is_added(%parameter0%, %parameter1%)',
since: '8.0'
)]
function enchant_dict_is_in_session($dict, $word) {}

View File

@ -1691,7 +1691,7 @@ class GearmanClient
* single argument, a GearmanTask object.
*
* @link https://php.net/manual/en/gearmanclient.setworkloadcallback.php
* @param callback $callback A function to call
* @param callable $callback A function to call
* @return bool
*/
public function setWorkloadCallback($callback) {}
@ -1711,7 +1711,7 @@ class GearmanClient
* function should take a single argument, a GearmanTask object.
*
* @link https://php.net/manual/en/gearmanclient.setdatacallback.php
* @param callback $callback A function or method to call
* @param callable $callback A function or method to call
* @return bool
*/
public function setDataCallback($callback) {}
@ -1721,7 +1721,7 @@ class GearmanClient
* accept a single argument, a GearmanTask object.
*
* @link https://php.net/manual/en/gearmanclient.setwarningcallback.php
* @param callback $callback A function to call
* @param callable $callback A function to call
* @return bool
*/
public function setWarningCallback($callback) {}
@ -1731,7 +1731,7 @@ class GearmanClient
* worker. The function should accept a single argument, a GearmanTask object.
*
* @link https://php.net/manual/en/gearmanclient.setstatuscallback.php
* @param callback $callback A function to call
* @param callable $callback A function to call
* @return bool
*/
public function setStatusCallback($callback) {}
@ -1741,7 +1741,7 @@ class GearmanClient
* function should accept a single argument, a GearmanTask oject.
*
* @link https://php.net/manual/en/gearmanclient.setcompletecallback.php
* @param callback $callback A function to be called
* @param callable $callback A function to be called
* @return bool
*/
public function setCompleteCallback($callback) {}
@ -1750,7 +1750,7 @@ class GearmanClient
* Specifies a function to call when a worker for a task sends an exception.
*
* @link https://php.net/manual/en/gearmanclient.setexceptioncallback.php
* @param callback $callback Function to call when the worker throws an exception
* @param callable $callback Function to call when the worker throws an exception
* @return bool
*/
public function setExceptionCallback($callback) {}
@ -1760,7 +1760,7 @@ class GearmanClient
* successfully. The function should accept a single argument, a GearmanTask object.
*
* @link https://php.net/manual/en/gearmanclient.setfailcallback.php
* @param callback $callback A function to call
* @param callable $callback A function to call
* @return bool
*/
public function setFailCallback($callback) {}
@ -2083,7 +2083,7 @@ class GearmanWorker
* @link https://php.net/manual/en/gearmanworker.addfunction.php
* @param string $function_name The name of a function to register with the job
* server
* @param callback $function A callback that gets called when a job for the
* @param callable $function A callback that gets called when a job for the
* registered function name is submitted
* @param mixed $context A reference to arbitrary application context data that can
* be modified by the worker function

View File

@ -668,7 +668,7 @@ function ibase_wait_event($event_name1, $event_name2 = null, ...$_) {}
/**
* Register a callback function to be called when events are posted
* @link https://php.net/manual/en/function.ibase-set-event-handler.php
* @param callback $event_handler <p>
* @param callable $event_handler <p>
* The callback is called with the event name and the link resource as
* arguments whenever one of the specified events is posted by the
* database.
@ -1413,7 +1413,7 @@ function fbird_wait_event($event_name1, $event_name2 = null, ...$_) {}
* This is an alias of ibase_set_event_handler
* Register a callback function to be called when events are posted
* @link https://php.net/manual/en/function.fbird-set-event-handler.php
* @param callback $event_handler <p>
* @param callable $event_handler <p>
* The callback is called with the event name and the link resource as
* arguments whenever one of the specified events is posted by the
* database.

View File

@ -4291,8 +4291,14 @@ function msgfmt_get_error_message(MessageFormatter $formatter): string {}
* @return IntlDateFormatter|null
*/
#[Pure]
function datefmt_create(?string $locale, int $dateType, int $timeType, $timezone = null, IntlCalendar|int|null $calendar = null,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $pattern = null): ?IntlDateFormatter {}
function datefmt_create(
?string $locale,
int $dateType,
int $timeType,
$timezone = null,
IntlCalendar|int|null $calendar = null,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $pattern = null
): ?IntlDateFormatter {}
/**
* (PHP 5 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)<br/>

View File

@ -337,7 +337,7 @@ function event_add($event, $timeout = -1) {}
* The additional flag EV_PERSIST makes the event to persist until {@link event_del}() is
* called, otherwise the callback is invoked only once.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* Callback function to be called when the matching event occurs.
* </p>
* @param mixed $arg [optional] <p>
@ -385,9 +385,9 @@ function event_del($event) {}
* @link https://php.net/event_buffer_new
*
* @param resource $stream Valid PHP stream resource. Must be castable to file descriptor.
* @param callback|null $readcb Callback to invoke where there is data to read, or NULL if no callback is desired.
* @param callback|null $writecb Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.
* @param callback $errorcb Callback to invoke where there is an error on the descriptor, cannot be NULL.
* @param callable|null $readcb Callback to invoke where there is data to read, or NULL if no callback is desired.
* @param callable|null $writecb Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.
* @param callable $errorcb Callback to invoke where there is an error on the descriptor, cannot be NULL.
* @param mixed $arg An argument that will be passed to each of the callbacks (optional).
*
* @return resource|false returns new buffered event resource on success or FALSE on error.
@ -592,9 +592,9 @@ function event_buffer_fd_set($bevent, $fd) {}
* @link https://php.net/event_buffer_set_callback
*
* @param resource $bevent Valid buffered event resource.
* @param callback|null $readcb Callback to invoke where there is data to read, or NULL if no callback is desired.
* @param callback|null $writecb Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.
* @param callback $errorcb Callback to invoke where there is an error on the descriptor, cannot be NULL.
* @param callable|null $readcb Callback to invoke where there is data to read, or NULL if no callback is desired.
* @param callable|null $writecb Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.
* @param callable $errorcb Callback to invoke where there is an error on the descriptor, cannot be NULL.
* @param mixed $arg An argument that will be passed to each of the callbacks (optional).
*
* @return bool returns TRUE on success or FALSE on error.
@ -636,7 +636,7 @@ function event_timer_new() {}
* @param resource $event <p>
* Valid event resource.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* Callback function to be called when the matching event occurs.
* </p>
* @param mixed $arg [optional] <p>

View File

@ -37,6 +37,9 @@ class Deprecated
* f(1,2) will be replaced with wrappedCall(f(2,1))
* @param string $since Element is deprecated starting with the provided PHP language level, applicable only for PhpStorm stubs entries
*/
public function __construct($reason = "", $replacement = "",
#[ExpectedValues(self::PHP_VERSIONS)] $since = "5.6") {}
public function __construct(
$reason = "",
$replacement = "",
#[ExpectedValues(self::PHP_VERSIONS)] $since = "5.6"
) {}
}

View File

@ -2390,12 +2390,14 @@ function mysqli_stat(mysqli $mysql): string|false {}
* @param string|null $cipher_algos A list of allowable ciphers to use for SSL encryption
* @return bool This function always returns TRUE value.
*/
function mysqli_ssl_set(mysqli $mysql,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $key ,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $certificate ,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $ca_certificate ,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $ca_path,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $cipher_algos): bool {}
function mysqli_ssl_set(
mysqli $mysql,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $key,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $certificate,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $ca_certificate,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $ca_path,
#[LanguageLevelTypeAware(['8.0' => '?string'], default: 'string')] $cipher_algos
): bool {}
/**
* Closes a prepared statement

View File

@ -299,7 +299,7 @@ class OAuthProvider
public function __construct($params_array) {}
/**
* @param callback $callback_function
* @param callable $callback_function
* @return void
*/
public function consumerHandler($callback_function) {}
@ -350,13 +350,13 @@ class OAuthProvider
final public function setRequestTokenPath($path) {}
/**
* @param callback $callback_function
* @param callable $callback_function
* @return void
*/
public function timestampNonceHandler($callback_function) {}
/**
* @param callback $callback_function
* @param callable $callback_function
* @return void
*/
public function tokenHandler($callback_function) {}

View File

@ -201,23 +201,23 @@ function session_unset() {}
/**
* Sets user-level session storage functions
* @link https://php.net/manual/en/function.session-set-save-handler.php
* @param callback $open <p>
* @param callable $open <p>
* Open function, this works like a constructor in classes and is
* executed when the session is being opened. The open function
* expects two parameters, where the first is the save path and
* the second is the session name.
* </p>
* @param callback $close <p>
* @param callable $close <p>
* Close function, this works like a destructor in classes and is
* executed when the session operation is done.
* </p>
* @param callback $read <p>
* @param callable $read <p>
* Read function must return string value always to make save handler
* work as expected. Return empty string if there is no data to read.
* Return values from other handlers are converted to boolean expression.
* true for success, false for failure.
* </p>
* @param callback $write <p>
* @param callable $write <p>
* Write function that is called when session data is to be saved. This
* function expects two parameters: an identifier and the data associated
* with it.
@ -229,21 +229,21 @@ function session_unset() {}
* necessary, it is suggested that the debug output be written to a
* file instead.
* </p>
* @param callback $destroy <p>
* @param callable $destroy <p>
* The destroy handler, this is executed when a session is destroyed with
* <b>session_destroy</b> and takes the session id as its
* only parameter.
* </p>
* @param callback $gc <p>
* @param callable $gc <p>
* The garbage collector, this is executed when the session garbage collector
* is executed and takes the max session lifetime as its only parameter.
* </p>
* @param callback $create_sid [optional]
* @param callable $create_sid [optional]
* <p>This callback is executed when a new session ID is required.
* No parameters are provided, and the return value should be a string that is a valid
* session ID for your handler.</p>
* @param callback $validate_sid [optional]
* @param callback $update_timestamp [optional]
* @param callable $validate_sid [optional]
* @param callable $update_timestamp [optional]
* @return bool true on success or false on failure.
*/
function session_set_save_handler(callable $open, callable $close, callable $read, callable $write, callable $destroy, callable $gc, $create_sid, $validate_sid, $update_timestamp): bool {}

View File

@ -23,7 +23,7 @@ function error_get_last(): ?array {}
/**
* Call the callback given by the first parameter
* @link https://php.net/manual/en/function.call-user-func.php
* @param callback $callback <p>
* @param callable $callback <p>
* The function to be called. Class methods may also be invoked
* statically using this function by passing
* array($classname, $methodname) to this parameter.
@ -45,7 +45,7 @@ function call_user_func(callable $callback, mixed ...$args): mixed {}
/**
* Call a callback with an array of parameters
* @link https://php.net/manual/en/function.call-user-func-array.php
* @param callback $callback <p>
* @param callable $callback <p>
* The function to be called.
* </p>
* @param array $args <p>
@ -84,7 +84,7 @@ function call_user_method_array(string $method_name, object &$obj, array $params
/**
* Call a static method
* @link https://php.net/manual/en/function.forward-static-call.php
* @param callback $callback <p>
* @param callable $callback <p>
* The function or method to be called. This parameter may be an array,
* with the name of the class, and the method, or a string, with a function
* name.
@ -267,7 +267,7 @@ function memory_get_peak_usage(bool $real_usage = false): int {}
/**
* Register a function for execution on shutdown
* @link https://php.net/manual/en/function.register-shutdown-function.php
* @param callback $callback <p>
* @param callable $callback <p>
* The shutdown function to register.
* </p>
* <p>
@ -292,7 +292,7 @@ function register_shutdown_function(callable $callback, ...$args): ?bool {}
/**
* Register a function for execution on each tick
* @link https://php.net/manual/en/function.register-tick-function.php
* @param callback $callback <p>
* @param callable $callback <p>
* The function name as a string, or an array consisting of an object and
* a method.
* </p>

View File

@ -146,7 +146,7 @@ function metaphone(string $string, int $max_phonemes = 0): false|string {}
/**
* Turn on output buffering
* @link https://php.net/manual/en/function.ob-start.php
* @param callback $callback [optional] <p>
* @param callable $callback [optional] <p>
* An optional output_callback function may be
* specified. This function takes a string as a parameter and should
* return a string. The function will be called when
@ -493,7 +493,7 @@ function rsort(array &$array, int $flags): bool {}
* @param array &$array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* The comparison function must return an integer less than, equal to, or
* greater than zero if the first argument is considered to be
* respectively less than, equal to, or greater than the second.
@ -508,7 +508,7 @@ function usort(array &$array, callable $callback): bool {}
* @param array &$array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* See usort and uksort for
* examples of user-defined comparison functions.
* </p>
@ -522,7 +522,7 @@ function uasort(array &$array, callable $callback): bool {}
* @param array &$array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* The callback comparison function.
* </p>
* <p>
@ -553,7 +553,7 @@ function shuffle(array &$array): bool {}
* @param array|object &$array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* Typically, funcname takes on two parameters.
* The array parameter's value being the first, and
* the key/index second.
@ -587,7 +587,7 @@ function array_walk(object|array &$array, callable $callback, mixed $arg): bool
* @param array|object &$array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* Typically, funcname takes on two parameters.
* The input parameter's value being the first, and
* the key/index second.

View File

@ -132,7 +132,7 @@ function array_reverse(array $array, bool $preserve_keys = false): array {}
* @param array $array <p>
* The input array.
* </p>
* @param callback $callback <p>
* @param callable $callback <p>
* The callback function. Signature is <pre>callback ( mixed $carry , mixed $item ) : mixed</pre>
* <blockquote>mixed <var>$carry</var> <p>The return value of the previous iteration; on the first iteration it holds the value of <var>$initial</var>.</p></blockquote>
* <blockquote>mixed <var>$item</var> <p>Holds the current iteration value of the <var>$input</var></p></blockquote>
@ -322,7 +322,7 @@ function array_intersect_key(array $array1, array $array2, array ...$_): array {
* First array to compare keys against.
* </p>
* @param array ...$_ [optional]
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* User supplied callback function to do the comparison.
* </p>
* @return array the values of array1 whose keys exist
@ -341,7 +341,7 @@ function array_intersect_ukey(array $array1, array $array2, array $_ = null, cal
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* The callback comparison function.
* </p>
* <p>
@ -383,7 +383,7 @@ function array_intersect_assoc(array $array1, array $array2, array $_ = null): a
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* For comparison is used the user supplied callback function.
* It must return an integer less than, equal
* to, or greater than zero if the first argument is considered to
@ -406,7 +406,7 @@ function array_uintersect_assoc(array $array1, array $array2, array $_ = null, c
* First array to compare keys against.
* </p>
* @param array ...$_ [optional]
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* User supplied callback function to do the comparison.
* </p>
* @return array the values of array1 whose values exist
@ -425,14 +425,14 @@ function array_intersect_uassoc(array $array1, array $array2, array $_ = null, c
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* For comparison is used the user supplied callback function.
* It must return an integer less than, equal
* to, or greater than zero if the first argument is considered to
* be respectively less than, equal to, or greater than the
* second.
* </p>
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* Key comparison callback function.
* </p>
* @return array an array containing all the values of
@ -505,7 +505,7 @@ function array_diff_key(array $array1, array $array2, array ...$_): array {}
* An array to compare against
* </p>
* @param array ...$_ [optional]
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* callback function to use.
* The callback function must return an integer less than, equal
* to, or greater than zero if the first argument is considered to
@ -527,7 +527,7 @@ function array_diff_ukey(array $array1, array $array2, array $_ = null, callable
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* The callback comparison function.
* </p>
* <p>
@ -569,7 +569,7 @@ function array_diff_assoc(array $array1, array $array2, array ...$_): array {}
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* The callback comparison function.
* </p>
* <p>
@ -601,7 +601,7 @@ function array_udiff_assoc(array $array1, array $array2, array $_ = null, callab
* An array to compare against
* </p>
* @param array ...$_ [optional]
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* callback function to use.
* The callback function must return an integer less than, equal
* to, or greater than zero if the first argument is considered to
@ -623,7 +623,7 @@ function array_diff_uassoc(array $array1, array $array2, array $_ = null, callab
* The second array.
* </p>
* @param array ...$_ [optional]
* @param callback $data_compare_func <p>
* @param callable $data_compare_func <p>
* The callback comparison function.
* </p>
* <p>
@ -639,7 +639,7 @@ function array_diff_uassoc(array $array1, array $array2, array $_ = null, callab
* array_diff_assoc which uses internal function for
* comparison.
* </p>
* @param callback $key_compare_func <p>
* @param callable $key_compare_func <p>
* The comparison of keys (indices) is done also by the callback function
* key_compare_func. This behaviour is unlike what
* array_udiff_assoc does, since the latter compares
@ -684,7 +684,7 @@ function array_product(array $array): int|float {}
* @param array $array <p>
* The array to iterate over
* </p>
* @param callback|null $callback [optional] <p>
* @param callable|null $callback [optional] <p>
* The callback function to use
* </p>
* <p>
@ -713,7 +713,7 @@ function array_filter(array $array, ?callable $callback, int $mode = 0): array {
/**
* Applies the callback to the elements of the given arrays
* @link https://php.net/manual/en/function.array-map.php
* @param callback $callback <p>
* @param callable $callback <p>
* Callback function to run for each element in each array.
* </p>
* @param array $array <p>

View File

@ -208,7 +208,7 @@ function sybase_min_server_severity($severity) {}
/**
* Sets the handler called when a server message is raised
* @link https://php.net/manual/en/function.sybase-set-message-handler.php
* @param callback $handler
* @param callable $handler
* @param resource $connection [optional]
* @return bool
* @removed 7.0

View File

@ -3,7 +3,11 @@ declare(strict_types=1);
namespace StubTests\CodeStyle;
use JetBrains\PhpStorm\Pure;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
use SplFileInfo;
@ -20,7 +24,7 @@ final class BracesOneLineFixer implements FixerInterface
return false;
}
public function fix(SplFileInfo $file, Tokens $tokens)
public function fix(SplFileInfo $file, Tokens $tokens): void
{
foreach ($tokens as $index => $token) {
if (!$token->equals('{')) {
@ -32,7 +36,7 @@ final class BracesOneLineFixer implements FixerInterface
if ($tokens[$braceEndIndex]->equals('}')) {
$beforeBraceIndex = $tokens->getPrevNonWhitespace($braceStartIndex);
for ($i = $beforeBraceIndex + 1; $i <= $braceEndIndex; $i++) {
$tokens[$i]->clear();
$tokens->clearAt($i);
}
if ($braceEndIndex - $beforeBraceIndex > 2) {
$tokens[$beforeBraceIndex + 1] = new Token(' ');
@ -59,4 +63,21 @@ final class BracesOneLineFixer implements FixerInterface
{
return true;
}
#[Pure]
public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
"Braces of empty function's body should be placed on the same line",
[
new CodeSample(
<<<PHP
<?php
declare(strict_types=1);
function foo() {}
PHP
),
]
);
}
}

View File

@ -85,8 +85,10 @@ class PHPClass extends BasePHPClass
if ($node->getDocComment() !== null) {
$docBlock = DocBlockFactory::createInstance()->create($node->getDocComment()->getText());
/** @var PropertyRead[] $properties */
$properties = array_merge($docBlock->getTagsByName('property-read'),
$docBlock->getTagsByName('property'));
$properties = array_merge(
$docBlock->getTagsByName('property-read'),
$docBlock->getTagsByName('property')
);
foreach ($properties as $property) {
$propertyName = $property->getVariableName();
assert($propertyName !== '', "@property name is empty in class $this->name");
@ -96,8 +98,10 @@ class PHPClass extends BasePHPClass
$newProperty->name = $propertyName;
$newProperty->parentName = $this->name;
$newProperty->type = '' . $property->getType();
assert(!array_key_exists($propertyName, $this->properties),
"Property '$propertyName' is already declared in class '$this->name'");
assert(
!array_key_exists($propertyName, $this->properties),
"Property '$propertyName' is already declared in class '$this->name'"
);
$this->properties[$propertyName] = $newProperty;
}
}

View File

@ -40,8 +40,10 @@ class StubsContainer
{
if (isset($constant->name)) {
if (array_key_exists($constant->name, $this->constants)) {
$amount = count(array_filter($this->constants,
fn (PHPConst $nextConstant) => $nextConstant->name === $constant->name));
$amount = count(array_filter(
$this->constants,
fn (PHPConst $nextConstant) => $nextConstant->name === $constant->name
));
$this->constants[$constant->name . '_duplicated_' . $amount] = $constant;
} else {
$this->constants[$constant->name] = $constant;
@ -86,8 +88,10 @@ class StubsContainer
{
if (isset($function->name)) {
if (array_key_exists($function->name, $this->functions)) {
$amount = count(array_filter($this->functions,
fn (PHPFunction $nextFunction) => $nextFunction->name === $function->name));
$amount = count(array_filter(
$this->functions,
fn (PHPFunction $nextFunction) => $nextFunction->name === $function->name
));
$this->functions[$function->name . '_duplicated_' . $amount] = $function;
} else {
$this->functions[$function->name] = $function;
@ -143,8 +147,10 @@ class StubsContainer
{
if (isset($class->name)) {
if (array_key_exists($class->name, $this->classes)) {
$amount = count(array_filter($this->classes,
fn (PHPClass $nextClass) => $nextClass->name === $class->name));
$amount = count(array_filter(
$this->classes,
fn (PHPClass $nextClass) => $nextClass->name === $class->name
));
$this->classes[$class->name . '_duplicated_' . $amount] = $class;
} else {
$this->classes[$class->name] = $class;
@ -200,8 +206,10 @@ class StubsContainer
{
if (isset($interface->name)) {
if (array_key_exists($interface->name, $this->interfaces)) {
$amount = count(array_filter($this->interfaces,
fn (PHPInterface $nextInterface) => $nextInterface->name === $interface->name));
$amount = count(array_filter(
$this->interfaces,
fn (PHPInterface $nextInterface) => $nextInterface->name === $interface->name
));
$this->interfaces[$interface->name . '_duplicated_' . $amount] = $interface;
} else {
$this->interfaces[$interface->name] = $interface;

View File

@ -35,8 +35,11 @@ class StubParser
self::$stubs = new StubsContainer();
$visitor = new ASTVisitor(self::$stubs);
$coreStubVisitor = new CoreStubASTVisitor(self::$stubs);
self::processStubs($visitor, $coreStubVisitor,
fn (SplFileInfo $file): bool => $file->getFilename() !== '.phpstorm.meta.php');
self::processStubs(
$visitor,
$coreStubVisitor,
fn (SplFileInfo $file): bool => $file->getFilename() !== '.phpstorm.meta.php'
);
$jsonData = json_decode(file_get_contents(__DIR__ . '/../TestData/mutedProblems.json'));
foreach (self::$stubs->getInterfaces() as $interface) {

View File

@ -94,8 +94,10 @@ class Utils
if ($lastAvailableVersion === null) {
$lastAvailableVersion = PhpVersions::getLatest();
}
return array_filter(iterator_to_array(new PhpVersions()),
fn ($version) => $version >= $firstSinceVersion && $version <= $lastAvailableVersion);
return array_filter(
iterator_to_array(new PhpVersions()),
fn ($version) => $version >= $firstSinceVersion && $version <= $lastAvailableVersion
);
}
/**

View File

@ -25,9 +25,11 @@ use StubTests\Parsers\Utils;
class ASTVisitor extends NodeVisitorAbstract
{
public function __construct(protected StubsContainer $stubs,
protected bool $isStubCore = false,
public ?string $sourceFilePath = null) {}
public function __construct(
protected StubsContainer $stubs,
protected bool $isStubCore = false,
public ?string $sourceFilePath = null
) {}
/**
* @param Node $node
@ -117,10 +119,14 @@ class ASTVisitor extends NodeVisitorAbstract
/** @var string $parentInterface */
foreach ($interface->parentInterfaces as $parentInterface) {
$parents[] = $parentInterface;
if ($this->stubs->getInterface($parentInterface,
$interface->stubBelongsToCore ? null : $interface->sourceFilePath) !== null) {
foreach ($this->combineParentInterfaces($this->stubs->getInterface($parentInterface,
$interface->stubBelongsToCore ? null : $interface->sourceFilePath)) as $value) {
if ($this->stubs->getInterface(
$parentInterface,
$interface->stubBelongsToCore ? null : $interface->sourceFilePath
) !== null) {
foreach ($this->combineParentInterfaces($this->stubs->getInterface(
$parentInterface,
$interface->stubBelongsToCore ? null : $interface->sourceFilePath
)) as $value) {
$parents[] = $value;
}
}
@ -139,19 +145,27 @@ class ASTVisitor extends NodeVisitorAbstract
/** @var string $interface */
foreach ($class->interfaces as $interface) {
$interfaces[] = $interface;
if ($this->stubs->getInterface($interface,
$class->stubBelongsToCore ? null : $class->sourceFilePath) !== null) {
$interfaces[] = $this->stubs->getInterface($interface,
$class->stubBelongsToCore ? null : $class->sourceFilePath)->parentInterfaces;
if ($this->stubs->getInterface(
$interface,
$class->stubBelongsToCore ? null : $class->sourceFilePath
) !== null) {
$interfaces[] = $this->stubs->getInterface(
$interface,
$class->stubBelongsToCore ? null : $class->sourceFilePath
)->parentInterfaces;
}
}
if ($class->parentClass === null) {
return $interfaces;
}
if ($this->stubs->getClass($class->parentClass,
$class->stubBelongsToCore ? null : $class->sourceFilePath) !== null) {
$inherited = $this->combineImplementedInterfaces($this->stubs->getClass($class->parentClass,
$class->stubBelongsToCore ? null : $class->sourceFilePath));
if ($this->stubs->getClass(
$class->parentClass,
$class->stubBelongsToCore ? null : $class->sourceFilePath
) !== null) {
$inherited = $this->combineImplementedInterfaces($this->stubs->getClass(
$class->parentClass,
$class->stubBelongsToCore ? null : $class->sourceFilePath
));
$interfaces[] = Utils::flattenArray($inherited, false);
}
return $interfaces;

View File

@ -3,12 +3,14 @@ declare(strict_types=1);
namespace StubTests\Parsers\Visitors;
use LogicException;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\NodeVisitorAbstract;
use RuntimeException;
use SplFileInfo;
use StubTests\Parsers\StubParser;
use UnexpectedValueException;
class MetaOverrideFunctionsParser extends NodeVisitorAbstract
{
@ -19,11 +21,18 @@ class MetaOverrideFunctionsParser extends NodeVisitorAbstract
*/
public array $overridenFunctions;
/**
* @throws UnexpectedValueException
* @throws LogicException
*/
public function __construct()
{
$this->overridenFunctions = [];
StubParser::processStubs($this, null,
fn (SplFileInfo $file): bool => $file->getFilename() === '.phpstorm.meta.php');
StubParser::processStubs(
$this,
null,
fn (SplFileInfo $file): bool => $file->getFilename() === '.phpstorm.meta.php'
);
}
/**

View File

@ -69,7 +69,8 @@ class StubsMetaExpectedArgumentsTest extends BaseStubsTest
public static function getMethodsFqns(StubsContainer $stubs): array
{
return self::flatten(
array_map(fn (PHPClass $class) => array_map(fn (PHPMethod $method) => self::getClassMemberFqn($class->name, $method->name), $class->methods), $stubs->getClasses()));
array_map(fn (PHPClass $class) => array_map(fn (PHPMethod $method) => self::getClassMemberFqn($class->name, $method->name), $class->methods), $stubs->getClasses())
);
}
/**
@ -130,8 +131,11 @@ class StubsMetaExpectedArgumentsTest extends BaseStubsTest
self::fail("Couldn't read name of arguments set");
}
self::assertContains($name, self::$registeredArgumentsSet, 'Can\'t find registered argument set: ' . $name);
self::assertArrayNotHasKey($name, $usedArgumentsSet,
$name . ' argumentsSet used more then once for ' . self::getFqn($argument->getFunctionReference()));
self::assertArrayNotHasKey(
$name,
$usedArgumentsSet,
$name . ' argumentsSet used more then once for ' . self::getFqn($argument->getFunctionReference())
);
$usedArgumentsSet[$name] = $name;
}
}
@ -143,8 +147,11 @@ class StubsMetaExpectedArgumentsTest extends BaseStubsTest
foreach (self::$expectedArguments as $argument) {
foreach ($argument->getExpectedArguments() as $literalArgument) {
if ($literalArgument instanceof String_) {
self::assertEquals(String_::KIND_SINGLE_QUOTED, $literalArgument->getAttribute('kind'),
'String literals as expectedArguments should be single-quoted');
self::assertEquals(
String_::KIND_SINGLE_QUOTED,
$literalArgument->getAttribute('kind'),
'String literals as expectedArguments should be single-quoted'
);
}
}
}
@ -183,8 +190,11 @@ class StubsMetaExpectedArgumentsTest extends BaseStubsTest
continue;
}
$functionReferenceFqn = self::getFqn($argument->getFunctionReference());
self::assertArrayNotHasKey($functionReferenceFqn, $expectedReturnValuesFunctionsFqns,
'Expected return values for ' . $functionReferenceFqn . ' already registered');
self::assertArrayNotHasKey(
$functionReferenceFqn,
$expectedReturnValuesFunctionsFqns,
'Expected return values for ' . $functionReferenceFqn . ' already registered'
);
$expectedReturnValuesFunctionsFqns[$functionReferenceFqn] = $functionReferenceFqn;
}
}
@ -218,8 +228,10 @@ class StubsMetaExpectedArgumentsTest extends BaseStubsTest
}
$originalName = $name->getAttribute('originalName');
if (method_exists($originalName, 'isFullyQualified')) {
self::assertTrue($originalName->isFullyQualified(),
self::getFqn($expr) . ' should be fully qualified');
self::assertTrue(
$originalName->isFullyQualified(),
self::getFqn($expr) . ' should be fully qualified'
);
} else {
self::fail('Could not check if name is fully qualified');
}

View File

@ -31,8 +31,10 @@ class StubsMetaInternalTagTest extends BaseStubsTest
$functions = PhpStormStubsSingleton::getPhpStormStubs()->getFunctions();
foreach ($functions as $function) {
if ($function->hasInternalMetaTag) {
$reflectionFunctions = array_filter(ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
fn ($refFunction) => $refFunction->name === $function->name);
$reflectionFunctions = array_filter(
ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
fn ($refFunction) => $refFunction->name === $function->name
);
$reflectionFunction = array_pop($reflectionFunctions);
if (!$reflectionFunction->hasMutedProblem(StubProblemType::ABSENT_IN_META)) {
self::checkInternalMetaInOverride($function->name);
@ -51,8 +53,10 @@ class StubsMetaInternalTagTest extends BaseStubsTest
if ($method->hasInternalMetaTag) {
$refClass = ReflectionStubsSingleton::getReflectionStubs()->getClass($className);
if ($refClass !== null) {
$reflectionMethods = array_filter($refClass->methods,
fn ($refMethod) => $refMethod->name === $methodName);
$reflectionMethods = array_filter(
$refClass->methods,
fn ($refMethod) => $refMethod->name === $methodName
);
/** @var PHPMethod $reflectionMethod */
$reflectionMethod = array_pop($reflectionMethods);
if ($reflectionMethod->hasMutedProblem(StubProblemType::ABSENT_IN_META)) {
@ -74,7 +78,10 @@ class StubsMetaInternalTagTest extends BaseStubsTest
*/
private static function checkInternalMetaInOverride(string $elementName): void
{
self::assertContains($elementName, self::$overriddenFunctionsInMeta,
"$elementName contains @meta in phpdoc but isn't added to 'override()' functions in meta file");
self::assertContains(
$elementName,
self::$overriddenFunctionsInMeta,
"$elementName contains @meta in phpdoc but isn't added to 'override()' functions in meta file"
);
}
}

View File

@ -21,10 +21,14 @@ class StubsParameterNamesTest extends BaseStubsTest
public function testFunctionsParameterNames(PHPFunction $function, PHPParameter $parameter)
{
$phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name);
self::assertNotEmpty(array_filter($phpstormFunction->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $parameter->name),
"Function {$function->name} has signature {$function->name}(" . self::printParameters($function->parameters) . ')' .
" but stub function has signature {$phpstormFunction->name}(" . self::printParameters($phpstormFunction->parameters) . ')');
self::assertNotEmpty(
array_filter(
$phpstormFunction->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $parameter->name
),
"Function $function->name has signature $function->name(" . self::printParameters($function->parameters) . ')' .
" but stub function has signature $phpstormFunction->name(" . self::printParameters($phpstormFunction->parameters) . ')'
);
}
/**
@ -40,10 +44,14 @@ class StubsParameterNamesTest extends BaseStubsTest
} else {
$stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->methods[$methodName];
}
self::assertNotEmpty(array_filter($stubMethod->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name),
self::assertNotEmpty(
array_filter(
$stubMethod->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name
),
"Method $className::$methodName has signature $methodName(" . self::printParameters($reflectionMethod->parameters) . ')' .
" but stub function has signature $methodName(" . self::printParameters($stubMethod->parameters) . ')');
" but stub function has signature $methodName(" . self::printParameters($stubMethod->parameters) . ')'
);
}
/**

View File

@ -24,12 +24,21 @@ class StubsReflectionClassesTest extends BaseStubsTest
$getReturnTypeMethod = array_pop($getReturnTypeMethods);
$allReturnTypes = array_unique(Utils::flattenArray($getReturnTypeMethod->returnTypesFromAttribute +
$getReturnTypeMethod->returnTypesFromSignature + $getReturnTypeMethod->returnTypesFromPhpDoc, false));
self::assertContains('ReflectionNamedType', $allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionNamedType in return types for php 7.1+');
self::assertContains('ReflectionUnionType', $allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionUnionType in return types for php 8.0+');
self::assertContains('ReflectionType', $allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionType in return types for php 7.0');
self::assertContains(
'ReflectionNamedType',
$allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionNamedType in return types for php 7.1+'
);
self::assertContains(
'ReflectionUnionType',
$allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionUnionType in return types for php 8.0+'
);
self::assertContains(
'ReflectionType',
$allReturnTypes,
'method ReflectionFunctionAbstract::getReturnType should have ReflectionType in return types for php 7.0'
);
}
/**
@ -42,10 +51,16 @@ class StubsReflectionClassesTest extends BaseStubsTest
$getTypeMethod = array_pop($getTypeMethods);
$allReturnTypes = array_unique(Utils::flattenArray($getTypeMethod->returnTypesFromAttribute +
$getTypeMethod->returnTypesFromSignature + $getTypeMethod->returnTypesFromPhpDoc, false));
self::assertContains('ReflectionNamedType', $allReturnTypes,
'method ReflectionProperty::getType should have ReflectionNamedType in return types for php 7.1+');
self::assertContains('ReflectionUnionType', $allReturnTypes,
'method ReflectionProperty::getType should have ReflectionUnionType in return types for php 8.0+');
self::assertContains(
'ReflectionNamedType',
$allReturnTypes,
'method ReflectionProperty::getType should have ReflectionNamedType in return types for php 7.1+'
);
self::assertContains(
'ReflectionUnionType',
$allReturnTypes,
'method ReflectionProperty::getType should have ReflectionUnionType in return types for php 8.0+'
);
}
/**
@ -58,9 +73,15 @@ class StubsReflectionClassesTest extends BaseStubsTest
$getTypeMethod = array_pop($getTypeMethods);
$allReturnTypes = array_unique(Utils::flattenArray($getTypeMethod->returnTypesFromAttribute +
$getTypeMethod->returnTypesFromSignature + $getTypeMethod->returnTypesFromPhpDoc, false));
self::assertContains('ReflectionNamedType', $allReturnTypes,
'method ReflectionParameter::getType should have ReflectionNamedType in return types');
self::assertContains('ReflectionUnionType', $allReturnTypes,
'method ReflectionParameter::getType should have ReflectionUnionType in return types');
self::assertContains(
'ReflectionNamedType',
$allReturnTypes,
'method ReflectionParameter::getType should have ReflectionNamedType in return types'
);
self::assertContains(
'ReflectionUnionType',
$allReturnTypes,
'method ReflectionParameter::getType should have ReflectionUnionType in return types'
);
}
}

View File

@ -170,10 +170,13 @@ class StubsTest extends BaseStubsTest
public function testFunctionsDuplicates()
{
$filtered = EntitiesFilter::getFiltered(
PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), problemTypes: StubProblemType::HAS_DUPLICATION
PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
problemTypes: StubProblemType::HAS_DUPLICATION
);
$duplicates = self::getDuplicatedFunctions($filtered);
self::assertCount(0, $duplicates,
self::assertCount(
0,
$duplicates,
"Functions \"" . implode(', ', $duplicates) .
"\" have duplicates in stubs.\nPlease use #[LanguageLevelTypeAware] or #[PhpStormStubsElementAvailable] if possible"
);
@ -189,8 +192,11 @@ class StubsTest extends BaseStubsTest
$stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->name === $parameter->name);
/** @var PHPParameter $stubOptionalParameter */
$stubOptionalParameter = array_pop($stubParameters);
self::assertEquals($parameter->isOptional, $stubOptionalParameter->isOptional,
sprintf('Reflection function %s has optional parameter %s', $function->name, $parameter->name));
self::assertEquals(
$parameter->isOptional,
$stubOptionalParameter->isOptional,
sprintf('Reflection function %s has optional parameter %s', $function->name, $parameter->name)
);
}
/**
@ -207,9 +213,17 @@ class StubsTest extends BaseStubsTest
$stubOptionalParameter = array_pop($stubParameters);
$reflectionValue = self::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue);
$stubValue = self::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue);
self::assertEquals($reflectionValue, $stubValue,
sprintf('Reflection function %s has optional parameter %s with default value %s but stub parameter has value %s',
$function->name, $parameter->name, $reflectionValue, $stubValue));
self::assertEquals(
$reflectionValue,
$stubValue,
sprintf(
'Reflection function %s has optional parameter %s with default value %s but stub parameter has value %s',
$function->name,
$parameter->name,
$reflectionValue,
$stubValue
)
);
}
/**
@ -231,9 +245,18 @@ class StubsTest extends BaseStubsTest
$stubOptionalParameter = array_pop($stubParameters);
$reflectionValue = self::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue);
$stubValue = self::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue, $class);
self::assertEquals($reflectionValue, $stubValue,
sprintf('Reflection method %s::%s has optional parameter %s with default value %s but stub parameter has value %s',
$class->name, $method->name, $parameter->name, $reflectionValue, $stubValue));
self::assertEquals(
$reflectionValue,
$stubValue,
sprintf(
'Reflection method %s::%s has optional parameter %s with default value %s but stub parameter has value %s',
$class->name,
$method->name,
$parameter->name,
$reflectionValue,
$stubValue
)
);
}
/**
@ -253,9 +276,16 @@ class StubsTest extends BaseStubsTest
$stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->name === $parameter->name);
/** @var PHPParameter $stubOptionalParameter */
$stubOptionalParameter = array_pop($stubParameters);
self::assertEquals($parameter->isOptional, $stubOptionalParameter->isOptional,
sprintf('Reflection method %s::%s has optional parameter %s but stub parameter is not optional',
$class->name, $method->name, $parameter->name));
self::assertEquals(
$parameter->isOptional,
$stubOptionalParameter->isOptional,
sprintf(
'Reflection method %s::%s has optional parameter %s but stub parameter is not optional',
$class->name,
$method->name,
$parameter->name
)
);
}
/**
@ -498,8 +528,10 @@ class StubsTest extends BaseStubsTest
*/
public function testImplodeFunctionIsCorrect()
{
$implodeFunctions = array_filter(PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
fn (PHPFunction $function) => $function->name === 'implode');
$implodeFunctions = array_filter(
PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
fn (PHPFunction $function) => $function->name === 'implode'
);
self::assertCount(1, $implodeFunctions);
/** @var PHPFunction $implodeFunction */
$implodeFunction = array_pop($implodeFunctions);
@ -543,8 +575,11 @@ class StubsTest extends BaseStubsTest
private static function getAllDuplicatesOfFunction(?string $name): array
{
return array_filter(PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
fn ($duplicateValue, $duplicateKey) => str_contains($duplicateValue->name, $name) && str_contains($duplicateKey, 'duplicated'), ARRAY_FILTER_USE_BOTH);
return array_filter(
PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
fn ($duplicateValue, $duplicateKey) => str_contains($duplicateValue->name, $name) && str_contains($duplicateKey, 'duplicated'),
ARRAY_FILTER_USE_BOTH
);
}
/**
@ -558,7 +593,8 @@ class StubsTest extends BaseStubsTest
if (str_contains($key, 'duplicated')) {
$duplicatesOfFunction = self::getAllDuplicatesOfFunction($value->name);
$functionVersions[] = Utils::getAvailableInVersions(
PhpStormStubsSingleton::getPhpStormStubs()->getFunction($value->name));
PhpStormStubsSingleton::getPhpStormStubs()->getFunction($value->name)
);
array_push($functionVersions, ...array_values(array_map(fn (PHPFunction $function) => Utils::getAvailableInVersions($function), $duplicatesOfFunction)));
$hasDuplicates = false;
$current = array_pop($functionVersions);
@ -588,10 +624,12 @@ class StubsTest extends BaseStubsTest
if ($defaultValue instanceof ConstFetch) {
$defaultValueName = (string)$defaultValue->name;
if ($defaultValueName !== 'false' && $defaultValueName !== 'true' && $defaultValueName !== 'null') {
$constants = array_filter(PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
$constants = array_filter(
PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
function (PHPConst $const) use ($defaultValue) {
return $const->name === (string)$defaultValue->name;
});
}
);
/** @var PHPConst $constant */
$constant = array_pop($constants);
$value = $constant->value;
@ -602,20 +640,26 @@ class StubsTest extends BaseStubsTest
$value = strval($defaultValue->value);
} elseif ($defaultValue instanceof BitwiseOr) {
if ($defaultValue->left instanceof ConstFetch && $defaultValue->right instanceof ConstFetch) {
$constants = array_filter(PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
/** @var BitwiseOr $defaultValue */
$constants = array_filter(
PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
fn (PHPConst $const) => property_exists($defaultValue->left, 'name') &&
$const->name === (string)$defaultValue->left->name);
$const->name === (string)$defaultValue->left->name
);
/** @var PHPConst $leftConstant */
$leftConstant = array_pop($constants);
$constants = array_filter(PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
/** @var BitwiseOr $defaultValue */
$constants = array_filter(
PhpStormStubsSingleton::getPhpStormStubs()->getConstants(),
fn (PHPConst $const) => property_exists($defaultValue->right, 'name') &&
$const->name === (string)$defaultValue->right->name);
$const->name === (string)$defaultValue->right->name
);
/** @var PHPConst $rightConstant */
$rightConstant = array_pop($constants);
$value = $leftConstant->value|$rightConstant->value;
}
} elseif ($defaultValue instanceof UnaryMinus && property_exists($defaultValue->expr, 'value')) {
$value = '-' . strval($defaultValue->expr->value);
$value = '-' . $defaultValue->expr->value;
} elseif ($defaultValue instanceof ClassConstFetch) {
$class = (string)$defaultValue->class;
if ($class === 'self' && $contextClass !== null) {

View File

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace StubTests;
use PHPUnit\Framework\Exception;
use RuntimeException;
use StubTests\Model\PHPClass;
use StubTests\Model\PHPFunction;
@ -26,9 +27,11 @@ class StubsTypeHintsTest extends BaseStubsTest
public function testFunctionsReturnTypeHints(PHPFunction $function)
{
$functionName = $function->name;
$allEqualStubFunctions = EntitiesFilter::getFiltered(PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
$allEqualStubFunctions = EntitiesFilter::getFiltered(
PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(),
fn (PHPFunction $stubFunction) => $stubFunction->name !== $functionName ||
!in_array(PhpVersions::getLatest(), Utils::getAvailableInVersions($stubFunction)));
!in_array(PhpVersions::getLatest(), Utils::getAvailableInVersions($stubFunction))
);
/** @var PHPFunction $stubFunction */
$stubFunction = array_pop($allEqualStubFunctions);
$conditionToCompareWithSignature = self::ifReflectionTypesExistInSignature($function->returnTypesFromSignature, $stubFunction->returnTypesFromSignature);
@ -50,16 +53,23 @@ class StubsTypeHintsTest extends BaseStubsTest
{
$functionName = $function->name;
$phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName);
/** @var PHPParameter $stubParameter */
$stubParameter = current(array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->name === $parameter->name));
self::assertNotFalse($stubParameter, "Parameter $$parameter->name not found at $phpstormFunction->name(" .
StubsParameterNamesTest::printParameters($phpstormFunction->parameters) . ')');
self::compareTypeHintsWithReflection($parameter, $stubParameter, $functionName);
if (!$parameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) {
self::assertEquals($parameter->is_passed_by_ref, $stubParameter->is_passed_by_ref,
"Invalid pass by ref $functionName: \$$parameter->name ");
self::assertEquals(
$parameter->is_passed_by_ref,
$stubParameter->is_passed_by_ref,
"Invalid pass by ref $functionName: \$$parameter->name "
);
}
self::assertEquals($parameter->is_vararg, $stubParameter->is_vararg,
"Invalid vararg $functionName: \$$parameter->name ");
self::assertEquals(
$parameter->is_vararg,
$stubParameter->is_vararg,
"Invalid vararg $functionName: \$$parameter->name "
);
}
/**
@ -76,8 +86,11 @@ class StubsTypeHintsTest extends BaseStubsTest
} else {
$stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->methods[$functionName];
}
self::assertEquals($method->returnTypesFromSignature, $stubMethod->returnTypesFromSignature,
"Method $class->name::$functionName has invalid return type");
self::assertEquals(
$method->returnTypesFromSignature,
$stubMethod->returnTypesFromSignature,
"Method $class->name::$functionName has invalid return type"
);
}
/**
@ -96,17 +109,26 @@ class StubsTypeHintsTest extends BaseStubsTest
} else {
$stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->methods[$methodName];
}
$stubParameter = current(array_filter($stubMethod->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name));
/** @var PHPParameter $stubParameter */
$stubParameter = current(array_filter(
$stubMethod->parameters,
fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name
));
self::assertNotFalse($stubParameter, "Parameter $$reflectionParameter->name not found at
$reflectionClass->name::$stubMethod->name(" .
StubsParameterNamesTest::printParameters($stubMethod->parameters) . ')');
if (!$reflectionParameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) {
self::assertEquals($reflectionParameter->is_passed_by_ref, $stubParameter->is_passed_by_ref,
"Invalid pass by ref $className::$methodName: \$$reflectionParameter->name ");
self::assertEquals(
$reflectionParameter->is_passed_by_ref,
$stubParameter->is_passed_by_ref,
"Invalid pass by ref $className::$methodName: \$$reflectionParameter->name "
);
}
self::assertEquals($reflectionParameter->is_vararg, $stubParameter->is_vararg,
"Invalid pass by ref $className::$methodName: \$$reflectionParameter->name ");
self::assertEquals(
$reflectionParameter->is_vararg,
$stubParameter->is_vararg,
"Invalid pass by ref $className::$methodName: \$$reflectionParameter->name "
);
}
/**
@ -119,10 +141,12 @@ class StubsTypeHintsTest extends BaseStubsTest
public static function testMethodDoesNotHaveScalarTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter)
{
$sinceVersion = Utils::getDeclaredSinceVersion($stubMethod);
self::assertEmpty(array_intersect(['int', 'float', 'string', 'bool'], $parameter->typesFromSignature),
self::assertEmpty(
array_intersect(['int', 'float', 'string', 'bool'], $parameter->typesFromSignature),
"Method '$class->name::$stubMethod->name' with @since '$sinceVersion'
has parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) .
"' but typehints available only since php 7");
"' but typehints available only since php 7"
);
}
/**
@ -135,10 +159,12 @@ class StubsTypeHintsTest extends BaseStubsTest
public static function testMethodDoesNotHaveNullableTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter)
{
$sinceVersion = Utils::getDeclaredSinceVersion($stubMethod);
self::assertEmpty(array_filter($parameter->typesFromSignature, fn (string $type) => str_contains($type, '?')),
self::assertEmpty(
array_filter($parameter->typesFromSignature, fn (string $type) => str_contains($type, '?')),
"Method '$class->name::$stubMethod->name' with @since '$sinceVersion'
has nullable parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) . "'
but nullable typehints available only since php 7.1");
but nullable typehints available only since php 7.1"
);
}
/**
@ -151,10 +177,13 @@ class StubsTypeHintsTest extends BaseStubsTest
public static function testMethodDoesNotHaveUnionTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter)
{
$sinceVersion = Utils::getDeclaredSinceVersion($stubMethod);
self::assertLessThan(2, count($parameter->typesFromSignature),
self::assertLessThan(
2,
count($parameter->typesFromSignature),
"Method '$class->name::$stubMethod->name' with @since '$sinceVersion'
has parameter '$parameter->name' with union typehint '" . implode('|', $parameter->typesFromSignature) . "'
but union typehints available only since php 8.0");
but union typehints available only since php 8.0"
);
}
/**
@ -178,10 +207,12 @@ class StubsTypeHintsTest extends BaseStubsTest
{
$sinceVersion = Utils::getDeclaredSinceVersion($stubMethod);
$returnTypes = $stubMethod->returnTypesFromSignature;
self::assertEmpty(array_filter($returnTypes, fn (string $type) => str_contains($type, '?')),
self::assertEmpty(
array_filter($returnTypes, fn (string $type) => str_contains($type, '?')),
"Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion'
but has nullable return typehint '" . implode('|', $returnTypes) . "' that supported only since PHP 7.1.
Please declare return type via PhpDoc");
Please declare return type via PhpDoc"
);
}
/**
@ -192,10 +223,13 @@ class StubsTypeHintsTest extends BaseStubsTest
public static function testMethodDoesNotHaveUnionReturnTypeHint(PHPMethod $stubMethod)
{
$sinceVersion = Utils::getDeclaredSinceVersion($stubMethod);
self::assertLessThan(2, count($stubMethod->returnTypesFromSignature),
self::assertLessThan(
2,
count($stubMethod->returnTypesFromSignature),
"Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion'
but has union return typehint '" . implode('|', $stubMethod->returnTypesFromSignature) . "' that supported only since PHP 8.0.
Please declare return type via PhpDoc");
Please declare return type via PhpDoc"
);
}
/**
@ -207,8 +241,10 @@ class StubsTypeHintsTest extends BaseStubsTest
*/
public function testMethodScalarTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter)
{
$reflectionMethods = array_filter(ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name);
$reflectionMethods = array_filter(
ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name
);
/** @var PHPMethod $reflectionMethod */
$reflectionMethod = array_pop($reflectionMethods);
$reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name);
@ -225,8 +261,10 @@ class StubsTypeHintsTest extends BaseStubsTest
*/
public function testMethodNullableTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter)
{
$reflectionMethods = array_filter(ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name);
$reflectionMethods = array_filter(
ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name
);
/** @var PHPMethod $reflectionMethod */
$reflectionMethod = array_pop($reflectionMethods);
$reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name);
@ -243,8 +281,10 @@ class StubsTypeHintsTest extends BaseStubsTest
*/
public function testMethodUnionTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter)
{
$reflectionMethods = array_filter(ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name);
$reflectionMethods = array_filter(
ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->methods,
fn (PHPMethod $method) => $method->name === $stubMethod->name
);
/** @var PHPMethod $reflectionMethod */
$reflectionMethod = array_pop($reflectionMethods);
$reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name);
@ -255,6 +295,7 @@ class StubsTypeHintsTest extends BaseStubsTest
/**
* @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::allFunctionAndMethodsWithReturnTypeHintsProvider
* @param PHPFunction|PHPMethod $method
* @throws Exception
*/
public static function testSignatureTypeHintsComplainPhpDocInMethods(PHPFunction|PHPMethod $method)
{
@ -276,11 +317,14 @@ class StubsTypeHintsTest extends BaseStubsTest
array_push($unifiedSignatureTypes, $typeName);
}
$typesIntersection = array_intersect($unifiedSignatureTypes, $unifiedPhpDocTypes);
self::assertEquals(count($unifiedSignatureTypes), count($typesIntersection),
self::assertSameSize(
$unifiedSignatureTypes,
$typesIntersection,
$method instanceof PHPMethod ? "Method $method->parentName::" : 'Function ' .
"$functionName has mismatch in phpdoc return type and signature return type\n
signature has " . implode('|', $unifiedSignatureTypes) . "\n
but phpdoc has " . implode('|', $unifiedPhpDocTypes));
but phpdoc has " . implode('|', $unifiedPhpDocTypes)
);
}
private static function compareTypeHintsWithReflection(PHPParameter $parameter, PHPParameter $stubParameter, ?string $functionName): void
@ -328,8 +372,10 @@ class StubsTypeHintsTest extends BaseStubsTest
private static function ifReflectionTypesExistInAttributes(array $reflectionTypes, array $typesFromAttribute): bool
{
return !empty(array_filter($typesFromAttribute,
fn (array $types) => count(array_intersect($reflectionTypes, $types)) == count($reflectionTypes)));
return !empty(array_filter(
$typesFromAttribute,
fn (array $types) => count(array_intersect($reflectionTypes, $types)) == count($reflectionTypes)
));
}
private static function ifReflectionTypesExistInSignature(array $reflectionTypes, array $typesFromSignature): bool

View File

@ -63,8 +63,12 @@ class EntitiesFilter
{
/** @var PHPParameter[] $resultArray */
$resultArray = [];
foreach (EntitiesFilter::getFiltered($function->parameters, $additionalFilter,
StubProblemType::PARAMETER_NAME_MISMATCH, ...$problemType) as $parameter) {
foreach (EntitiesFilter::getFiltered(
$function->parameters,
$additionalFilter,
StubProblemType::PARAMETER_NAME_MISMATCH,
...$problemType
) as $parameter) {
$resultArray[] = $parameter;
}
return $resultArray;

View File

@ -26,8 +26,11 @@ class ReflectionClassesTestDataProviders
public static function classesWithInterfacesProvider(): ?Generator
{
foreach (EntitiesFilter::getFiltered(ReflectionStubsSingleton::getReflectionStubs()->getClasses(),
fn (PHPClass $class) => empty($class->interfaces), StubProblemType::WRONG_INTERFACE) as $class) {
foreach (EntitiesFilter::getFiltered(
ReflectionStubsSingleton::getReflectionStubs()->getClasses(),
fn (PHPClass $class) => empty($class->interfaces),
StubProblemType::WRONG_INTERFACE
) as $class) {
//exclude classes from PHPReflectionParser
if (strncmp($class->name, 'PHP', 3) !== 0) {
yield "class $class->name" => [$class];
@ -42,7 +45,8 @@ class ReflectionClassesTestDataProviders
$filtered = EntitiesFilter::getFiltered(
$classesAndInterfaces,
fn (PHPClass|PHPInterface $class) => empty($class->parentInterfaces) && empty($class->parentClass),
StubProblemType::WRONG_PARENT);
StubProblemType::WRONG_PARENT
);
foreach ($filtered as $class) {
yield "class $class->name" => [$class];
}

View File

@ -19,16 +19,20 @@ class ReflectionFunctionsProvider
public static function functionsForDeprecationTestsProvider(): ?Generator
{
foreach (EntitiesFilter::getFiltered(ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
problemTypes: StubProblemType::FUNCTION_IS_DEPRECATED) as $function) {
foreach (EntitiesFilter::getFiltered(
ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
problemTypes: StubProblemType::FUNCTION_IS_DEPRECATED
) as $function) {
yield "function $function->name" => [$function];
}
}
public static function functionsForParamsAmountTestsProvider(): ?Generator
{
foreach (EntitiesFilter::getFiltered(ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
problemTypes: StubProblemType::FUNCTION_PARAMETER_MISMATCH) as $function) {
foreach (EntitiesFilter::getFiltered(
ReflectionStubsSingleton::getReflectionStubs()->getFunctions(),
problemTypes: StubProblemType::FUNCTION_PARAMETER_MISMATCH
) as $function) {
yield "function $function->name" => [$function];
}
}

View File

@ -14,8 +14,11 @@ class ReflectionParametersProvider
public static function functionParametersProvider(): ?Generator
{
foreach (EntitiesFilter::getFilteredFunctions() as $function) {
foreach (EntitiesFilter::getFilteredParameters($function, null,
StubProblemType::PARAMETER_TYPE_MISMATCH) as $parameter) {
foreach (EntitiesFilter::getFilteredParameters(
$function,
null,
StubProblemType::PARAMETER_TYPE_MISMATCH
) as $parameter) {
yield "$function->name($parameter->name)" => [$function, $parameter];
}
}
@ -24,8 +27,11 @@ class ReflectionParametersProvider
public static function functionOptionalParametersProvider(): ?Generator
{
foreach (EntitiesFilter::getFilteredFunctions() as $function) {
foreach (EntitiesFilter::getFilteredParameters($function, fn (PHPParameter $parameter) => !$parameter->isOptional,
StubProblemType::PARAMETER_TYPE_MISMATCH) as $parameter) {
foreach (EntitiesFilter::getFilteredParameters(
$function,
fn (PHPParameter $parameter) => !$parameter->isOptional,
StubProblemType::PARAMETER_TYPE_MISMATCH
) as $parameter) {
yield "$function->name($parameter->name)" => [$function, $parameter];
}
}
@ -34,10 +40,12 @@ class ReflectionParametersProvider
public static function functionOptionalParametersWithDefaultValueProvider(): ?Generator
{
foreach (EntitiesFilter::getFilteredFunctions() as $function) {
foreach (EntitiesFilter::getFilteredParameters($function,
foreach (EntitiesFilter::getFilteredParameters(
$function,
fn (PHPParameter $parameter) => !$parameter->isOptional || empty($parameter->defaultValue),
StubProblemType::PARAMETER_TYPE_MISMATCH,
StubProblemType::WRONG_PARAMETER_DEFAULT_VALUE) as $parameter) {
StubProblemType::WRONG_PARAMETER_DEFAULT_VALUE
) as $parameter) {
yield "$function->name($parameter->name)" => [$function, $parameter];
}
}
@ -67,8 +75,11 @@ class ReflectionParametersProvider
//exclude classes from PHPReflectionParser
if (strncmp($class->name, 'PHP', 3) !== 0) {
foreach (EntitiesFilter::getFilteredFunctions($class) as $method) {
foreach (EntitiesFilter::getFilteredParameters($method, fn (PHPParameter $parameter) => !$parameter->isOptional,
StubProblemType::PARAMETER_TYPE_MISMATCH) as $parameter) {
foreach (EntitiesFilter::getFilteredParameters(
$method,
fn (PHPParameter $parameter) => !$parameter->isOptional,
StubProblemType::PARAMETER_TYPE_MISMATCH
) as $parameter) {
yield "$class->name::$method->name($parameter->name)" => [$class, $method, $parameter];
}
}
@ -84,10 +95,12 @@ class ReflectionParametersProvider
//exclude classes from PHPReflectionParser
if (strncmp($class->name, 'PHP', 3) !== 0) {
foreach (EntitiesFilter::getFilteredFunctions($class) as $method) {
foreach (EntitiesFilter::getFilteredParameters($method,
foreach (EntitiesFilter::getFilteredParameters(
$method,
fn (PHPParameter $parameter) => !$parameter->isOptional || empty($parameter->defaultValue),
StubProblemType::PARAMETER_TYPE_MISMATCH,
StubProblemType::WRONG_PARAMETER_DEFAULT_VALUE) as $parameter) {
StubProblemType::WRONG_PARAMETER_DEFAULT_VALUE
) as $parameter) {
yield "$class->name::$method->name($parameter->name)" => [$class, $method, $parameter];
}
}

View File

@ -35,8 +35,11 @@ class ReflectionPropertiesProvider
{
$classesAndInterfaces = ReflectionStubsSingleton::getReflectionStubs()->getClasses();
foreach (EntitiesFilter::getFiltered($classesAndInterfaces) as $class) {
foreach (EntitiesFilter::getFiltered($class->properties,
fn (PHPProperty $property) => $property->access === 'private', ...$problemTypes) as $property) {
foreach (EntitiesFilter::getFiltered(
$class->properties,
fn (PHPProperty $property) => $property->access === 'private',
...$problemTypes
) as $property) {
yield "Property $class->name::$property->name" => [$class, $property];
}
}

View File

@ -31,14 +31,18 @@ class StubMethodsProvider
$allFunctions = PhpStormStubsSingleton::getPhpStormStubs()->getFunctions();
$filteredMethods = [];
foreach (EntitiesFilter::getFiltered($coreClassesAndInterfaces) as $className => $class) {
$filteredMethods = EntitiesFilter::getFiltered($class->methods,
$filteredMethods = EntitiesFilter::getFiltered(
$class->methods,
fn (PHPMethod $method) => empty($method->returnTypesFromSignature) || empty($method->returnTypesFromPhpDoc)
|| $method->parentName === '___PHPSTORM_HELPERS\object',
StubProblemType::TYPE_IN_PHPDOC_DIFFERS_FROM_SIGNATURE);
StubProblemType::TYPE_IN_PHPDOC_DIFFERS_FROM_SIGNATURE
);
}
$filteredMethods += EntitiesFilter::getFiltered($allFunctions,
$filteredMethods += EntitiesFilter::getFiltered(
$allFunctions,
fn (PHPFunction $function) => empty($function->returnTypesFromSignature) || empty($function->returnTypesFromPhpDoc),
StubProblemType::TYPE_IN_PHPDOC_DIFFERS_FROM_SIGNATURE);
StubProblemType::TYPE_IN_PHPDOC_DIFFERS_FROM_SIGNATURE
);
foreach ($filteredMethods as $methodName => $method) {
if ($method instanceof PHPMethod) {
yield "method $method->parentName::$methodName" => [$method];
@ -51,22 +55,31 @@ class StubMethodsProvider
public static function methodsForReturnTypeHintTestsProvider(): ?Generator
{
$filterFunction = EntitiesFilter::getFilterFunctionForLanguageLevel(7);
return self::yieldFilteredMethods($filterFunction, StubProblemType::FUNCTION_HAS_RETURN_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT);
return self::yieldFilteredMethods(
$filterFunction,
StubProblemType::FUNCTION_HAS_RETURN_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT
);
}
public static function methodsForNullableReturnTypeHintTestsProvider(): ?Generator
{
$filterFunction = EntitiesFilter::getFilterFunctionForLanguageLevel(7.1);
return self::yieldFilteredMethods($filterFunction, StubProblemType::HAS_NULLABLE_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT);
return self::yieldFilteredMethods(
$filterFunction,
StubProblemType::HAS_NULLABLE_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT
);
}
public static function methodsForUnionReturnTypeHintTestsProvider(): ?Generator
{
$filterFunction = EntitiesFilter::getFilterFunctionForLanguageLevel(8);
return self::yieldFilteredMethods($filterFunction, StubProblemType::HAS_UNION_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT);
return self::yieldFilteredMethods(
$filterFunction,
StubProblemType::HAS_UNION_TYPEHINT,
StubProblemType::WRONG_RETURN_TYPEHINT
);
}
private static function yieldFilteredMethods(callable $filterFunction, int ...$problemTypes): ?Generator
@ -74,8 +87,11 @@ class StubMethodsProvider
$coreClassesAndInterfaces = PhpStormStubsSingleton::getPhpStormStubs()->getCoreClasses() +
PhpStormStubsSingleton::getPhpStormStubs()->getCoreInterfaces();
foreach (EntitiesFilter::getFiltered($coreClassesAndInterfaces) as $className => $class) {
foreach (EntitiesFilter::getFiltered($class->methods,
fn (PHPMethod $method) => $method->parentName === '___PHPSTORM_HELPERS\object', ...$problemTypes) as $methodName => $method) {
foreach (EntitiesFilter::getFiltered(
$class->methods,
fn (PHPMethod $method) => $method->parentName === '___PHPSTORM_HELPERS\object',
...$problemTypes
) as $methodName => $method) {
$firstSinceVersion = Utils::getDeclaredSinceVersion($method);
if ($filterFunction($class, $method, $firstSinceVersion) === true) {
yield "method $className::$methodName" => [$method];