PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/dom - nodelist.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 55 60 91.7 %
Date: 2014-10-22 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Christian Stocker <chregu@php.net>                          |
      16             :    |          Rob Richards <rrichards@php.net>                            |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #if HAVE_LIBXML && HAVE_DOM
      28             : #include "php_dom.h"
      29             : 
      30             : 
      31             : /* {{{ arginfo */
      32             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_item, 0, 0, 1)
      33             :         ZEND_ARG_INFO(0, index)
      34             : ZEND_END_ARG_INFO();
      35             : /* }}} */
      36             : 
      37             : /*
      38             : * class DOMNodeList 
      39             : *
      40             : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
      41             : * Since: 
      42             : */
      43             : 
      44             : const zend_function_entry php_dom_nodelist_class_functions[] = {
      45             :         PHP_FALIAS(item, dom_nodelist_item, arginfo_dom_nodelist_item)
      46             :         PHP_FE_END
      47             : };
      48             : 
      49             : /* {{{ length   int     
      50             : readonly=yes 
      51             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
      52             : Since: 
      53             : */
      54          68 : int dom_nodelist_length_read(dom_object *obj, zval *retval TSRMLS_DC)
      55             : {
      56             :         dom_nnodemap_object *objmap;
      57             :         xmlNodePtr nodep, curnode;
      58          68 :         int count = 0;
      59             :         HashTable *nodeht;
      60             : 
      61          68 :         objmap = (dom_nnodemap_object *)obj->ptr;
      62          68 :         if (objmap != NULL) {
      63          68 :                 if (objmap->ht) {
      64           0 :                         count = xmlHashSize(objmap->ht);
      65             :                 } else {
      66          68 :                         if (objmap->nodetype == DOM_NODESET) {
      67          14 :                                 nodeht = HASH_OF(&objmap->baseobj_zv);
      68           7 :                                 count = zend_hash_num_elements(nodeht);
      69             :                         } else {
      70          61 :                                 nodep = dom_object_get_node(objmap->baseobj);
      71          61 :                                 if (nodep) {
      72         112 :                                         if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
      73          51 :                                                 curnode = nodep->children;
      74          51 :                                                 if (curnode) {
      75          51 :                                                         count++;
      76         198 :                                                         while (curnode->next != NULL) {
      77          96 :                                                                 count++;
      78          96 :                                                                 curnode = curnode->next;
      79             :                                                         }
      80             :                                                 }
      81             :                                         } else {
      82          18 :                                                 if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
      83           8 :                                                         nodep = xmlDocGetRootElement((xmlDoc *) nodep);
      84             :                                                 } else {
      85           2 :                                                         nodep = nodep->children;
      86             :                                                 }
      87          10 :                                                 curnode = dom_get_elements_by_tag_name_ns_raw(
      88             :                                                         nodep, (char *) objmap->ns, (char *) objmap->local, &count, -1);
      89             :                                         }
      90             :                                 }
      91             :                         }
      92             :                 }
      93             :         }
      94             : 
      95          68 :         ZVAL_LONG(retval, count);
      96          68 :         return SUCCESS;
      97             : }
      98             : 
      99             : /* }}} */
     100             : 
     101             : /* {{{ proto DOMNode dom_nodelist_item(int index);
     102             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
     103             : Since: 
     104             : */
     105          64 : PHP_FUNCTION(dom_nodelist_item)
     106             : {
     107             :         zval *id;
     108             :         zend_long index;
     109             :         int ret;
     110             :         dom_object *intern;
     111          64 :         xmlNodePtr itemnode = NULL;
     112             : 
     113             :         dom_nnodemap_object *objmap;
     114             :         xmlNodePtr nodep, curnode;
     115          64 :         int count = 0;
     116             : 
     117          64 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &id, dom_nodelist_class_entry, &index) == FAILURE) {
     118           0 :                 return;
     119             :         }
     120             : 
     121          64 :         if (index >= 0) {
     122          64 :                 intern = Z_DOMOBJ_P(id);
     123             : 
     124          64 :                 objmap = (dom_nnodemap_object *)intern->ptr;
     125          64 :                 if (objmap != NULL) {
     126          64 :                         if (objmap->ht) {
     127           0 :                                 if (objmap->nodetype == XML_ENTITY_NODE) {
     128           0 :                                         itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
     129             :                                 } else {
     130           0 :                                         itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
     131             :                                 }
     132             :                         } else {
     133          64 :                                 if (objmap->nodetype == DOM_NODESET) {
     134          14 :                                         HashTable *nodeht = HASH_OF(&objmap->baseobj_zv);
     135           7 :                                         zval *entry = zend_hash_index_find(nodeht, index);
     136           7 :                                         if (entry) {
     137           7 :                                                 ZVAL_COPY(return_value, entry);
     138           7 :                                                 return;
     139             :                                         }
     140          57 :                                 } else if (objmap->baseobj) {
     141          56 :                                         nodep = dom_object_get_node(objmap->baseobj);
     142          56 :                                         if (nodep) {
     143          79 :                                                 if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
     144          23 :                                                         curnode = nodep->children;
     145          80 :                                                         while (count < index && curnode != NULL) {
     146          34 :                                                                 count++;
     147          34 :                                                                 curnode = curnode->next;
     148             :                                                         }
     149          23 :                                                         itemnode = curnode;
     150             :                                                 } else {
     151          58 :                                                         if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
     152          25 :                                                                 nodep = xmlDocGetRootElement((xmlDoc *) nodep);
     153             :                                                         } else {
     154           8 :                                                                 nodep = nodep->children;
     155             :                                                         }
     156          33 :                                                         itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, index);
     157             :                                                 }
     158             :                                         }
     159             :                                 }
     160             :                         }
     161             :                 }
     162             : 
     163          57 :                 if (itemnode) {
     164          54 :                         DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
     165          54 :                         return;
     166             :                 }
     167             :         }
     168             : 
     169           3 :         RETVAL_NULL();
     170             : }
     171             : /* }}} end dom_nodelist_item */
     172             : 
     173             : #endif
     174             : 
     175             : /*
     176             :  * Local variables:
     177             :  * tab-width: 4
     178             :  * c-basic-offset: 4
     179             :  * End:
     180             :  * vim600: noet sw=4 ts=4 fdm=marker
     181             :  * vim<600: noet sw=4 ts=4
     182             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:47 +0000 (3 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.