diff --git a/functionMap.php b/functionMap.php index 792c6d0..598ea35 100644 --- a/functionMap.php +++ b/functionMap.php @@ -49,6 +49,7 @@ 'sanitize_post' => ['T', '@phpstan-template' => 'T of array|object', 'post' => 'T'], 'sanitize_term' => ['T', '@phpstan-template' => 'T of array|object', 'term' => 'T'], 'stripslashes_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], + 'stripslashes_from_strings_only' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'urldecode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'urlencode_deep' => ['T', '@phpstan-template' => 'T', 'value' => 'T'], 'validate_file' => ["(\$file is '' ? 0 : (\$allowed_files is empty ? 0|1|2 : 0|1|2|3))"], diff --git a/tests/Faker.php b/tests/Faker.php new file mode 100644 index 0000000..42a6ff1 --- /dev/null +++ b/tests/Faker.php @@ -0,0 +1,75 @@ +, + * resource: resource, + * object: object, + * numeric-string: numeric-string, + * null: null, + * mixed: mixed, + * true: true, + * false: false, + * callable: callable, + * iterable: iterable, + * array-key: array-key, + * positive-int: positive-int, + * negative-int: negative-int, + * non-positive-int: non-positive-int, + * non-negative-int: non-negative-int, + * non-zero-int: non-zero-int, + * } + */ +class Faker +{ + /** + * @var Types $types + * @phpstan-ignore-next-line + */ + private static $types; + + /** + * @template T of string + * @param T $type + * @return Types[T] + */ + public static function fake(string $type): mixed + { + return self::$types[$type]; + } + + /** + * @template T of string + * @template K of string + * @param T $valueType + * @param K $keyType + * @return array + */ + public static function fakeArray(string $valueType, string $keyType = 'array-key'): mixed + { + return [$_GET[$keyType], $_GET[$valueType]]; + } + + /** + * @template T of non-empty-array> + * @param T $types + * @return Types[value-of] + */ + public static function or(array $types): mixed + { + foreach ($types as $type) { + if ($_GET['thing'] === $type) { + return self::fake($type); + } + } + return self::fake($types[0]); + } +} diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 00563dc..92c12f0 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -44,6 +44,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/paginate_links.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/rest_ensure_response.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/size_format.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/stripslashes.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/term_exists.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/validate_file.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/wp_debug_backtrace_summary.php'); diff --git a/tests/data/stripslashes.php b/tests/data/stripslashes.php new file mode 100644 index 0000000..83da2a5 --- /dev/null +++ b/tests/data/stripslashes.php @@ -0,0 +1,27 @@ +