Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
68.42% covered (warning)
68.42%
13 / 19
CRAP
82.10% covered (warning)
82.10%
133 / 162
DOMBuilder
0.00% covered (danger)
0.00%
0 / 1
68.42% covered (warning)
68.42%
13 / 19
78.97
82.10% covered (warning)
82.10%
133 / 162
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
8 / 8
 rethrowIfNotDomException
0.00% covered (danger)
0.00%
0 / 1
2.15
66.67% covered (warning)
66.67%
2 / 3
 getFragment
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 isCoerced
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 startDocument
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 createDocument
0.00% covered (danger)
0.00%
0 / 1
3.07
80.00% covered (warning)
80.00%
8 / 10
 endDocument
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 insertNode
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
10 / 10
 coerceName
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 createNode
0.00% covered (danger)
0.00%
0 / 1
13.15
80.00% covered (warning)
80.00%
32 / 40
 characters
0.00% covered (danger)
0.00%
0 / 1
7.19
84.21% covered (warning)
84.21%
16 / 19
 insertElement
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 endTag
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 doctype
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
7 / 7
 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
0.00% covered (danger)
0.00%
0 / 1
27.15
56.25% covered (warning)
56.25%
18 / 32
 removeNode
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 reparentChildren
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
<?php
namespace RemexHtml\DOM;
use RemexHtml\HTMLData;
use RemexHtml\Tokenizer\Attributes;
use RemexHtml\TreeBuilder\Element;
use RemexHtml\TreeBuilder\TreeBuilder;
use RemexHtml\TreeBuilder\TreeHandler;
/**
 * A TreeHandler which constructs a DOMDocument.
 *
 * Note that this class permits third-party `DOMImplementation`s
 * (documents other than `\DOMDocument`, nodes other than `\DOMNode`,
 * etc) and so no enforced PHP type hints are used which name these
 * classes directly.  For the sake of static type checking, the
 * types *in comments* are given as if the standard PHP `\DOM*`
 * classes are being used but at runtime everything is duck-typed.
 */
class DOMBuilder implements TreeHandler {
    /** @var string|null The name of the input document type */
    public $doctypeName;
    /** @var string|null The public ID */
    public $public;
    /** @var string|null The system ID */
    public $system;
    /**
     * @var int The quirks mode. May be either TreeBuilder::NO_QUIRKS,
     *   TreeBuilder::LIMITED_QUIRKS or TreeBuilder::QUIRKS to indicate
     *   no-quirks mode, limited-quirks mode or quirks mode respectively.
     */
    public $quirks;
    /** @var \DOMDocument */
    private $doc;
    /** @var callable|null */
    private $errorCallback;
    /** @var bool */
    private $suppressHtmlNamespace;
    /** @var bool */
    private $suppressIdAttribute;
    /** @var \DOMImplementation */
    private $domImplementation;
    /** @var class-string */
    private $domExceptionClass;
    /** @var bool */
    private $isFragment;
    /** @var bool */
    private $coerced;
    /**
     * @param array $options An associative array of options:
     *   - errorCallback : A function which is called on parse errors
     *   - suppressHtmlNamespace : omit the namespace when creating HTML
     *     elements. False by default.
     *   - suppressIdAttribute : don't call the nonstandard
     *     DOMElement::setIdAttribute() method while constructing elements.
     *     False by default (this method is needed for efficient
     *     DOMDocument::getElementById() calls).  Set to true if you are
     *     using a W3C spec-compliant DOMImplementation and wish to avoid
     *     nonstandard calls.
     *   - domImplementation: The DOMImplementation object to use.  If this
     *     parameter is missing or null, a new DOMImplementation object will
     *     be constructed using the `domImplementationClass` option value.
     *     You can use a third-party DOM implementation by passing in an
     *     appropriately duck-typed object here.
     *   - domImplementationClass: The string name of the DOMImplementation
     *     class to use.  Defaults to `\DOMImplementation::class` but
     *     you can use a third-party DOM implementation by passing
     *     an alternative class name here.
     *   - domExceptionClass: The string name of the DOMException
     *     class to use.  Defaults to `\DOMException::class` but
     *     you can use a third-party DOM implementation by passing
     *     an alternative class name here.
     */
    public function __construct( $options = [] ) {
        $options += [
            'suppressHtmlNamespace' => false,
            'suppressIdAttribute' => false,
            'errorCallback' => null,
            'domImplementation' => null,
            'domImplementationClass' => \DOMImplementation::class,
            'domExceptionClass' => \DOMException::class,
        ];
        $this->errorCallback = $options['errorCallback'];