src/Element/HTML/HTMLTableElement.php
/**
     * Creates a new HTMLTableRowElement (tr), and a new HTMLTableSectionElement
     * (tbody) if one does not already exist. It then inserts the newly created
     * tr element at the specified location. It returns the newly created tr
     * element.
     *
     * @see https://html.spec.whatwg.org/multipage/tables.html#dom-table-insertrow
     *
     * @throws \Rowbot\DOM\Exception\IndexSizeError If $index is < -1 or > the number of rows in the table.
     */
Creates a new HTMLTableRowElement (tr), and a new HTMLTableSectionElement
(tbody) if one does not already exist. It then inserts the newly created
tr element at the specified location. It returns the newly created tr
element.



@throws \Rowbot\DOM\Exception\IndexSizeError If $index is < -1 or > the number of rows in the table.
Creates a new HTMLTableRowElement ( tr ) and a new HTMLTableSectionElement ( tbody ) if one does not already exist . It then inserts the newly created tr element at the specified location . It returns the newly created tr element . @throws \ Rowbot \ DOM \ Exception \ IndexSizeError If $index is < - 1 or > the number of rows in the table .
public function insertRow(int $index = -1): HTMLTableRowElement
    {
        if ($index < -1) {
            throw new IndexSizeError();
        }
        $rows = $this->getRowsFilter()($this);
        $indexedRow = null;
        $lastRow = null;
        $numRows = 0;
        while ($rows->valid()) {
            $lastRow = $rows->current();
            if ($index === $numRows) {
                $indexedRow = $lastRow;
            }
            ++$numRows;
            $rows->next();
        }
        if ($index > $numRows) {
            throw new IndexSizeError();
        }
        $tableRow = ElementFactory::create($this->nodeDocument, 'tr', Namespaces::HTML);
        $node = $this->childNodes->last();
        $lastTbody = null;
        while ($node) {
            if ($node instanceof HTMLTableSectionElement && $node->localName === 'tbody') {
                $lastTbody = $node;
            }
            $node = $node->previousSibling;
        }
        if ($numRows === 0 && $lastTbody === null) {
            $tableBody = ElementFactory::create($this->nodeDocument, 'tbody', Namespaces::HTML);
            $tableBody->insertNode($tableRow, null);
            $this->insertNode($tableBody, null);
            return $tableRow;
        }
        if ($numRows === 0) {
            $lastTbody->insertNode($tableRow, null);
            return $tableRow;
        }
        if ($index === -1 || $index === $numRows) {
            $lastRow->parentNode->insertNode($tableRow, null);
            return $tableRow;
        }
        $indexedRow->parentNode->insertNode($tableRow, $indexedRow);
        return $tableRow;
    }
public function insertRow ( int $ index = - 1 ) : HTMLTableRowElement { if ( $ index < - 1 ) { throw new IndexSizeError ( ) ; } $ rows = $ this -> getRowsFilter ( ) ( $ this ) ; $ indexedRow = null ; $ lastRow = null ; $ numRows = 0 ; while ( $ rows -> valid ( ) ) { $ lastRow = $ rows -> current ( ) ; if ( $ index === $ numRows ) { $ indexedRow = $ lastRow ; } ++ $ numRows ; $ rows -> next ( ) ; } if ( $ index > $ numRows ) { throw new IndexSizeError ( ) ; } $ tableRow = ElementFactory :: create ( $ this -> nodeDocument , 'tr' , Namespaces :: HTML ) ; $ node = $ this -> childNodes -> last ( ) ; $ lastTbody = null ; while ( $ node ) { if ( $ node instanceof HTMLTableSectionElement && $ node -> localName === 'tbody' ) { $ lastTbody = $ node ; } $ node = $ node -> previousSibling ; } if ( $ numRows === 0 && $ lastTbody === null ) { $ tableBody = ElementFactory :: create ( $ this -> nodeDocument , 'tbody' , Namespaces :: HTML ) ; $ tableBody -> insertNode ( $ tableRow , null ) ; $ this -> insertNode ( $ tableBody , null ) ; return $ tableRow ; } if ( $ numRows === 0 ) { $ lastTbody -> insertNode ( $ tableRow , null ) ; return $ tableRow ; } if ( $ index === - 1 || $ index === $ numRows ) { $ lastRow -> parentNode -> insertNode ( $ tableRow , null ) ; return $ tableRow ; } $ indexedRow -> parentNode -> insertNode ( $ tableRow , $ indexedRow ) ; return $ tableRow ; }
Creates a new HTMLTableRowElement (tr), and a new HTMLTableSectionElement
 (tbody) if one does not already exist.
Creates a new HTMLTableRowElement ( tr ) and a new HTMLTableSectionElement ( tbody ) if one does not already exist .
// If index is less than −1 or greater than the number of elements in rows collection: //    The method must throw an "IndexSizeError" DOMException. // If the rows collection has zero elements in it, and the table has no tbody elements in it: // The method must table-create a tbody element, then table-create a tr element, then // append the tr element to the tbody element, then append the tbody element to the // table element, and finally return the tr element. // If the rows collection has zero elements in it: // The method must table-create a tr element, append it to the last tbody element in the // table, and return the tr element. // If index is −1 or equal to the number of items in rows collection: // The method must table-create a tr element, and append it to the parent of the last tr // element in the rows collection. Then, the newly created tr element must be returned. // Otherwise: // The method must table-create a tr element, insert it immediately before the indexth tr element in the rows // collection, in the same parent, and finally must return the newly created tr element.