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/intl/spoofchecker - spoofchecker_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 40 50 80.0 %
Date: 2014-10-22 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | This source file is subject to version 3.01 of the PHP license,      |
       6             :    | that is bundled with this package in the file LICENSE, and is        |
       7             :    | available through the world-wide-web at the following url:           |
       8             :    | http://www.php.net/license/3_01.txt                                  |
       9             :    | If you did not receive a copy of the PHP license and are unable to   |
      10             :    | obtain it through the world-wide-web, please send a note to          |
      11             :    | license@php.net so we can mail you a copy immediately.               |
      12             :    +----------------------------------------------------------------------+
      13             :    | Authors: Scott MacVicar <scottmac@php.net>                           |
      14             :    +----------------------------------------------------------------------+
      15             :  */
      16             : 
      17             : #include "spoofchecker_class.h"
      18             : #include "spoofchecker_main.h"
      19             : #include "spoofchecker_create.h"
      20             : #include "php_intl.h"
      21             : #include "intl_error.h"
      22             : 
      23             : #include <unicode/uspoof.h>
      24             : 
      25             : zend_class_entry *Spoofchecker_ce_ptr = NULL;
      26             : static zend_object_handlers Spoofchecker_handlers;
      27             : 
      28             : /*
      29             :  * Auxiliary functions needed by objects of 'Spoofchecker' class
      30             :  */
      31             : 
      32             : /* {{{ Spoofchecker_objects_dtor */
      33           6 : static void Spoofchecker_objects_dtor(zend_object *object TSRMLS_DC)
      34             : {
      35           6 :         zend_objects_destroy_object(object TSRMLS_CC);
      36           6 : }
      37             : /* }}} */
      38             : 
      39             : /* {{{ Spoofchecker_objects_free */
      40           6 : void Spoofchecker_objects_free(zend_object *object TSRMLS_DC)
      41             : {
      42           6 :         Spoofchecker_object* co = php_intl_spoofchecker_fetch_object(object);
      43             : 
      44           6 :         zend_object_std_dtor(&co->zo TSRMLS_CC);
      45             : 
      46           6 :         spoofchecker_object_destroy(co TSRMLS_CC);
      47           6 : }
      48             : /* }}} */
      49             : 
      50             : /* {{{ Spoofchecker_object_create */
      51           6 : zend_object *Spoofchecker_object_create(
      52             :         zend_class_entry *ce TSRMLS_DC)
      53             : {
      54             :         Spoofchecker_object*     intern;
      55             : 
      56           6 :         intern = ecalloc(1, sizeof(Spoofchecker_object) + sizeof(zval) * (ce->default_properties_count - 1));
      57           6 :         intl_error_init(SPOOFCHECKER_ERROR_P(intern) TSRMLS_CC);
      58           6 :         zend_object_std_init(&intern->zo, ce TSRMLS_CC);
      59           6 :         object_properties_init(&intern->zo, ce);
      60             : 
      61           6 :         intern->zo.handlers = &Spoofchecker_handlers;
      62             : 
      63           6 :         return &intern->zo;
      64             : }
      65             : /* }}} */
      66             : 
      67             : /*
      68             :  * 'Spoofchecker' class registration structures & functions
      69             :  */
      70             : 
      71             : /* {{{ Spoofchecker methods arguments info */
      72             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_0_args, 0, 0, 0)
      73             : ZEND_END_ARG_INFO()
      74             : 
      75             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_checks, 0, 0, 1)
      76             :         ZEND_ARG_INFO(0, checks)
      77             : ZEND_END_ARG_INFO()
      78             : 
      79             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_allowed_locales, 0, 0, 1)
      80             :         ZEND_ARG_INFO(0, locale_list)
      81             : ZEND_END_ARG_INFO()
      82             : 
      83             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_is_suspicous, 0, 0, 1)
      84             :         ZEND_ARG_INFO(0, text)
      85             :         ZEND_ARG_INFO(1, error)
      86             : ZEND_END_ARG_INFO()
      87             : 
      88             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_are_confusable, 0, 0, 2)
      89             :         ZEND_ARG_INFO(0, s1)
      90             :         ZEND_ARG_INFO(0, s2)
      91             :         ZEND_ARG_INFO(1, error)
      92             : ZEND_END_ARG_INFO()
      93             : 
      94             : /* }}} */
      95             : 
      96             : /* {{{ Spoofchecker_class_functions
      97             :  * Every 'Spoofchecker' class method has an entry in this table
      98             :  */
      99             : 
     100             : zend_function_entry Spoofchecker_class_functions[] = {
     101             :         PHP_ME(Spoofchecker, __construct, spoofchecker_0_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
     102             :         PHP_ME(Spoofchecker, isSuspicious, spoofchecker_is_suspicous, ZEND_ACC_PUBLIC)
     103             :         PHP_ME(Spoofchecker, areConfusable, spoofchecker_are_confusable, ZEND_ACC_PUBLIC)
     104             :         PHP_ME(Spoofchecker, setAllowedLocales, spoofchecker_set_allowed_locales, ZEND_ACC_PUBLIC)
     105             :         PHP_ME(Spoofchecker, setChecks, spoofchecker_set_checks, ZEND_ACC_PUBLIC)
     106             :         PHP_FE_END
     107             : };
     108             : /* }}} */
     109             : 
     110           1 : static zend_object *spoofchecker_clone_obj(zval *object TSRMLS_DC) /* {{{ */
     111             : {
     112             :         zend_object *new_obj_val;
     113             :         Spoofchecker_object *sfo, *new_sfo;
     114             : 
     115           1 :     sfo = Z_INTL_SPOOFCHECKER_P(object);
     116           1 :     intl_error_reset(SPOOFCHECKER_ERROR_P(sfo) TSRMLS_CC);
     117             : 
     118           1 :         new_obj_val = Spoofchecker_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
     119           1 :         new_sfo = php_intl_spoofchecker_fetch_object(new_obj_val);
     120             :         /* clone standard parts */      
     121           1 :         zend_objects_clone_members(&new_sfo->zo, &sfo->zo TSRMLS_CC);
     122             :         /* clone internal object */
     123           1 :         new_sfo->uspoof = uspoof_clone(sfo->uspoof, SPOOFCHECKER_ERROR_CODE_P(new_sfo));
     124           1 :         if(U_FAILURE(SPOOFCHECKER_ERROR_CODE(new_sfo))) {
     125             :                 /* set up error in case error handler is interested */
     126           0 :                 intl_error_set( NULL, SPOOFCHECKER_ERROR_CODE(new_sfo), "Failed to clone SpoofChecker object", 0 TSRMLS_CC );
     127           0 :                 Spoofchecker_objects_dtor(&new_sfo->zo TSRMLS_CC); /* free new object */
     128           0 :                 zend_error(E_ERROR, "Failed to clone SpoofChecker object");
     129             :         }
     130           1 :         return new_obj_val;
     131             : }
     132             : /* }}} */
     133             : 
     134             : /* {{{ spoofchecker_register_Spoofchecker_class
     135             :  * Initialize 'Spoofchecker' class
     136             :  */
     137       20423 : void spoofchecker_register_Spoofchecker_class(TSRMLS_D)
     138             : {
     139             :         zend_class_entry ce;
     140             : 
     141             :         /* Create and register 'Spoofchecker' class. */
     142       20423 :         INIT_CLASS_ENTRY(ce, "Spoofchecker", Spoofchecker_class_functions);
     143       20423 :         ce.create_object = Spoofchecker_object_create;
     144       20423 :         Spoofchecker_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC);
     145             : 
     146       20423 :         memcpy(&Spoofchecker_handlers, zend_get_std_object_handlers(),
     147             :                 sizeof Spoofchecker_handlers);
     148       20423 :         Spoofchecker_handlers.offset = XtOffsetOf(Spoofchecker_object, zo);
     149       20423 :         Spoofchecker_handlers.clone_obj = spoofchecker_clone_obj; 
     150       20423 :         Spoofchecker_handlers.dtor_obj = Spoofchecker_objects_dtor;
     151       20423 :         Spoofchecker_handlers.free_obj = Spoofchecker_objects_free;
     152             : 
     153       20423 :         if (!Spoofchecker_ce_ptr) {
     154           0 :                 zend_error(E_ERROR,
     155             :                         "Spoofchecker: attempt to create properties "
     156             :                         "on a non-registered class.");
     157           0 :                 return;
     158             :         }
     159             : }
     160             : /* }}} */
     161             : 
     162             : /* {{{ void spoofchecker_object_init( Spoofchecker_object* co )
     163             :  * Initialize internals of Spoofchecker_object.
     164             :  * Must be called before any other call to 'spoofchecker_object_...' functions.
     165             :  */
     166           0 : void spoofchecker_object_init(Spoofchecker_object* co TSRMLS_DC)
     167             : {
     168           0 :         if (!co) {
     169           0 :                 return;
     170             :         }
     171             : 
     172           0 :         intl_error_init(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
     173             : }
     174             : /* }}} */
     175             : 
     176             : /* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co )
     177             :  * Clean up mem allocted by internals of Spoofchecker_object
     178             :  */
     179           6 : void spoofchecker_object_destroy(Spoofchecker_object* co TSRMLS_DC)
     180             : {
     181           6 :         if (!co) {
     182           0 :                 return;
     183             :         }
     184             : 
     185           6 :         if (co->uspoof) {
     186           6 :                 uspoof_close(co->uspoof);
     187           6 :                 co->uspoof = NULL;
     188             :         }
     189             : 
     190           6 :         intl_error_reset(SPOOFCHECKER_ERROR_P(co) TSRMLS_CC);
     191             : }
     192             : /* }}} */
     193             : 
     194             : /*
     195             :  * Local variables:
     196             :  * tab-width: 4
     197             :  * c-basic-offset: 4
     198             :  * End:
     199             :  * vim600: noet sw=4 ts=4 fdm=marker
     200             :  * vim<600: noet sw=4 ts=4
     201             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:50 +0000 (21 hours ago)

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