@@ -344,7 +344,7 @@ protected function _getAttributeLocation($matches, $options)
344344 */
345345 protected function _getTagLocation ($ matches , $ options )
346346 {
347- $ tagName = strtolower ($ options ['tagName ' ]);
347+ $ tagName = isset ( $ options [ ' tagName ' ]) ? strtolower ($ options ['tagName ' ]) : '' ;
348348
349349 return $ options ['tagList ' ][$ tagName ] ?? (ucfirst ($ tagName ) . ' Text ' );
350350 }
@@ -386,6 +386,8 @@ protected function _applySpecialTagsFormat($tagHtml, $tagName, $trArr)
386386 */
387387 protected function _applySimpleTagsFormat ($ tagHtml , $ tagName , $ trArr )
388388 {
389+ $ tagHtml = $ tagHtml !== null ? $ tagHtml : '' ;
390+ $ tagName = $ tagName !== null ? $ tagName : '' ;
389391 $ simpleTags = substr (
390392 $ tagHtml ,
391393 0 ,
@@ -568,6 +570,7 @@ function ($tagHtml, $tagName, $trArr) {
568570 * @param callable $formatCallback
569571 *
570572 * @return void
573+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
571574 */
572575 private function _translateTags (string &$ content , array $ tagsList , callable $ formatCallback )
573576 {
@@ -621,7 +624,7 @@ private function _translateTags(string &$content, array $tagsList, callable $for
621624 && $ tagBodyOpenStartPosition > $ tagMatch [0 ][1 ]
622625 ) {
623626 $ tagHtmlHead = $ formatCallback ($ tagHtml , $ tagName , $ trArr );
624- $ headTranslateTags .= substr ($ tagHtmlHead , strlen ($ tagHtml ));
627+ $ headTranslateTags .= $ tagHtmlHead !== null ? substr ($ tagHtmlHead , strlen ($ tagHtml )) : '' ;
625628 } else {
626629 $ tagHtml = $ formatCallback ($ tagHtml , $ tagName , $ trArr );
627630 }
@@ -654,13 +657,14 @@ private function _translateTags(string &$content, array $tagsList, callable $for
654657 */
655658 private function _findEndOfTag ($ body , $ tagName , $ from )
656659 {
660+ $ body = $ body !== null ? $ body : '' ;
657661 $ openTag = '< ' . $ tagName ;
658662 $ closeTag = ($ this ->_isJson ? '< \\/ ' : '</ ' ) . $ tagName ;
659663 $ tagLength = strlen ($ tagName );
660664 $ length = $ tagLength + 1 ;
661665 $ end = $ from + 1 ;
662666 while (substr_count ($ body , $ openTag , $ from , $ length ) !== substr_count ($ body , $ closeTag , $ from , $ length )) {
663- $ end = strpos ($ body , ( string ) $ closeTag , $ end + $ tagLength + 1 );
667+ $ end = strpos ($ body , $ closeTag , $ end + $ tagLength + 1 );
664668 if ($ end === false ) {
665669 return false ;
666670 }
0 commit comments