Object whose $str has been converted to an URL slug.
* + * @phpstan-param ASCII::*_LANGUAGE_CODE $language + * * @psalm-suppress ImpureMethodCall :/ */ public function urlify( From 61662fdfbc9d83b6625c8dea0f40ac027e06f70e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Apr 2026 02:14:03 +0000 Subject: [PATCH 04/10] Polish CI and phpstan comments Agent-Logs-Url: https://github.com/voku/Stringy/sessions/c994b095-7d56-4d26-ab6a-452e4181411e Co-authored-by: voku <264695+voku@users.noreply.github.com> --- .github/workflows/ci.yml | 1 - phpstan.neon | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d02b8e9..b2b7f97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,6 @@ jobs: - name: Install dependencies run: | composer require --dev --no-update "phpunit/phpunit:${{ matrix.phpunit }}" - if [[ "${{ matrix.composer }}" == "lowest" ]]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable fi; diff --git a/phpstan.neon b/phpstan.neon index 7ab0718..ea39177 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,6 @@ parameters: + # Analyze against the minimum supported runtime so PHP 7.1 compatibility + # issues are caught even when phpstan itself runs on a newer PHP in CI. phpVersion: 70100 level: 8 paths: From 471b26b2f8d2e2311c001d005e9e9d57849df1e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Apr 2026 02:25:27 +0000 Subject: [PATCH 05/10] Handle jsonSerialize deprecation on PHP 8.1+ Agent-Logs-Url: https://github.com/voku/Stringy/sessions/fb88e031-1c45-47d1-a3d4-7675a49c19b9 Co-authored-by: voku <264695+voku@users.noreply.github.com> --- src/JsonSerializableReturnTypeTrait.php | 43 +++++++++++++++++++++++++ src/Stringy.php | 19 +++-------- 2 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 src/JsonSerializableReturnTypeTrait.php diff --git a/src/JsonSerializableReturnTypeTrait.php b/src/JsonSerializableReturnTypeTrait.php new file mode 100644 index 0000000..f7de2fa --- /dev/null +++ b/src/JsonSerializableReturnTypeTrait.php @@ -0,0 +1,43 @@ += 80100) { + eval(<<<'PHP' +namespace Stringy; + +trait JsonSerializableReturnTypeTrait +{ + /** + * Returns value which can be serialized by json_encode(). + * + * @psalm-mutation-free + * + * @return string The current value of the $str property + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return (string) $this; + } +} +PHP + ); +} else { + trait JsonSerializableReturnTypeTrait + { + /** + * Returns value which can be serialized by json_encode(). + * + * @psalm-mutation-free + * + * @return string The current value of the $str property + */ + public function jsonSerialize() + { + return (string) $this; + } + } +} diff --git a/src/Stringy.php b/src/Stringy.php index 51cf2c4..fd9ebb9 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -4,6 +4,8 @@ namespace Stringy; +require_once __DIR__ . '/JsonSerializableReturnTypeTrait.php'; + use Defuse\Crypto\Crypto; use voku\helper\AntiXSS; use voku\helper\ASCII; @@ -33,6 +35,8 @@ */ class Stringy implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonSerializable { + use JsonSerializableReturnTypeTrait; + /** * An instance's string. * @@ -2503,21 +2507,6 @@ public function isWhitespace(): bool return $this->isBlank(); } - /** - * Returns value which can be serialized by json_encode(). - * - * EXAMPLE:
- *
- *
- * @psalm-mutation-free
- *
- * @return string The current value of the $str property
- */
- public function jsonSerialize()
- {
- return (string) $this;
- }
-
/**
* Convert the string to kebab-case.
*
From 087d58c0d6540d7364bf2c71a02071633998bdc4 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 22 Apr 2026 02:26:32 +0000
Subject: [PATCH 06/10] Rely on trait autoload for jsonSerialize shim
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/fb88e031-1c45-47d1-a3d4-7675a49c19b9
Co-authored-by: voku <264695+voku@users.noreply.github.com>
---
src/Stringy.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/Stringy.php b/src/Stringy.php
index fd9ebb9..776e726 100644
--- a/src/Stringy.php
+++ b/src/Stringy.php
@@ -4,8 +4,6 @@
namespace Stringy;
-require_once __DIR__ . '/JsonSerializableReturnTypeTrait.php';
-
use Defuse\Crypto\Crypto;
use voku\helper\AntiXSS;
use voku\helper\ASCII;
From 0611d9eee1244c00bef7490a6e4ba91c8c5b661a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 22 Apr 2026 02:27:24 +0000
Subject: [PATCH 07/10] Remove eval from jsonSerialize compatibility shim
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/fb88e031-1c45-47d1-a3d4-7675a49c19b9
Co-authored-by: voku <264695+voku@users.noreply.github.com>
---
.../JsonSerializableReturnTypeTraitPhp81.php | 24 +++++++++++++++++++
src/JsonSerializableReturnTypeTrait.php | 21 +---------------
2 files changed, 25 insertions(+), 20 deletions(-)
create mode 100644 resources/JsonSerializableReturnTypeTraitPhp81.php
diff --git a/resources/JsonSerializableReturnTypeTraitPhp81.php b/resources/JsonSerializableReturnTypeTraitPhp81.php
new file mode 100644
index 0000000..de330b3
--- /dev/null
+++ b/resources/JsonSerializableReturnTypeTraitPhp81.php
@@ -0,0 +1,24 @@
+= 80100) {
- eval(<<<'PHP'
-namespace Stringy;
-
-trait JsonSerializableReturnTypeTrait
-{
- /**
- * Returns value which can be serialized by json_encode().
- *
- * @psalm-mutation-free
- *
- * @return string The current value of the $str property
- */
- #[\ReturnTypeWillChange]
- public function jsonSerialize()
- {
- return (string) $this;
- }
-}
-PHP
- );
+ require_once __DIR__ . '/../resources/JsonSerializableReturnTypeTraitPhp81.php';
} else {
trait JsonSerializableReturnTypeTrait
{
From 5490dd3430a22c5e9befb60850b2d113f11d8da8 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 22 Apr 2026 10:47:21 +0000
Subject: [PATCH 08/10] Move PHP 8.1 trait to src, flip to default/fallback
pattern
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/807a633f-9165-4e29-b1e9-f29041d1a64f
Co-authored-by: voku <264695+voku@users.noreply.github.com>
---
phpstan.neon | 4 ++++
src/JsonSerializableReturnTypeTrait.php | 6 +++---
{resources => src}/JsonSerializableReturnTypeTraitPhp81.php | 0
3 files changed, 7 insertions(+), 3 deletions(-)
rename {resources => src}/JsonSerializableReturnTypeTraitPhp81.php (100%)
diff --git a/phpstan.neon b/phpstan.neon
index ea39177..5e251e7 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -5,6 +5,10 @@ parameters:
level: 8
paths:
- %currentWorkingDirectory%/src/
+ excludePaths:
+ # This file is only loaded on PHP 8.1+ by JsonSerializableReturnTypeTrait.php.
+ # It defines the same trait name, so excluding it prevents a duplicate-symbol error.
+ - %currentWorkingDirectory%/src/JsonSerializableReturnTypeTraitPhp81.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# false-positive?
diff --git a/src/JsonSerializableReturnTypeTrait.php b/src/JsonSerializableReturnTypeTrait.php
index bb3b608..b42d8ca 100644
--- a/src/JsonSerializableReturnTypeTrait.php
+++ b/src/JsonSerializableReturnTypeTrait.php
@@ -4,9 +4,7 @@
namespace Stringy;
-if (\PHP_VERSION_ID >= 80100) {
- require_once __DIR__ . '/../resources/JsonSerializableReturnTypeTraitPhp81.php';
-} else {
+if (\PHP_VERSION_ID < 80100) {
trait JsonSerializableReturnTypeTrait
{
/**
@@ -21,4 +19,6 @@ public function jsonSerialize()
return (string) $this;
}
}
+} else {
+ require_once __DIR__ . '/JsonSerializableReturnTypeTraitPhp81.php';
}
diff --git a/resources/JsonSerializableReturnTypeTraitPhp81.php b/src/JsonSerializableReturnTypeTraitPhp81.php
similarity index 100%
rename from resources/JsonSerializableReturnTypeTraitPhp81.php
rename to src/JsonSerializableReturnTypeTraitPhp81.php
From c7a6c48f05bf21b5e333a2eab7220f4e1e273368 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 22 Apr 2026 11:41:02 +0000
Subject: [PATCH 09/10] fix: exclude PHP81 trait shim from PHPUnit coverage
scan
Agent-Logs-Url: https://github.com/voku/Stringy/sessions/2b5f4210-b56e-44c2-bed8-9a5bb2986468
Co-authored-by: voku <264695+voku@users.noreply.github.com>
---
phpunit.xml.dist | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index cddd6d0..308ffc2 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -4,6 +4,11 @@