Passed
Push — master ( cf57bc...9eba79 )
by Michael
01:41
created

Utility   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getEditor() 0 25 3
A getSignForm() 0 17 1
A gbookIP() 0 16 4
1
<?php namespace XoopsModules\Gbook;
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
/**
12
 * Gbook\Utility Class
13
 *
14
 * @copyright   XOOPS Project (https://xoops.org)
15
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @author      XOOPS Development Team
17
 * @package     GBook
18
 * @since       1.03
19
 *
20
 */
21
22
//namespace GBook;
23
24
use Xmf\Request;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use XoopsModules\Gbook;
26
use XoopsModules\Gbook\Common;
27
28
/**
29
 * Class Utility
30
 */
31
class Utility
32
{
33
    use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
34
35
    use Common\ServerStats; // getServerStats Trait
36
37
    use Common\FilesManagement; // Files Management Trait
38
39
    //--------------- Custom module methods -----------------------------
40
41
    /**
42
     * @param $name
43
     * @param $value
44
     * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor
45
     */
46
    public static function getEditor($name, $value)
47
    {
48
        global $xoopsUser, $xoopsModule, $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
49
        $options = [];
50
        $isAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
51
52
        if (class_exists('XoopsFormEditor')) {
53
            $options['name']   = $name;
54
            $options['value']  = $value;
55
            $options['rows']   = 5;
56
            $options['cols']   = '100%';
57
            $options['width']  = '100%';
58
            $options['height'] = '200px';
59
            if ($isAdmin) {
60
                $descEditor = new \XoopsFormEditor(ucfirst($name), $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
0 ignored issues
show
Bug introduced by
The type XoopsFormEditor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
            } else {
62
                $descEditor = new \XoopsFormEditor(ucfirst($name), $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
63
            }
64
        } else {
65
            $descEditor = new \XoopsFormDhtmlTextArea(ucfirst($name), $name, $value, '100%', '100%');
0 ignored issues
show
Bug introduced by
The type XoopsFormDhtmlTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
        }
67
68
        //        $form->addElement($descEditor);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
70
        return $descEditor;
71
    }
72
73
    /**
74
     * @param $nameTmp
75
     * @param $emailTmp
76
     * @param $urlTmp
77
     * @param $messageTmp
78
     * @return \XoopsThemeForm
79
     */
80
    public static function getSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp)
81
    {
82
        $name      = new \XoopsFormText(_MD_GBOOK_NAME, 'Name', 43, 100, $nameTmp);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
83
        $email     = new \XoopsFormText(_MD_GBOOK_EMAIL, 'Email', 43, 100, $emailTmp);
84
        $url       = new \XoopsFormText(_MD_GBOOK_URL, 'URL', 43, 100, $urlTmp);
85
        $message   = new \XoopsFormTextArea(_MD_GBOOK_MESSAGE, 'Message', $messageTmp);
0 ignored issues
show
Bug introduced by
The type XoopsFormTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
        $submit    = new \XoopsFormButton('', 'submit', _MD_GBOOK_SUBMIT, 'submit');
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
87
        $gbookform = new \XoopsThemeForm(_MD_GBOOK_SIGN, 'gbookform', 'sign.php');
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
88
89
        $gbookform->addElement($name, true);
90
        $gbookform->addElement($email);
91
        $gbookform->addElement($url);
92
        $gbookform->addElement($message, true);
93
        $gbookform->addElement(new \XoopsFormCaptcha(), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormCaptcha was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
        $gbookform->addElement($submit);
95
96
        return $gbookform;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public static function gbookIP()
103
    {
104
        $ip = 'UNKNOWN';
105
        if (getenv('HTTP_CLIENT_IP')) {
106
            $ip = getenv('HTTP_CLIENT_IP');
107
        } else {
108
            if (getenv('HTTP_X_FORWARDED_FOR')) {
109
                $ip = getenv('HTTP_X_FORWARDED_FOR');
110
            } else {
111
                if (getenv('REMOTE_ADDR')) {
112
                    $ip = getenv('REMOTE_ADDR');
113
                }
114
            }
115
        }
116
117
        return $ip;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ip also could return the type false|array which is incompatible with the documented return type string.
Loading history...
118
    }
119
120
}
121