diff --git a/components/CookieUser.php b/components/CookieUser.php index 7d46a74929..b01c4e3c03 100644 --- a/components/CookieUser.php +++ b/components/CookieUser.php @@ -10,7 +10,6 @@ class CookieUser { public string $userToken; public string $name; - private static ?CookieUser $userCache = null; public static function getFromCookieOrCache(): ?CookieUser { @@ -20,8 +19,6 @@ public static function getFromCookieOrCache(): ?CookieUser $cookieUser->name = trim($matches['name']); return $cookieUser; - } elseif (self::$userCache) { - return self::$userCache; } else { return null; } diff --git a/components/HTMLTools.php b/components/HTMLTools.php index 966838143d..6597f17a1e 100644 --- a/components/HTMLTools.php +++ b/components/HTMLTools.php @@ -144,7 +144,7 @@ public static function wrapOrphanedTextWithP(string $html): string $dom = self::html2DOM($html); $hasChanged = false; - /** @var \DOMElement $wrapP */ + /** @var \DOMElement|null $wrapP */ $wrapP = null; for ($i = 0; $i < $dom->childNodes->length; $i++) { $childNode = $dom->childNodes->item($i); @@ -382,7 +382,7 @@ private static function explicitlySetLiValuesInt(\DOMElement $element, ?int $cou if ($element->nodeName === 'ol' || $element->nodeName === 'ul') { $liCount = 0; $start = $element->getAttribute('start'); - if ($start !== null && $start > 0) { + if ($start > 0) { $liCount = intval($start) - 1; } $formatting = self::OL_DECIMAL_DOT; @@ -453,7 +453,7 @@ private static function sectionSimpleHTMLInt(\DOMElement $element, int &$paragra $lino = 0; if ($element->nodeName === 'ol') { $start = $element->getAttribute('start'); - if ($start !== null && $start > 0) { + if ($start > 0) { $lino = intval($start) - 1; } } @@ -927,7 +927,6 @@ public static function renderDomToHtml(\DOMNode $node, bool $skipBody = false): public static function getDomDebug(\DOMNode $node): array { if (is_a($node, \DOMElement::class)) { - /** @var \DOMNode $node */ $nodeArr = [ 'name' => $node->nodeName, 'classes' => '', diff --git a/components/MotionNumbering.php b/components/MotionNumbering.php index 03189672aa..ba5eea20cc 100644 --- a/components/MotionNumbering.php +++ b/components/MotionNumbering.php @@ -15,8 +15,10 @@ public static function getNewTitlePrefixInternal(string $titlePrefix): string $new = \Yii::t('motion', 'prefix_new_code'); $newMatch = preg_quote($new, '/'); if (preg_match('/' . $newMatch . '/i', $titlePrefix)) { - /** @var string[] $parts */ $parts = preg_split('/(' . $newMatch . '\s*)/i', $titlePrefix, -1, PREG_SPLIT_DELIM_CAPTURE); + if ($parts === false) { + return $titlePrefix . $new; + } $last = (int)array_pop($parts); $last = ($last > 0 ? $last + 1 : 2); // NEW BLA -> NEW 2 $parts[] = $last; diff --git a/components/diff/Diff.php b/components/diff/Diff.php index 27a6f78e4c..bf3ecb5e19 100644 --- a/components/diff/Diff.php +++ b/components/diff/Diff.php @@ -63,12 +63,19 @@ public static function tokenizeLine(string $line): array $line = static::normalizeForDiff($line); $htmlTag = '/(
\n+|<[^>]+>)/siu'; $arr = preg_split($htmlTag, $line, -1, PREG_SPLIT_DELIM_CAPTURE); + if ($arr === false) { + throw new \RuntimeException('Failed to parse line: ' . $line); + } $out = []; foreach ($arr as $arr2) { if (preg_match($htmlTag, $arr2)) { $out[] = $arr2; } else { - foreach (preg_split('/([ \-.:])/', $arr2, -1, PREG_SPLIT_DELIM_CAPTURE) as $tok) { + $tokens = preg_split('/([ \-.:])/', $arr2, -1, PREG_SPLIT_DELIM_CAPTURE); + if ($tokens === false) { + throw new \RuntimeException('Failed to parse line: ' . $arr2); + } + foreach ($tokens as $tok) { if ($tok === ' ' || $tok === '-') { if (count($out) == 0) { $out[] = $tok; @@ -410,8 +417,10 @@ public static function findFirstOccurrenceIgnoringTags(string $haystack, string if ($firstTag === false || $firstTag > $first) { return $first; } - /** @var string[] $parts */ $parts = preg_split('/(<[^>]*>)/', $haystack, -1, PREG_SPLIT_DELIM_CAPTURE); + if ($parts === false) { + throw new \RuntimeException('Failed to parse line: ' . $haystack); + } $pos = 0; for ($i = 0; $i < count($parts); $i++) { if (($i % 2) === 0) { @@ -437,8 +446,10 @@ public function getUnchangedPrefixPostfix(string $orig, string $new, string $dif return ['', $orig, $new, $diff, '']; } - /** @var string[] $parts */ - $parts = preg_split('/###(INS|DEL)_(START|END)###/siuU', $diff); + $parts = preg_split('/###(INS|DEL)_(START|END)###/siuU', $diff); + if ($parts === false) { + throw new \RuntimeException('Failed to parse line: ' . $diff); + } $prefix = $parts[0]; $postfix = $parts[(int)count($parts) - 1]; $prefixLen = (int)grapheme_strlen($prefix); @@ -595,7 +606,10 @@ public function convertToWordArray(string $diff, ?int $amendmentId = null): arra $words = [ 0 => new DiffWord(), ]; - $diffPartArr = preg_split('/(###(?:INS|DEL)_(?:START|END)###)/siu', $diff, -1, PREG_SPLIT_DELIM_CAPTURE); + $diffPartArr = preg_split('/(###(?:INS|DEL)_(?:START|END)###)/siu', $diff, -1, PREG_SPLIT_DELIM_CAPTURE); + if ($diffPartArr === false) { + throw new \RuntimeException('Failed to parse line: ' . $diff); + } $inDel = $inIns = false; $originalWordPos = 0; $pendingOpeningDel = false; diff --git a/components/diff/DiffRenderer.php b/components/diff/DiffRenderer.php index d5788f3a53..c34beeaf62 100644 --- a/components/diff/DiffRenderer.php +++ b/components/diff/DiffRenderer.php @@ -117,15 +117,6 @@ public static function nodeStartInsDel(\DOMNode $node): bool return false; } - /** - * @internal - * @return string[] - */ - public function splitTextByMarkers(string $text): array - { - return preg_split('/###(INS|DEL)_(START|END)###/siu', $text); - } - public static function nodeToPlainText(\DOMNode $node): string { $text = $node->nodeValue; @@ -232,6 +223,9 @@ public function textToNodes(string $text, ?string $inIns, ?string $inDel, ?\DOMN while ($text !== '') { if ($inIns !== null) { $split = preg_split('/###INS_END###/siu', $text, 2); + if ($split === false) { + throw new \RuntimeException('Could not parse text: ' . $text); + } if ($split[0] !== '') { $newText = $this->nodeCreator->createTextNode($split[0]); if ($lastIsIns) { @@ -250,6 +244,9 @@ public function textToNodes(string $text, ?string $inIns, ?string $inDel, ?\DOMN } } elseif ($inDel !== null) { $split = preg_split('/###DEL_END###/siu', $text, 2); + if ($split === false) { + throw new \RuntimeException('Could not parse text: ' . $text); + } if ($split[0] !== '') { $newText = $this->nodeCreator->createTextNode($split[0]); if ($lastIsDel) { @@ -267,8 +264,10 @@ public function textToNodes(string $text, ?string $inIns, ?string $inDel, ?\DOMN $text = ''; } } else { - /** @var string[] $split */ $split = preg_split('/(###(?:INS|DEL)_START([^#]{0,20})###)/siu', $text, 2, PREG_SPLIT_DELIM_CAPTURE); + if ($split === false) { + throw new \RuntimeException('Could not parse text: ' . $text); + } if (count($split) === 4) { if ($split[0] !== '') { $newText = $this->nodeCreator->createTextNode($split[0]);