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: 36 46 78.3 %
Date: 2016-07-19 Functions: 5 6 83.3 %
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_free */
      33           6 : void Spoofchecker_objects_free(zend_object *object)
      34             : {
      35           6 :         Spoofchecker_object* co = php_intl_spoofchecker_fetch_object(object);
      36             : 
      37           6 :         zend_object_std_dtor(&co->zo);
      38             : 
      39           6 :         spoofchecker_object_destroy(co);
      40           6 : }
      41             : /* }}} */
      42             : 
      43             : /* {{{ Spoofchecker_object_create */
      44           6 : zend_object *Spoofchecker_object_create(
      45             :         zend_class_entry *ce)
      46             : {
      47             :         Spoofchecker_object*     intern;
      48             : 
      49           6 :         intern = ecalloc(1, sizeof(Spoofchecker_object) + zend_object_properties_size(ce));
      50           6 :         intl_error_init(SPOOFCHECKER_ERROR_P(intern));
      51           6 :         zend_object_std_init(&intern->zo, ce);
      52           6 :         object_properties_init(&intern->zo, ce);
      53             : 
      54           6 :         intern->zo.handlers = &Spoofchecker_handlers;
      55             : 
      56           6 :         return &intern->zo;
      57             : }
      58             : /* }}} */
      59             : 
      60             : /*
      61             :  * 'Spoofchecker' class registration structures & functions
      62             :  */
      63             : 
      64             : /* {{{ Spoofchecker methods arguments info */
      65             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_0_args, 0, 0, 0)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_checks, 0, 0, 1)
      69             :         ZEND_ARG_INFO(0, checks)
      70             : ZEND_END_ARG_INFO()
      71             : 
      72             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_set_allowed_locales, 0, 0, 1)
      73             :         ZEND_ARG_INFO(0, locale_list)
      74             : ZEND_END_ARG_INFO()
      75             : 
      76             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_is_suspicous, 0, 0, 1)
      77             :         ZEND_ARG_INFO(0, text)
      78             :         ZEND_ARG_INFO(1, error)
      79             : ZEND_END_ARG_INFO()
      80             : 
      81             : ZEND_BEGIN_ARG_INFO_EX(spoofchecker_are_confusable, 0, 0, 2)
      82             :         ZEND_ARG_INFO(0, s1)
      83             :         ZEND_ARG_INFO(0, s2)
      84             :         ZEND_ARG_INFO(1, error)
      85             : ZEND_END_ARG_INFO()
      86             : 
      87             : /* }}} */
      88             : 
      89             : /* {{{ Spoofchecker_class_functions
      90             :  * Every 'Spoofchecker' class method has an entry in this table
      91             :  */
      92             : 
      93             : zend_function_entry Spoofchecker_class_functions[] = {
      94             :         PHP_ME(Spoofchecker, __construct, spoofchecker_0_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
      95             :         PHP_ME(Spoofchecker, isSuspicious, spoofchecker_is_suspicous, ZEND_ACC_PUBLIC)
      96             :         PHP_ME(Spoofchecker, areConfusable, spoofchecker_are_confusable, ZEND_ACC_PUBLIC)
      97             :         PHP_ME(Spoofchecker, setAllowedLocales, spoofchecker_set_allowed_locales, ZEND_ACC_PUBLIC)
      98             :         PHP_ME(Spoofchecker, setChecks, spoofchecker_set_checks, ZEND_ACC_PUBLIC)
      99             :         PHP_FE_END
     100             : };
     101             : /* }}} */
     102             : 
     103           1 : static zend_object *spoofchecker_clone_obj(zval *object) /* {{{ */
     104             : {
     105             :         zend_object *new_obj_val;
     106             :         Spoofchecker_object *sfo, *new_sfo;
     107             : 
     108           1 :     sfo = Z_INTL_SPOOFCHECKER_P(object);
     109           1 :     intl_error_reset(SPOOFCHECKER_ERROR_P(sfo));
     110             : 
     111           1 :         new_obj_val = Spoofchecker_ce_ptr->create_object(Z_OBJCE_P(object));
     112           1 :         new_sfo = php_intl_spoofchecker_fetch_object(new_obj_val);
     113             :         /* clone standard parts */
     114           1 :         zend_objects_clone_members(&new_sfo->zo, &sfo->zo);
     115             :         /* clone internal object */
     116           1 :         new_sfo->uspoof = uspoof_clone(sfo->uspoof, SPOOFCHECKER_ERROR_CODE_P(new_sfo));
     117           1 :         if(U_FAILURE(SPOOFCHECKER_ERROR_CODE(new_sfo))) {
     118             :                 /* set up error in case error handler is interested */
     119           0 :                 intl_error_set( NULL, SPOOFCHECKER_ERROR_CODE(new_sfo), "Failed to clone SpoofChecker object", 0 );
     120           0 :                 Spoofchecker_objects_free(&new_sfo->zo); /* free new object */
     121           0 :                 zend_error(E_ERROR, "Failed to clone SpoofChecker object");
     122             :         }
     123           1 :         return new_obj_val;
     124             : }
     125             : /* }}} */
     126             : 
     127             : /* {{{ spoofchecker_register_Spoofchecker_class
     128             :  * Initialize 'Spoofchecker' class
     129             :  */
     130       23409 : void spoofchecker_register_Spoofchecker_class(void)
     131             : {
     132             :         zend_class_entry ce;
     133             : 
     134             :         /* Create and register 'Spoofchecker' class. */
     135       23409 :         INIT_CLASS_ENTRY(ce, "Spoofchecker", Spoofchecker_class_functions);
     136       23409 :         ce.create_object = Spoofchecker_object_create;
     137       23409 :         Spoofchecker_ce_ptr = zend_register_internal_class(&ce);
     138             : 
     139       23409 :         memcpy(&Spoofchecker_handlers, zend_get_std_object_handlers(),
     140             :                 sizeof Spoofchecker_handlers);
     141       23409 :         Spoofchecker_handlers.offset = XtOffsetOf(Spoofchecker_object, zo);
     142       23409 :         Spoofchecker_handlers.clone_obj = spoofchecker_clone_obj;
     143       23409 :         Spoofchecker_handlers.free_obj = Spoofchecker_objects_free;
     144             : 
     145       23409 :         if (!Spoofchecker_ce_ptr) {
     146           0 :                 zend_error(E_ERROR,
     147             :                         "Spoofchecker: attempt to create properties "
     148             :                         "on a non-registered class.");
     149           0 :                 return;
     150             :         }
     151             : }
     152             : /* }}} */
     153             : 
     154             : /* {{{ void spoofchecker_object_init( Spoofchecker_object* co )
     155             :  * Initialize internals of Spoofchecker_object.
     156             :  * Must be called before any other call to 'spoofchecker_object_...' functions.
     157             :  */
     158           0 : void spoofchecker_object_init(Spoofchecker_object* co)
     159             : {
     160           0 :         if (!co) {
     161           0 :                 return;
     162             :         }
     163             : 
     164           0 :         intl_error_init(SPOOFCHECKER_ERROR_P(co));
     165             : }
     166             : /* }}} */
     167             : 
     168             : /* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co )
     169             :  * Clean up mem allocted by internals of Spoofchecker_object
     170             :  */
     171           6 : void spoofchecker_object_destroy(Spoofchecker_object* co)
     172             : {
     173           6 :         if (!co) {
     174           0 :                 return;
     175             :         }
     176             : 
     177           6 :         if (co->uspoof) {
     178           6 :                 uspoof_close(co->uspoof);
     179           6 :                 co->uspoof = NULL;
     180             :         }
     181             : 
     182           6 :         intl_error_reset(SPOOFCHECKER_ERROR_P(co));
     183             : }
     184             : /* }}} */
     185             : 
     186             : /*
     187             :  * Local variables:
     188             :  * tab-width: 4
     189             :  * c-basic-offset: 4
     190             :  * End:
     191             :  * vim600: noet sw=4 ts=4 fdm=marker
     192             :  * vim<600: noet sw=4 ts=4
     193             :  */

Generated by: LCOV version 1.10

Generated at Wed, 20 Jul 2016 02:56:19 +0000 (5 days ago)

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