Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 28
CargoOutlineTree
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 28
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addRow
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 categorizeRow
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 9
 addField
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 13
<?php
/**
 * A tree structure for holding the outline data.
 */
class CargoOutlineTree {
    public $mTree;
    public $mUnsortedRows;
    public $mFormattedValue;
    public function __construct( $rows = [], $formattedValue = null ) {
        $this->mTree = [];
        $this->mUnsortedRows = $rows;
        $this->mFormattedValue = $formattedValue;
    }
    public function addRow( $row ) {
        $this->mUnsortedRows[] = $row;
    }
    public function categorizeRow( $vals, $row, $formattedVals ) {
        foreach ( $vals as $val ) {
            if ( array_key_exists( $val, $this->mTree ) ) {
                $this->mTree[$val]->mUnsortedRows[] = $row;
            } else {
                $formattedVal = reset( $formattedVals );
                $this->mTree[$val] = new CargoOutlineTree( [ $row ], $formattedVal );
            }
        }
    }
    public function addField( $field ) {
        if ( count( $this->mUnsortedRows ) > 0 ) {
            foreach ( $this->mUnsortedRows as $row ) {
                $fieldValues = $row->getOutlineFieldValues( $field );
                $formattedFieldValues = $row->getFormattedOutlineFieldValues( $field );
                $this->categorizeRow( $fieldValues, $row, $formattedFieldValues );
            }
            $this->mUnsortedRows = [];
        } else {
            foreach ( $this->mTree as $i => $node ) {
                $this->mTree[$i]->addField( $field );
            }
        }
    }
}