Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
28.57% covered (danger)
28.57%
2 / 7
CRAP
21.74% covered (danger)
21.74%
5 / 23
Text
0.00% covered (danger)
0.00%
0 / 1
28.57% covered (danger)
28.57%
2 / 7
94.01
21.74% covered (danger)
21.74%
5 / 23
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 getNodeType
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getNodeName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 _subclass_isEqualNode
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 _subclass_cloneNodeShallow
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 splitText
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 9
 wholeText
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 6
<?php
declare( strict_types = 1 );
// phpcs:disable Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps
namespace Wikimedia\Dodo;
/******************************************************************************
 * Text.php
 * --------
 */
class Text extends CharacterData implements \Wikimedia\IDLeDOM\Text {
    // DOM mixins
    use Slottable;
    // Stub out methods not yet implemented.
    use \Wikimedia\IDLeDOM\Stub\Text;
    use UnimplementedTrait;
    // Helper functions from IDLeDOM
    use \Wikimedia\IDLeDOM\Helper\Text;
    /**
     * @param Document $doc
     * @param string $data
     */
    public function __construct( Document $doc, string $data ) {
        parent::__construct();
        $this->_ownerDocument = $doc;
        $this->_data = $data;
    }
    /**
     * @inheritDoc
     */
    public function getNodeType() : int {
        return Node::TEXT_NODE;
    }
    /**
     * @inheritDoc
     */
    public function getNodeName() : string {
        return "#text";
    }
    /**
     * @param Node $node
     * @return bool
     */
    public function _subclass_isEqualNode( Node $node ): bool {
        return ( $this->_data === $node->_data );
    }
    /**
     * @return ?Node always Text
     */
    public function _subclass_cloneNodeShallow(): ?Node {
        return new Text( $this->_ownerDocument, $this->_data );
    }
    /**
     * @param int $offset
     * @return Text
     */
    public function splitText( $offset ) {
        if ( $offset > strlen( $this->_data ) || $offset < 0 ) {
            Util::error( "IndexSizeError" );
        }
        $newdata = substr( $this->_data, $offset );
        $newnode = $this->_ownerDocument->createTextNode( $newdata );
        $this->setNodeValue( substr( $this->_data, 0, $offset ) );
        $parent = $this->getParentNode();
        if ( $parent !== null ) {
            $parent->insertBefore( $newnode, $this->getNextSibling() );
        }
        return $newnode;
    }
    /**
     * @return string
     */
    public function wholeText() {
        $result = [ $this->getTextContent() ?? '' ];
        for ( $n = $this->getNextSibling(); $n !== null; $n = $n->getNextSibling() ) {
            if ( $n->getNodeType() !== Node::TEXT_NODE ) {
                break;
            }
            $result[] = $n->getTextContent() ?? '';
        }
        return implode( '', $result );
    }
}