From de2c75b004eb41cc7892a33e398c203c1c8299fc Mon Sep 17 00:00:00 2001 From: Markus Staab <maggus.staab@googlemail.com> Date: Thu, 28 Nov 2024 11:27:34 +0100 Subject: [PATCH 1/6] Remove Travis CI badge from README (#472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/thecodingmachine/safe/commit/56ab9335d67c505d6eeae411584e2066e7a1ac0e#diff-d50e69bd6199d6bb04c726d9b3da9a0bbbd5731ad3ef6500f42e07ff10fb98a9 Co-authored-by: Viktor Szépe <viktor@szepe.net> --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 137bf690..49df6074 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ [![Latest Version](https://poser.pugx.org/thecodingmachine/safe/v/stable.svg)](https://packagist.org/packages/thecodingmachine/safe) [![Total Downloads](https://poser.pugx.org/thecodingmachine/safe/downloads.svg)](https://packagist.org/packages/thecodingmachine/safe) [![License](https://poser.pugx.org/thecodingmachine/safe/license.svg)](https://packagist.org/packages/thecodingmachine/safe) -[![Build Status](https://travis-ci.org/thecodingmachine/safe.svg?branch=master)](https://travis-ci.org/thecodingmachine/safe) [![Continuous Integration](https://github.com/thecodingmachine/safe/workflows/Continuous%20Integration/badge.svg)](https://github.com/thecodingmachine/safe/actions) [![codecov](https://codecov.io/gh/thecodingmachine/safe/branch/master/graph/badge.svg)](https://codecov.io/gh/thecodingmachine/safe) From d15d3ac0286be4b32c99fc0754aabe82165a45b2 Mon Sep 17 00:00:00 2001 From: Markus Staab <maggus.staab@googlemail.com> Date: Thu, 28 Nov 2024 11:30:19 +0100 Subject: [PATCH 2/6] fix named arg w json_decode to be consistent with php (#473) Co-authored-by: dpi <pro@danielph.in> --- lib/special_cases.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/special_cases.php b/lib/special_cases.php index 8b9e12ff..71159d8f 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -25,7 +25,7 @@ * Wrapper for json_decode that throws when an error occurs. * * @param string $json JSON data to parse - * @param bool $assoc When true, returned objects will be converted + * @param bool $associative When true, returned objects will be converted * into associative arrays. * @param int<1, max> $depth User specified recursion depth. * @param int $flags Bitmask of JSON decode options. @@ -34,9 +34,9 @@ * @throws JsonException if the JSON cannot be decoded. * @link http://www.php.net/manual/en/function.json-decode.php */ -function json_decode(string $json, bool $assoc = false, int $depth = 512, int $flags = 0): mixed +function json_decode(string $json, bool $associative = false, int $depth = 512, int $flags = 0): mixed { - $data = \json_decode($json, $assoc, $depth, $flags); + $data = \json_decode($json, $associative, $depth, $flags); if (!($flags & JSON_THROW_ON_ERROR) && JSON_ERROR_NONE !== json_last_error()) { throw JsonException::createFromPhpError(); } From 8ebff34a803373bc244bb0853657854a38364651 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet <ceesjank@gmail.com> Date: Thu, 28 Nov 2024 11:31:22 +0100 Subject: [PATCH 3/6] Drop double \ from parameter types (#445) Currently the generation of files is failing due to ?\\DateTimeZone in a nullable parameter on at least one function. This changeset fixes that a bit crudely but effectively. --- generator/src/WritePhpFunction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/WritePhpFunction.php b/generator/src/WritePhpFunction.php index b34f6e9d..f552aae3 100644 --- a/generator/src/WritePhpFunction.php +++ b/generator/src/WritePhpFunction.php @@ -170,7 +170,7 @@ private function displayParamsWithType(array $params): string $paramsAsString[] = $paramAsString; } - return implode(', ', $paramsAsString); + return str_replace('\\\\', '\\', implode(', ', $paramsAsString)); } private function printFunctionCall(Method $function): string From f6f479f51c537d6a5bdd2ee4395eddb3208421f6 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky <simon@podlipsky.net> Date: Thu, 28 Nov 2024 11:34:09 +0100 Subject: [PATCH 4/6] Add custom base64_decode fcn mapping (#431) Phpstan defines multiple variants now which breaks it for Safe https://github.com/phpstan/phpstan-src/blob/80ce9a404787133ff3fa266f90602728bf1c349c/resources/functionMap.php#L410-L411 --- generator/config/CustomPhpStanFunctionMap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/generator/config/CustomPhpStanFunctionMap.php b/generator/config/CustomPhpStanFunctionMap.php index 241488ec..22ad1a21 100644 --- a/generator/config/CustomPhpStanFunctionMap.php +++ b/generator/config/CustomPhpStanFunctionMap.php @@ -6,6 +6,7 @@ */ return [ + 'base64_decode' => ['string|false', 'str'=>'string', 'strict='=>'bool'], // base64_decode returns false only in strict mode https://github.com/phpstan/phpstan-src/commit/cee66721266ae05f3cc052f82391d2645d74d55f 'password_hash' => ['string|false', 'password'=>'string', 'algo'=>'int|string|null', 'options='=>'array'], 'com_load_typelib' => ['bool', 'typelib_name'=>'string', 'case_insensitive='=>'bool'], // case_insensitive is a bool 'sem_get' => ['resource|false', 'key'=>'int', 'max_acquire='=>'int', 'perm='=>'int', 'auto_release='=>'bool'], // auto_release is a bool From cb5fc31e67589522f4a17fbe2fe4e8927f909bc8 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky <simon@podlipsky.net> Date: Thu, 28 Nov 2024 11:34:31 +0100 Subject: [PATCH 5/6] Fix typo in "signatures" (#429) --- generator/src/PhpStanFunctions/PhpStanFunction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/PhpStanFunctions/PhpStanFunction.php b/generator/src/PhpStanFunctions/PhpStanFunction.php index c6054de2..7381f17a 100644 --- a/generator/src/PhpStanFunctions/PhpStanFunction.php +++ b/generator/src/PhpStanFunctions/PhpStanFunction.php @@ -21,7 +21,7 @@ class PhpStanFunction public function __construct(array $signature) { if (count($signature) < 1) { - throw new \RuntimeException('Invalid signoatures'); + throw new \RuntimeException('Invalid signatures'); } $this->returnType = new PhpStanType(\array_shift($signature)); foreach ($signature as $name => $type) { From 238a14195cc3283f26ec022bb8676fe2de538491 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky <simon@podlipsky.net> Date: Thu, 28 Nov 2024 11:34:56 +0100 Subject: [PATCH 6/6] Update testDetectFalsyFunction (#432) --- generator/tests/DocPageTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/generator/tests/DocPageTest.php b/generator/tests/DocPageTest.php index 27760ea7..f8a1e7d6 100644 --- a/generator/tests/DocPageTest.php +++ b/generator/tests/DocPageTest.php @@ -11,12 +11,11 @@ public function testDetectFalsyFunction() $pregMatch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/pcre/functions/preg-match.xml'); $implode = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/strings/functions/implode.xml'); $getCwd = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/dir/functions/getcwd.xml'); - $setTime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/datetime/settime.xml'); + $createFromFormat = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/datetime/createfromformat.xml'); $filesize = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/filesystem/functions/filesize.xml'); $mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml'); $fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml'); $arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml'); - $date = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/date.xml'); $classImplement = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/spl/functions/class-implements.xml'); $getHeaders = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/url/functions/get-headers.xml'); $gzopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/zlib/functions/gzopen.xml'); @@ -25,12 +24,11 @@ public function testDetectFalsyFunction() $this->assertTrue($pregMatch->detectFalsyFunction()); $this->assertFalse($implode->detectFalsyFunction()); $this->assertTrue($getCwd->detectFalsyFunction()); - $this->assertTrue($setTime->detectFalsyFunction()); + $this->assertTrue($createFromFormat->detectFalsyFunction()); $this->assertTrue($filesize->detectFalsyFunction()); $this->assertTrue($mcryptDecrypt->detectFalsyFunction()); $this->assertTrue($fsockopen->detectFalsyFunction()); $this->assertFalse($arrayReplace->detectFalsyFunction()); - $this->assertTrue($date->detectFalsyFunction()); $this->assertTrue($classImplement->detectFalsyFunction()); $this->assertTrue($getHeaders->detectFalsyFunction()); $this->assertTrue($gzopen->detectFalsyFunction());