Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
83.33% covered (warning)
83.33%
10 / 12
CRAP
90.00% covered (success)
90.00%
27 / 30
Tree
0.00% covered (danger)
0.00%
0 / 1
83.33% covered (warning)
83.33%
10 / 12
16.26
90.00% covered (success)
90.00%
27 / 30
 __construct($nodeName = null)
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 _getNewName()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 append(&$child, $nodeName = null)
0.00% covered (danger)
0.00%
0 / 1
4.07
83.33% covered (warning)
83.33%
10 / 12
 nodes()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getNodeByName($nodeName)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getNode($nodeNbr)
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getParent()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 rewind()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 current()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 key()
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 next()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 valid()
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
/**
 *
 */
namespace aae\adt {
    /**
     * @author Axel Ancona Esselmann
     * @package aae\adt
     */
    class Tree implements \Iterator {
        protected $_nodes = array();
        public $nodeName = "";
        protected $_parent = null;
        protected static $_s_instanceCounter = 0;
        public function __construct($nodeName = null) {
            if (is_null($nodeName)) {
                $this->nodeName = self::_getNewName();
            } else {
                $this->nodeName = $nodeName;
            }
        }
        
        protected function _getNewName() {
            return "node_".Tree::$_s_instanceCounter++;
        }
    
        public function append(&$child, $nodeName = null) {
            if (is_a($child, "aae\adt\Tree")) {
                if (!is_null($nodeName)) {
                    $child->nodeName = $nodeName;
                } else {
                    $nodeName = $child->nodeName;
                }
                $child->_parent = $this;
            } else {
                if (is_null($nodeName)) {
                    $nodeName = $this->_getNewName();
                }
            }
            $this->_nodes[$nodeName] = $child;
        }
    
        public function nodes() {
            return $this->_nodes;
        }
    
        public function getNodeByName($nodeName) {
            return $this->_nodes[$nodeName];
        }
    
        public function getNode($nodeNbr) {
            $nodes = array_values($this->_nodes);
            return $nodes[$nodeNbr];
        }
        public function getParent() {
            return $this->_parent;
        }
        public function rewind() {
            reset($this->_nodes);
        }
        public function current() {
            return current($this->_nodes);
        }
        public function key() {
            return key($this->_nodes);
        }
        public function next() {
            next($this->_nodes);
        }
        public function valid() {
            return key($this->_nodes) !== null;
        }
    }
}