Simplify the code to calculate the number of paragraphs to retain
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 09:58:09 +0000 (11:58 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 16:34:04 +0000 (18:34 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php

index 2ba481cc3b25ef428728f9dff61ef3c3c1f97a07..4bf2fdafab9790d34fc98be24b74c0d95f682eb1 100644 (file)
@@ -83,13 +83,8 @@ final class HtmlOutputNodeNormalizer
                 // We need to reduce the number of paragraphs by half, unless it
                 // is an uneven number in which case we need to remove one
                 // additional paragraph.
-                if ($offset % 2 === 1) {
-                    // 2 -> 1, 4 -> 2
-                    $numberOfParagraphsToRemove = \ceil($offset / 2);
-                } else {
-                    // 3 -> 1, 5 -> 2
-                    $numberOfParagraphsToRemove = \ceil($offset / 2) + 1;
-                }
+                $totalNumberOfParagraphs = $offset + 1;
+                $numberOfParagraphsToRemove = \ceil($totalNumberOfParagraphs / 2);
 
                 $removeParagraphs = \array_slice($paragraphs, $i, $numberOfParagraphsToRemove);
                 foreach ($removeParagraphs as $paragraph) {