Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoOutlineTree
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 addRow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 categorizeRow
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 addField
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3/**
4 * A tree structure for holding the outline data.
5 */
6class CargoOutlineTree {
7    public $mTree;
8    public $mUnsortedRows;
9    public $mFormattedValue;
10
11    public function __construct( $rows = [], $formattedValue = null ) {
12        $this->mTree = [];
13        $this->mUnsortedRows = $rows;
14        $this->mFormattedValue = $formattedValue;
15    }
16
17    public function addRow( $row ) {
18        $this->mUnsortedRows[] = $row;
19    }
20
21    public function categorizeRow( $vals, $row, $formattedVals ) {
22        foreach ( $vals as $val ) {
23            if ( array_key_exists( $val, $this->mTree ) ) {
24                $this->mTree[$val]->mUnsortedRows[] = $row;
25            } else {
26                $formattedVal = reset( $formattedVals );
27                $this->mTree[$val] = new CargoOutlineTree( [ $row ], $formattedVal );
28            }
29        }
30    }
31
32    public function addField( $field ) {
33        if ( count( $this->mUnsortedRows ) > 0 ) {
34            foreach ( $this->mUnsortedRows as $row ) {
35                $fieldValues = $row->getOutlineFieldValues( $field );
36                $formattedFieldValues = $row->getFormattedOutlineFieldValues( $field );
37                $this->categorizeRow( $fieldValues, $row, $formattedFieldValues );
38            }
39            $this->mUnsortedRows = [];
40        } else {
41            foreach ( $this->mTree as $i => $node ) {
42                $this->mTree[$i]->addField( $field );
43            }
44        }
45    }
46}