XoopsFormCaptcha   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 4
A setConfig() 0 4 1
A render() 0 6 2
1
<?php
2
/**
3
 * Adding CAPTCHA
4
 *
5
 * Currently there are two types of CAPTCHA forms, text and image
6
 * The default mode is "text", it can be changed in the priority:
7
 * 1 If mode is set through XoopsFormCaptcha::setMode(), take it
8
 * 2 Elseif mode is set though captcha/config.php, take it
9
 * 3 Else, take "text"
10
 *
11
 * D.J.
12
 */
13
14
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
15
16
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php';
17
18
/*
19
 * Usage
20
 *
21
 * For form creation:
22
 * 1 Add [require_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php";] to class/xoopsformloader.php, OR add to the file that uses CAPTCHA before calling XoopsFormCaptcha
23
 * 2 Add form element where proper: $xoopsform->addElement(new \XoopsFormCaptcha($caption, $name, $skipmember, ...);
24
 *
25
 * For verification:
26
 *   if (@require_once XOOPS_ROOT_PATH."/class/captcha/xoopscaptcha.php") {
27
 *      $xoopsCaptcha = XoopsCaptcha::getInstance();
28
 *      if (! $xoopsCaptcha->verify() ) {
29
 *          echo $xoopsCaptcha->getMessage();
30
 *          ...
31
 *      }
32
 *  }
33
 *
34
 */
35
36
/**
37
 * Class XoopsFormCaptcha
38
 */
39
class XoopsFormCaptcha extends \XoopsFormElement
40
{
41
    public $_captchaHandler;
42
43
    /**
44
     * @param string  $caption        Caption of the form element, default value is defined in captcha/language/
45
     * @param string  $name           Name for the input box
46
     * @param boolean $skipmember     Skip CAPTCHA check for members
47
     * @param int     $numchar        Number of characters in image mode, and input box size for text mode
48
     * @param int     $minfontsize    Minimum font-size of characters in image mode
49
     * @param int     $maxfontsize    Maximum font-size of characters in image mode
50
     * @param int     $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
51
     * @param int     $backgroundnum  Number of background images in image mode
52
     *
53
     */
54
    public function __construct(
55
        $caption = '',
56
        $name = 'xoopscaptcha',
57
        $skipmember = null,
58
        $numchar = null,
59
        $minfontsize = null,
60
        $maxfontsize = null,
61
        $backgroundtype = null,
62
        $backgroundnum = null
63
    ) {
64
        if (!class_exists('XoopsCaptcaha')) {
65
            require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php';
66
        }
67
68
        $this->_captchaHandler = XoopsCaptcha::getInstance();
69
        $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum);
0 ignored issues
show
Bug introduced by
It seems like $skipmember defined by parameter $skipmember on line 57 can also be of type boolean; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $numchar defined by parameter $numchar on line 58 can also be of type integer; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $minfontsize defined by parameter $minfontsize on line 59 can also be of type integer; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $maxfontsize defined by parameter $maxfontsize on line 60 can also be of type integer; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $backgroundtype defined by parameter $backgroundtype on line 61 can also be of type integer; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $backgroundnum defined by parameter $backgroundnum on line 62 can also be of type integer; however, XoopsCaptcha::init() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
70
        if (!$this->_captchaHandler->active) {
71
            $this->setHidden();
72
        } else {
73
            $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption();
74
            $this->setCaption($caption);
75
        }
76
    }
77
78
    /**
79
     * @param $name
80
     * @param $val
81
     * @return bool
82
     */
83
    public function setConfig($name, $val)
84
    {
85
        return $this->_captchaHandler->setConfig($name, $val);
86
    }
87
88
    /**
89
     * @return mixed|string
90
     */
91
    public function render()
92
    {
93
        if (!$this->isHidden()) {
94
            return $this->_captchaHandler->render();
95
        }
96
    }
97
}
98