Parser::fitsStack()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Kaloa\Renderer\Inigo;
4
5
use Kaloa\Renderer\Config;
6
use Kaloa\Renderer\Inigo\Handler\AbbrHandler;
7
use Kaloa\Renderer\Inigo\Handler\AmazonHandler;
8
use Kaloa\Renderer\Inigo\Handler\CodeHandler;
9
use Kaloa\Renderer\Inigo\Handler\FootnotesHandler;
10
use Kaloa\Renderer\Inigo\Handler\HTMLHandler;
11
use Kaloa\Renderer\Inigo\Handler\ImgHandler;
12
use Kaloa\Renderer\Inigo\Handler\ProtoHandler;
13
use Kaloa\Renderer\Inigo\Handler\QuoteHandler;
14
use Kaloa\Renderer\Inigo\Handler\SimpleHandler;
15
use Kaloa\Renderer\Inigo\Handler\UrlHandler;
16
use Kaloa\Renderer\Inigo\Handler\YouTubeHandler;
17
use Kaloa\Renderer\Inigo\Tag;
18
use SplStack;
19
20
/**
21
 * Inigo
22
 *
23
 * Do not use this renderer. The code is very (!) old. It's in here for
24
 * backwards compatibility reasons
25
 *
26
 * @author Marc Ermshaus
27
 */
28
final class Parser
29
{
30
    const TAG_OUTLINE          = 0x1;
31
    const TAG_INLINE           = 0x2;
32
    const TAG_PRE              = 0x4;
33
    const TAG_SINGLE           = 0x8;
34
    const TAG_CLEAR_CONTENT    = 0x10;
35
    const TAG_FORCE_PARAGRAPHS = 0x20;
36
37
    const PC_IMG_ALIGN_LEFT   = 0;
38
    const PC_IMG_ALIGN_RIGHT  = 1;
39
    const PC_IMG_ALIGN_CENTER = 2;
40
41
    /* "German" style
42
    const PC_PARSER_QUOTE_LEFT = '&#8222;';
43
    const PC_PARSER_QUOTE_RIGHT = '&#8220;');
44
    /**/
45
    /* "French" style */
46
    const PC_PARSER_QUOTE_LEFT  = '&raquo;';
47
    const PC_PARSER_QUOTE_RIGHT = '&laquo;';
48
    /**/
49
50
    private $s = '';
51
    private $m_stack;
52
    private $m_handlers;
53
    private $m_vars;
54
55
    /**
56
     *
57
     * @param Config $config
58
     */
59 18
    public function addDefaultHandlers(Config $config)
60
    {
61 18
        $this->addSetting('image-dir', $config->getResourceBasePath() . '/');
62
63
        // Example for multiple tags being displayed in the same way
64 18
        $this
65 18
        ->addHandler(new SimpleHandler('b|strong', Parser::TAG_INLINE, '<strong>', '</strong>'))
66 18
        ->addHandler(new SimpleHandler('i|em', Parser::TAG_INLINE, '<em>', '</em>'))
67
68 18
        ->addHandler(new SimpleHandler('icode', Parser::TAG_INLINE, '<code>', '</code>'))
69
70 18
        ->addHandler(new SimpleHandler('u', Parser::TAG_INLINE, '<u>', '</u>'))
71 18
        ->addHandler(new SimpleHandler('s|strike', Parser::TAG_INLINE, '<s>', '</s>'))
72
73
        // Used to display other tags. Tags with type Parser::TAG_PRE will not be parsed
74
        // This tag belongs also to two types
75
76 18
        ->addHandler(new SimpleHandler('off|noparse', Parser::TAG_INLINE | Parser::TAG_PRE, '', ''))
77 18
        ->addHandler(new SimpleHandler('var', Parser::TAG_INLINE | Parser::TAG_PRE, '<var>', '</var>'))
78
//        ->addHandler(new SimpleHandler(
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
//            'quote',
80
//            Parser::TAG_OUTLINE | Parser::TAG_FORCE_PARAGRAPHS,
81
//            '<blockquote>',
82
//            "</blockquote>\n\n"
83
//        ))
84
85 18
        ->addHandler(new QuoteHandler())
86
87
        /* Most replacements are rather simple */
88 18
        ->addHandler(new SimpleHandler('h1', Parser::TAG_OUTLINE, "<h1>", "</h1>\n\n"))
89 18
        ->addHandler(new SimpleHandler('h2', Parser::TAG_OUTLINE, "<h2>", "</h2>\n\n"))
90 18
        ->addHandler(new SimpleHandler('h3', Parser::TAG_OUTLINE, "<h3>", "</h3>\n\n"))
91 18
        ->addHandler(new SimpleHandler('h4', Parser::TAG_OUTLINE, "<h4>", "</h4>\n\n"))
92 18
        ->addHandler(new SimpleHandler('h5', Parser::TAG_OUTLINE, "<h5>", "</h5>\n\n"))
93 18
        ->addHandler(new SimpleHandler('h6', Parser::TAG_OUTLINE, "<h6>", "</h6>\n\n"))
94 18
        ->addHandler(new SimpleHandler('dl', Parser::TAG_OUTLINE, "<dl>", "\n\n</dl>\n\n"))
95 18
        ->addHandler(new SimpleHandler('dt', Parser::TAG_OUTLINE, "\n\n<dt>", "</dt>"))
96 18
        ->addHandler(new SimpleHandler('dd', Parser::TAG_OUTLINE, "\n<dd>", "</dd>"))
97 18
        ->addHandler(new SimpleHandler('ul', Parser::TAG_OUTLINE, "<ul>", "\n</ul>\n\n"))
98 18
        ->addHandler(new SimpleHandler('ol', Parser::TAG_OUTLINE, "<ol>", "\n</ol>\n\n"))
99 18
        ->addHandler(new SimpleHandler('li', Parser::TAG_OUTLINE, "\n<li>", "</li>"))
100 18
        ->addHandler(new SimpleHandler('table', Parser::TAG_OUTLINE, "<table>", "\n</table>\n\n"))
101 18
        ->addHandler(new SimpleHandler('tr', Parser::TAG_OUTLINE, "\n<tr>", "\n</tr>"))
102 18
        ->addHandler(new SimpleHandler('td', Parser::TAG_OUTLINE, "\n<td>", "</td>"))
103 18
        ->addHandler(new SimpleHandler('th', Parser::TAG_OUTLINE, "\n<th>", "</th>"))
104
105 18
        ->addHandler(new SimpleHandler('indent', Parser::TAG_OUTLINE, "<div style=\"margin-left: 30px;\">", "</div>\n\n"))
106 18
        ->addHandler(new SimpleHandler('center', Parser::TAG_OUTLINE, "<div style=\"text-align: center;\">", "</div>\n\n"))
107
108 18
        ->addHandler(new UrlHandler())
109 18
        ->addHandler(new ImgHandler())
110 18
        ->addHandler(new AmazonHandler())
111 18
        ->addHandler(new AbbrHandler())
112 18
        ->addHandler(new HTMLHandler())
113 18
        ->addHandler(new CodeHandler($config->getSyntaxHighlighter()))
114 18
        ->addHandler(new FootnotesHandler())
115 18
        ->addHandler(new YouTubeHandler());
116 18
    }
117
118
    /**
119
     *
120
     */
121 18
    public function addHandler(ProtoHandler $class)
122
    {
123 18
        $tags = explode('|', $class->name);
124
125 18
        $j = 0;
126
127 18
        foreach ($tags as $tag) {
128 18
            if (trim($tag) !== '') {
129 18
                $temp = array();
130 18
                $temp['name'] = $tag;
131
132 18
                if (is_array($class->type)) {
133 18
                    $temp['type'] = $class->type[$j];
134 18
                } else {
135 18
                    $temp['type'] = $class->type;
136
                }
137 18
                $temp['function'] = $class;
138
139 18
                $this->m_handlers[] = $temp;
140 18
            }
141
142 18
            $j++;
143 18
        }
144
145 18
        return $this;
146
    }
147
148
    /**
149
     *
150
     * @param string $name
151
     */
152 18
    public function addSetting($name, $value = '')
153
    {
154 18
        $this->m_vars[$name] = $value;
155 18
    }
156
157
    /**
158
     *
159
     */
160 17
    private function printHandlerMarkup(Tag $tag, $front = true, $tag_content = '')
161
    {
162 17
        $data = array();
163
164 17
        $data['tag']    = $tag->getName();
165 17
        $data['params'] = $tag->getAttributes();
166 17
        $data['front']  = $front;
167 17
        $data['vars']   = $this->m_vars;
168
169 17
        if ($tag_content !== '') {
170 4
            $data['content'] = $tag_content;
171 4
        }
172
173 17
        $i = 0;
174
175 17
        $tagCnt = count($this->m_handlers);
176
177 17
        while (($i < $tagCnt) && ($this->m_handlers[$i]['name'] !== $data['tag'])) {
178 17
            $i++;
179 17
        }
180
181 17
        return $this->m_handlers[$i]['function']->draw($data);
182
    }
183
184
    /**
185
     * Gets the next tag
186
     *
187
     * @param  string $s        String to parse
188
     * @param  int    $i        Offset where search begins
189
     * @param  int    $position Will be filled with next tag's offset (FALSE if
190
     *                          there are no more tags)
191
     * @return Tag
192
     */
193 17
    private function getNextTag(&$s, $i, &$position)
194
    {
195 17
        $j = mb_strpos($s, '[', $i);
196 17
        $k = mb_strpos($s, ']', $j + 1);
197
198 17
        if ($j === false || $k === false) {
199 16
            $position = false;
200 16
            return null;
201
        }
202
203 17
        $t = mb_substr($s, $j + 1, $k - ($j + 1));
204 17
        $l = mb_strrpos($t, '[');
205
206 17
        if ($l !== false) {
207 1
            $j += $l + 1;
208 1
        }
209
210 17
        $position = $j;
211
212 17
        $tagString = mb_substr($s, $j, $k - $j + 1);
213
214 17
        return new Tag($tagString, $this->getHandlers());
215
    }
216
217
    /**
218
     *
219
     * @return
220
     */
221 18
    public function getHandlers()
222
    {
223 18
        return $this->m_handlers;
224
    }
225
226
    /**
227
     *
228
     * @param string $s
229
     */
230 17
    public function parse($s)
231
    {
232
        // Cleaning the data that shall be parsed
233
234 17
        $s = trim($s);
235 17
        $s = str_replace("\r\n", "\n", $s);
236 17
        $s = str_replace("\r", "\n", $s);
237 17
        $s = preg_replace("/\n{3,}/", "\n\n", $s);
238
239 17
        $this->s = $s;
240
241
        // Preprocessing
242
243 17
        foreach ($this->m_handlers as $h) {
244 17
            $h['function']->initialize();
245 17
        }
246
247
        // Heavy lifting
248
249 17
        $ret = ($this->s === '') ? '' : $this->parseEx();
250
251
        // Postprocessing
252
253 16
        $data = array();
254 16
        $data['vars'] = $this->m_vars;
255
256 16
        foreach ($this->m_handlers as $h) {
257 16
            $data['tag'] = $h['name'];
258 16
            $ret = $h['function']->postProcess($ret, $data);
259 16
        }
260
261 16
        return trim($ret);
262
    }
263
264
    /**
265
     *
266
     * @param  Tag  $tag
267
     * @return bool
268
     */
269 17
    private function fitsStack(Tag $tag)
270
    {
271 17
        return ($tag->getName() === $this->m_stack->top()->getName());
272
    }
273
274
    /**
275
     *
276
     */
277 17
    private function parseEx()
278
    {
279 17
        $ret = '';
280
281 17
        $cdata = '';
282 17
        $last_pos = 0;
283 17
        $f_clear_content = false;
284
285 17
        $this->m_stack = new SplStack();
286
287 17
        $tag_content = '';
288 17
        $pos = 0;
289
290 17
        $tag = $this->getNextTag($this->s, $pos, $tag_pos);
291
292 17
        while ($tag !== null) {
293
            // Handle all occurences of "[...]" that are not part of the list of
294
            // registered tags (m_handlers) as CDATA
295 17
            $executeTag = $tag->isValid();
296
297
            // If we are parsing inside of a TAG_PRE tag, do not execute current
298
            // tag (= pretend it is CDATA) unless it is the corresponding
299
            // closing tag to the active TAG_PRE tag
300
            if ($executeTag
301 17
                && $this->m_stack->count() > 0
302 17
                && $this->m_stack->top()->isOfType(self::TAG_PRE)
303 17
            ) {
304 5
                $executeTag = ($tag->isClosingTag() && $this->fitsStack($tag));
305 5
            }
306
307 17
            if ($executeTag) {
308
                // Tag is valid and not inside of a TAG_PRE tag, execute it
309
310
                // Get CDATA
311 17
                $cdata .= $this->formatString(mb_substr(
312 17
                    $this->s,
313 17
                    $last_pos,
314
                    $tag_pos - $last_pos
315 17
                ));
316
317 17
                if (!$tag->isClosingTag()) {
318
                    // Opening tag
319
320 17
                    if (!$tag->isOfType(self::TAG_INLINE)) {
321
                        // Opening tag, outline tag
322
323 11 View Code Duplication
                        if ($f_clear_content) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
324
                            $tag_content .= $this->printCData($cdata, true);
325
                            $tag_content .= $this->printHandlerMarkup($tag, true);
326
                        } else {
327 11
                            $ret .= $this->printCData($cdata, true);
328 11
                            $ret .= $this->printHandlerMarkup($tag, true);
329
                        }
330
331
                        // If clear content tag, detect content and skip parsing
332 11
                        if ($tag->isOfType(self::TAG_CLEAR_CONTENT)) {
333 4
                            $f_clear_content = true;
334 4
                        }
335 11
                    } else {
336
                        // Opening tag, inline tag
337
338 10
                        $cdata .= $this->printHandlerMarkup($tag, true);
339
                    }
340
341 17
                    if (!$tag->isOfType(self::TAG_SINGLE)) {
342 17
                        $this->m_stack->push($tag);
343 17
                    }
344 17
                } else {
345
                    // Closing tag
346
347 17
                    if (!$tag->isOfType(self::TAG_INLINE)) {
348
                        // Closing tag, outline tag
349
350 11
                        if ($tag->isOfType(self::TAG_CLEAR_CONTENT)) {
351
                            // Closing tag, outline tag, clear content tag
352
353 4
                            $f_clear_content = false;
354 4
                            $tag_content .= $this->printCData($cdata);
355 4
                            $ret .= $this->printHandlerMarkup($tag, false, $tag_content);
356 4
                            $tag_content = '';
357 4 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
358
                            // Closing tag, outline tag, NOT clear content tag
359
360 7
                            if ($f_clear_content) {
361
                                $tag_content .= $this->printCData($cdata);
362
                                $tag_content .= $this->printHandlerMarkup($tag, false);
363
                            } else {
364 7
                                $ret .= $this->printCData($cdata);
365 7
                                $ret .= $this->printHandlerMarkup($tag, false);
366
                            }
367
                        }
368 11
                    } else {
369
                        // Closing tag, inline tag
370
371 9
                        $cdata .= $this->printHandlerMarkup($tag, false);
372
                    }
373
374
                    // Tag complete, remove from stack
375 17
                    if ($this->fitsStack($tag)) {
376 16
                        $this->m_stack->pop();
377 16
                    } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
378
                        // Markup error
379
                    }
380
                }
381 17
            } else {
382
                // Tag is CDATA
383
384 5
                $cdata .= $this->formatString(mb_substr(
385 5
                    $this->s,
386 5
                    $last_pos,
387
                    $tag_pos - $last_pos
388 5
                ) . $tag->getRawData());
389
            }
390
391 17
            $pos = $tag_pos + mb_strlen($tag->getRawData());
392 17
            $last_pos = $pos;
393 17
            $tag = $this->getNextTag($this->s, $pos, $tag_pos);
394 17
        }
395
396
        // Add string data after last tag as CDATA
397 16
        $cdata .= $this->formatString(mb_substr($this->s, $last_pos));
398 16
        $ret   .= $this->printCData($cdata, true);
399
400 16
        return $ret;
401
    }
402
403
    /**
404
     * Formats small pieces of CDATA
405
     *
406
     * @param  string $s
407
     * @return string
408
     */
409 17
    private function formatString($s)
410
    {
411 17
        static $last_tag = null;
412
413 17
        if ($this->m_stack->count() > 0
414 17
            && $this->m_stack->top()->isOfType(self::TAG_PRE)
415 17
        ) {
416
            // Do not format text inside of TAG_PRE tags
417
418 5
            return $s;
419
        }
420
421
        /*
422
         * TODO Replace double-quotes alternately with nice left and right
423
         * quotes
424
         */
425
426 17
        if ($last_tag !== null) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
427
            #echo $last_tag->getName();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
428 13
        }
429
430
        #echo '|' . $s . '|';
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
431
432
        // opening quote
433 17
        if ($last_tag !== null && $last_tag->isOfType(self::TAG_INLINE)) {
0 ignored issues
show
Bug introduced by
The method isOfType cannot be called on $last_tag (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
434 9
            $s = preg_replace('/([\s])&quot;/', '\1&raquo;', $s);
435
436
            #echo 'without';
437 9
        } else {
438 17
            $s = preg_replace('/([\s]|^)&quot;/', '\1&raquo;', $s);
439
        }
440
441
        // [X][X] will always be rendered as [S][S], not as [S][E]
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
442 17
        $s = preg_replace('/(&raquo;)&quot;/', '\1&raquo;', $s);
443
444
        #echo '<br />';
445
446
        // everything else is closing quote
447 17
        $s = str_replace('&quot;', '&laquo;', $s);
448
449 17
        $s = str_replace('--', '&ndash;', $s);
450
451 17
        if ($this->m_stack->count() > 0) {
452 13
            $last_tag = $this->m_stack->top();
453 13
        } else {
454 17
            $last_tag = null;
455
        }
456
457
        $e = function ($s) { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); };
458
459 17
        return $e($s);
460
    }
461
462
    /**
463
     * Formats whole blocks of CDATA
464
     *
465
     * @param  string $cdata
466
     * @param  boolean $outline
467
     * @return string
468
     */
469 17
    private function printCData(&$cdata, $outline = false)
470
    {
471 17
        $cdata = trim($cdata);
472 17
        $ret = '';
473
474
        /*$t = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
475
476
        if ($outline) {
477
            //echo $tag->getName();
478
            $t = ' yes';
479
        }*/
480
481 17
        if ($cdata === '') {
482 7
            return $ret;
483
        }
484
485
        //$e = function ($s) { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); };
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
486
487
        if (
488
            // All top-level blocks of CDATA have to be surrounded with <p>
489
            //($this->m_stack->size() == 0)
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
490
491
            // An outline tag starts after this CDATA block
492
            //|| ($tag != null)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
493
            /*||*/ $outline
494
495
            /*
496
             * Obvious. Should make a difference between \n and \n\n though
497
             * TODO
498
             */
499 15
            || (mb_strpos($cdata, "\n"))
500
501
            /* TODO Add FORCE_PARAGRAPHS parameter to tags (li?, blockquote, ...) */
502 9
            || ($this->m_stack->count() > 0
503 8
                    && $this->m_stack->top()->isOfType(self::TAG_FORCE_PARAGRAPHS))
504 15
        ) {
505 14
            if ($this->m_stack->count() > 0
506 14
                && $this->m_stack->top()->isOfType(self::TAG_PRE)
507 14
            ) {
508
                /*
509
                 * We are inside of a TAG_PRE tag and do not want the CDATA to
510
                 * be reformatted
511
                 */
512
513
                //$ret .= '[CDATA' . $t . ']' . $cdata . '[/CDATA]';
514 2
                $ret .= $cdata;
515 2
            } else {
516
                //$cdata = $e($cdata);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
517
518 13
                $cdata = str_replace("\n\n", '</p><p>', $cdata);
519 13
                $cdata = str_replace("\n", "<br />\n", $cdata);
520 13
                $cdata = str_replace('</p><p>', "</p>\n\n<p>", $cdata);
521
                //$ret .= '<p>' . '[CDATA' . $t . ']' . $cdata . '[/CDATA]' . "</p>\n";
522 13
                $ret .= '<p>' . $cdata . "</p>\n";
523
            }
524 14
        } else {
525
            /* No need to add paragraph markup (something like [li]CDATA[/li]) */
526
527
            //$ret .= '[CDATA' . $t . ']' . $cdata . '[/CDATA]';
528 7
            $ret .= $cdata;
529
        }
530
531 15
        $cdata = '';
532
533 15
        return $ret;
534
    }
535
}
536