FluentDOM Package
Current file: /fluentdom/releases/release_2.0/FluentDOM/FluentDOMIterator.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9
100.00%100.00%
100.00% 16 / 16
 
FluentDOMIterator
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 9 / 9
100.00%100.00%
100.00% 16 / 16
 public function __construct($owner)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function current()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function key()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function next()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function rewind()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 2 / 2
 public function seek($position)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 public function valid()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function getChildren()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1
 public function hasChildren()
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 1 / 1


       1                 : <?php                                                                         
       2                 : /**                                                                           
       3                 : * FluentDOMIterator is the Iterator class for FluentDOM objects               
       4                 : *                                                                             
       5                 : * @version $Id: FluentDOMIterator.php 296 2009-07-21 12:15:44Z subjective $   
       6                 : * @license http://www.opensource.org/licenses/mit-license.php The MIT License 
       7                 : * @copyright Copyright (c) 2009 Bastian Feder, Thomas Weinert                 
       8                 : *                                                                             
       9                 : * @package FluentDOM                                                          
      10                 : */                                                                            
      11                 :                                                                               
      12                 : /**                                                                           
      13                 : * FluentDOMIterator is the Iterator class for FluentDOM objects               
      14                 : *                                                                             
      15                 : * @package FluentDOM                                                          
      16                 : */                                                                            
      17                 : class FluentDOMIterator implements RecursiveIterator, SeekableIterator {      
      18                 :                                                                               
      19                 :   private $_position  = 0;                                                    
      20                 :   private $_owner = NULL;                                                     
      21                 :                                                                               
      22                 :   /**                                                                         
      23                 :   * remember the owner object (the FluentDOM object this iterator interates)  
      24                 :   *                                                                           
      25                 :   * @param $owner                                                             
      26                 :   * @access public                                                            
      27                 :   * @return                                                                   
      28                 :   */                                                                          
      29                 :   public function __construct($owner) {                                       
      30              20 :     $this->_owner = $owner;                                                   
      31              20 :   }                                                                           
      32                 :                                                                               
      33                 :    /*                                                                         
      34                 :   * Interface - Iterator, SeekableIterator                                    
      35                 :   */                                                                          
      36                 :                                                                               
      37                 :   /**                                                                         
      38                 :   * Get current iterator element                                              
      39                 :   *                                                                           
      40                 :   * @access public                                                            
      41                 :   * @return object DOMNode                                                    
      42                 :   */                                                                          
      43                 :   public function current() {                                                 
      44              11 :     return $this->_owner->item($this->_position);                             
      45                 :   }                                                                           
      46                 :                                                                               
      47                 :   /**                                                                         
      48                 :   * Get current iterator pointer                                              
      49                 :   *                                                                           
      50                 :   * @access public                                                            
      51                 :   * @return integer                                                           
      52                 :   */                                                                          
      53                 :   public function key() {                                                     
      54               2 :     return $this->_position;                                                  
      55                 :   }                                                                           
      56                 :                                                                               
      57                 :   /**                                                                         
      58                 :   * Move iterator pointer to next element                                     
      59                 :   *                                                                           
      60                 :   * @access public                                                            
      61                 :   * @return void                                                              
      62                 :   */                                                                          
      63                 :   public function next() {                                                    
      64              11 :     ++$this->_position;                                                       
      65              11 :   }                                                                           
      66                 :                                                                               
      67                 :   /**                                                                         
      68                 :   * Reset iterator pointer                                                    
      69                 :   *                                                                           
      70                 :   * @access public                                                            
      71                 :   * @return void                                                              
      72                 :   */                                                                          
      73                 :   public function rewind() {                                                  
      74              12 :     $this->_position = 0;                                                     
      75              12 :   }                                                                           
      76                 :                                                                               
      77                 :   /**                                                                         
      78                 :   * Move iterator pointer to specified element                                
      79                 :   *                                                                           
      80                 :   * @param integer $position                                                  
      81                 :   * @access public                                                            
      82                 :   * @return void                                                              
      83                 :   */                                                                          
      84                 :   public function seek($position) {                                           
      85               2 :     if (count($this->_owner) > $position) {                                   
      86               1 :       $this->_position = $position;                                           
      87               1 :     } else {                                                                  
      88               1 :       throw new InvalidArgumentException('Unknown position');                 
      89                 :     }                                                                         
      90               1 :   }                                                                           
      91                 :                                                                               
      92                 :   /**                                                                         
      93                 :   * Check if current iterator pointer contains a valid element                
      94                 :   *                                                                           
      95                 :   * @access public                                                            
      96                 :   * @return boolean                                                           
      97                 :   */                                                                          
      98                 :   public function valid() {                                                   
      99              12 :     return is_object($this->_owner->item($this->_position));                  
     100                 :   }                                                                           
     101                 :                                                                               
     102                 :   /**                                                                         
     103                 :   * Get children of the current iterator element                              
     104                 :   *                                                                           
     105                 :   * @access public                                                            
     106                 :   * @return object FluentDOM                                                  
     107                 :   */                                                                          
     108                 :   public function getChildren() {                                             
     109               2 :     return $this->_owner->eq($this->_position)->find('node()')->getIterator();
     110                 :   }                                                                           
     111                 :                                                                               
     112                 :   /**                                                                         
     113                 :   * Check if the current iterator element has children                        
     114                 :   *                                                                           
     115                 :   * @access public                                                            
     116                 :   * @return object FluentDOM                                                  
     117                 :   */                                                                          
     118                 :   public function hasChildren() {                                             
     119               2 :     return (count($this->_owner->eq($this->_position)->find('node()')) > 0);  
     120                 :   }                                                                           
     121                 :                                                                               

Generated by PHPUnit 3.3.17 and Xdebug 2.0.4 at Sat Jul 25 13:10:02 CEST 2009.