From 15703639d1980f4227762e7803bbd61d4d8642ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Tue, 11 Nov 2025 17:54:08 +0400 Subject: [PATCH 1/2] Fix `MarkdownHighlightTrait::highlight()` behavior for PHP 8.3 --- .github/workflows/build.yml | 2 +- CHANGELOG.md | 1 + helpers/MarkdownHighlightTrait.php | 10 +++++++-- tests/commands/ApiControllerTest.php | 6 +++++ ...trollerTest__testGenerateBootstrap__1.html | 22 +++++++++---------- ...trollerTest__testGenerateBootstrap__2.html | 18 +++++++-------- ...trollerTest__testGenerateBootstrap__3.html | 18 +++++++-------- 7 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e334b932..dcba0778 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3cd8f6..810091a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 apidoc extension Change Log - Bug #313: Fix deprecation error `Method deprecated, use ::getParameters()` (mspirkov) - Bug #317: Fix `trim` deprecation errors `Passing null to parameter #1 ($string) of type string is deprecated` (mspirkov) - Bug #318: Fix deprecation errors `mb_convert_encoding(): Handling HTML entities via mbstring is deprecated` (mspirkov) +- Bug #312: Fix `MarkdownHighlightTrait::highlight()` behavior for PHP 8.3 (mspirkov) 3.0.7 February 13, 2025 diff --git a/helpers/MarkdownHighlightTrait.php b/helpers/MarkdownHighlightTrait.php index f2eb93b3..26a2ba39 100644 --- a/helpers/MarkdownHighlightTrait.php +++ b/helpers/MarkdownHighlightTrait.php @@ -78,8 +78,14 @@ public static function highlight($code, $language) $text = substr($text, 0, $pos) . substr($text, $pos + 6); } } - // remove \n and tags added by php - $text = substr(trim($text), 36, -16); + + // Remove prefixes and suffixes added by php + if (PHP_VERSION_ID >= 80300) { + // The `highlight_string` result format has changed since PHP8.3 + $text = substr($text, 34, -13); + } else { + $text = substr($text, 36, -16); + } return $text; } diff --git a/tests/commands/ApiControllerTest.php b/tests/commands/ApiControllerTest.php index 2c90d6dc..f8ced9ea 100644 --- a/tests/commands/ApiControllerTest.php +++ b/tests/commands/ApiControllerTest.php @@ -86,6 +86,12 @@ public function testGenerateBootstrap() $fileContent = preg_replace('/\s+href\s*=\s*(["\'])#[^"\']*\1/i', '', $fileContent); $fileContent = preg_replace('/\s+data-target\s*=\s*(["\'])#[^"\']*\1/i', '', $fileContent); + // The `highlight_string` result format has changed since PHP8.3 + // To prevent the tests from breaking, we remove some spaces. + $fileContent = str_replace('> $', '>$', $fileContent); + $fileContent = str_replace('> <', '><', $fileContent); + $fileContent = str_replace('= ', '= ', $fileContent); + $this->assertMatchesHtmlSnapshot($fileContent); $filesCount++; } diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html index 6e963d94..b6e85dda 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__1.html @@ -194,7 +194,7 @@

Property Details

-public integer $age null +publicinteger$age= null
@@ -217,7 +217,7 @@

Property Details

-public integer $birthDate null +publicinteger$birthDate= null
@@ -240,7 +240,7 @@

Property Details

-public string $name null +publicstring$name= null
@@ -272,7 +272,7 @@

Method Details

+publicintegergetAge ( ) @@ -296,7 +296,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -326,7 +326,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -368,7 +368,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -392,9 +392,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -422,7 +422,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+public abstractstringrender ( ) @@ -446,7 +446,7 @@

Method Details

-                abstract public function render();
+                abstractpublicfunctionrender();
 
             
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html index 47dcfbb8..3adb315e 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html @@ -194,7 +194,7 @@

Method Details

-public abstract string render ( )
+publicintegergetAge ( ) @@ -218,7 +218,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -251,7 +251,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -296,7 +296,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -320,9 +320,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -350,7 +350,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+publicstringrender ( ) @@ -374,10 +374,10 @@

Method Details

-                public function render()
+                publicfunctionrender()
 {
     // this method has `inheritdoc` tag in brackets
-    return 'This is a cat';
+    return'This is a cat';
 }
 
             
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html index 76141f0c..dd8e933b 100644 --- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html +++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html @@ -194,7 +194,7 @@

Method Details

-public string render ( )
+publicintegergetAge ( ) @@ -218,7 +218,7 @@

Method Details

-                public function getAge()
+                publicfunctiongetAge()
 {
     return time() - $this->birthDate;
 }
@@ -251,7 +251,7 @@ 

Method Details

-public integer getAge ( )
+publicintegergetSomething ( $test ) @@ -296,7 +296,7 @@

Method Details

-public integer getSomething ( $test )
$test
+publicbooleanisOlder ( $date ) @@ -320,9 +320,9 @@

Method Details

-                public function isOlder($date)
+                publicfunctionisOlder($date)
 {
-    return $this->getAge() > $date;
+    return$this->getAge() > $date;
 }
 
             
@@ -350,7 +350,7 @@

Method Details

-public boolean isOlder ( $date )
$date
+publicstringrender ( ) @@ -374,10 +374,10 @@

Method Details

-                public function render()
+                publicfunctionrender()
 {
     // this method has `inheritdoc` tag without brackets
-    return 'This is a dog';
+    return'This is a dog';
 }
 
             
From 18e40e5e3b73b54867dcd2aca59b3a6d44d79b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Tue, 11 Nov 2025 17:56:12 +0400 Subject: [PATCH 2/2] self review --- tests/commands/ApiControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/commands/ApiControllerTest.php b/tests/commands/ApiControllerTest.php index f8ced9ea..97f33523 100644 --- a/tests/commands/ApiControllerTest.php +++ b/tests/commands/ApiControllerTest.php @@ -87,7 +87,7 @@ public function testGenerateBootstrap() $fileContent = preg_replace('/\s+data-target\s*=\s*(["\'])#[^"\']*\1/i', '', $fileContent); // The `highlight_string` result format has changed since PHP8.3 - // To prevent the tests from breaking, we remove some spaces. + // To prevent test failures, we remove some spaces. $fileContent = str_replace('> $', '>$', $fileContent); $fileContent = str_replace('> <', '><', $fileContent); $fileContent = str_replace('= ', '= ', $fileContent);
-public string render ( )