Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
68.00% covered (warning)
68.00%
17 / 25
CRAP
97.21% covered (success)
97.21%
279 / 287
TreeBuilder
0.00% covered (danger)
0.00%
0 / 1
68.00% covered (warning)
68.00%
17 / 25
103
97.21% covered (success)
97.21%
279 / 287
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.00
90.91% covered (success)
90.91%
10 / 11
 startDocument
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
15 / 15
 adjustedCurrentNode
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
4 / 4
 appropriatePlace
0.00% covered (danger)
0.00%
0 / 1
9.02
94.12% covered (success)
94.12%
16 / 17
 insertCharacters
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 insertElement
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 insertForeign
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
7 / 7
 pop
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 doctype
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 comment
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 error
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 mergeAttributes
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
3 / 3
 closePInButtonScope
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 checkUnclosed
0.00% covered (danger)
0.00%
0 / 1
5.01
91.67% covered (success)
91.67%
11 / 12
 reconstructAFE
100.00% covered (success)
100.00%
1 / 1
9
100.00% covered (success)
100.00%
21 / 21
 adoptionAgency
100.00% covered (success)
100.00%
1 / 1
22
100.00% covered (success)
100.00%
91 / 91
 anyOtherEndTag
0.00% covered (danger)
0.00%
0 / 1
6.01
94.74% covered (success)
94.74%
18 / 19
 generateImpliedEndTags
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
8 / 8
 generateImpliedEndTagsThoroughly
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
7 / 7
 generateImpliedEndTagsAndPop
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 popAllUpToElement
0.00% covered (danger)
0.00%
0 / 1
4.02
88.89% covered (warning)
88.89%
8 / 9
 popAllUpToName
0.00% covered (danger)
0.00%
0 / 1
4.02
88.89% covered (warning)
88.89%
8 / 9
 popAllUpToNames
0.00% covered (danger)
0.00%
0 / 1
4.02
88.89% covered (warning)
88.89%
8 / 9
 clearStackBack
0.00% covered (danger)
0.00%
0 / 1
4.07
83.33% covered (warning)
83.33%
5 / 6
 stopParsing
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
12 / 12
<?php
namespace RemexHtml\TreeBuilder;
use RemexHtml\HTMLData;
use RemexHtml\PropGuard;
use RemexHtml\Tokenizer\Attributes;
use RemexHtml\Tokenizer\PlainAttributes;
use RemexHtml\Tokenizer\Tokenizer;
/**
 * TreeBuilder is the receiver of events from the InsertionMode subclasses,
 * and is responsible for forwarding events on to the TreeHandler, which is
 * responsible for constructing a DOM.
 *
 * TreeBuilder contains most of the state referred to by the "tree construction"
 * part of the HTML spec which is not handled elsewhere, such as the stack of
 * open elements and the list of active formatting elements.
 *
 * Miscellaneous helpers for InsertionMode subclasses are also in this class.
 *
 * https://www.w3.org/TR/2016/REC-html51-20161101/syntax.html
 */
class TreeBuilder {
    use PropGuard;
    // Quirks
    public const NO_QUIRKS = 0;
    public const LIMITED_QUIRKS = 1;
    public const QUIRKS = 2;
    // Insertion placement
    public const BEFORE = 0;
    public const UNDER = 1;
    public const ROOT = 2;
    // Configuration
    public $isIframeSrcdoc;
    public $scriptingFlag;
    public $ignoreErrors;
    public $ignoreNulls;
    // Objects
    /** @var TreeHandler */
    public $handler;
    /** @var SimpleStack */
    public $stack;
    /** @var ActiveFormattingElements */
    public $afe;
    /** @var Tokenizer */
    public $tokenizer;
    // State
    public $isFragment = false;
    public $fragmentContext;
    /** @var Element|null */
    public $headElement;
    /** @var Element|null */
    public $formElement;
    public $framesetOK = true;
    public $quirks = self::NO_QUIRKS;
    public $fosterParenting = false;
    public $pendingTableCharacters = [];
    private static $fosterTriggers = [
        'table' => true,
        'tbody' => true,
        'tfoot' => true,
        'thead' => true,
        'tr' => true
    ];
    private static $impliedEndTags = [
        'dd' => true,
        'dt' => true,
        'li' => true,
        'option' => true,
        'optgroup' => true,
        'p' => true,
        'rb' => true,
        'rp' => true,
        'rt' => true,
        'rtc' => true,
    ];
    private static $thoroughlyImpliedEndTags = [
        'caption' => true,
        'colgroup' => true,
        'dd' => true,
        'dt' => true,
        'li' => true,
        'optgroup' => true,
        'option' => true,
        'p' => true,
        'rb' => true,
        'rp' => true,
        'rt' => true,
        'rtc' => true,
        'tbody' => true,
        'td' => true,
        'tfoot' => true,
        'th' => true,
        'thead' => true,
        'tr' => true
    ];
    /**
     * @param TreeHandler $handler The handler which receives tree mutation events
     * @param array $options Associative array of options. The options are:
     *   - isIframeSrcdoc: True if the document is an iframe srcdoc document.
     *     Default false.
     *   - scriptingFlag: True if the scripting flag is enabled. Default true.
     *     Setting this to false cause the contents of <noscript> elements to be
     *     processed as normal content. The scriptingFlag option in the
     *     Tokenizer should be set to the same value.
     *   - ignoreErrors: True to ignore errors. This improves performance.
     *     Default false.
     *   - ignoreNulls: True to ignore null characters in the input, instead of
     *     following the specified behaviour. Default false.
     *   - scopeCache: True to use an implementation of the stack of open elements
     *     which caches "in scope" predicates. False to use a simpler
     *     implementation. Default true. Setting this to false may improve
     *     performance for simple documents, although at the expense of O(N^2)
     *     instead of O(N) worst case time order.
     */
    public function __construct( TreeHandler $handler, $options = [] ) {
        $this->handler = $handler;