Logs   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 70
c 1
b 0
f 1
dl 0
loc 138
rs 10
wmc 16

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewInsertedIdLogs() 0 4 1
A getInstance() 0 5 2
A __construct() 0 8 1
A getFormLogs() 0 34 4
B getValuesLogs() 0 33 6
A toArrayRequests() 0 8 2
1
<?php
2
3
namespace XoopsModules\Wggithub;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * wgGitHub module for xoops
17
 *
18
 * @copyright      2020 XOOPS Project (https://xooops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        wggithub
21
 * @since          1.0
22
 * @min_xoops      2.5.10
23
 * @author         Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
24
 */
25
26
use XoopsModules\Wggithub;
27
28
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object Logs
32
 */
33
class Logs extends \XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
34
{
35
    /**
36
     * Constructor
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        $this->initVar('log_id', \XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43
        $this->initVar('log_type', \XOBJ_DTYPE_INT);
44
        $this->initVar('log_details', \XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
        $this->initVar('log_result', \XOBJ_DTYPE_TXTAREA);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTAREA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
46
        $this->initVar('log_datecreated', \XOBJ_DTYPE_INT);
47
        $this->initVar('log_submitter', \XOBJ_DTYPE_INT);
48
    }
49
50
    /**
51
     * @static function &getInstance
52
     *
53
     * @param null
54
     */
55
    public static function getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
    }
62
63
    /**
64
     * The new inserted $Id
65
     * @return inserted id
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wggithub\inserted 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
    public function getNewInsertedIdLogs()
68
    {
69
        $newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
70
        return $newInsertedId;
71
    }
72
73
    /**
74
     * @public function getForm
75
     * @param bool $action
76
     * @param int  $start
77
     * @param int  $limit
78
     * @return \XoopsThemeForm
79
     */
80
    public function getFormLogs($action = false, $start = 0, $limit = 0)
81
    {
82
        if (!$action) {
83
            $action = $_SERVER['REQUEST_URI'];
84
        }
85
        // Title
86
        $title = $this->isNew() ? \sprintf(\_AM_WGGITHUB_LOG_ADD) : \sprintf(\_AM_WGGITHUB_LOG_EDIT);
87
        // Get Theme Form
88
        \xoops_load('XoopsFormLoader');
0 ignored issues
show
Bug introduced by
The function xoops_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
        /** @scrutinizer ignore-call */ \xoops_load('XoopsFormLoader');
Loading history...
89
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
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...
90
        $form->setExtra('enctype="multipart/form-data"');
91
92
        $logTypeSelect = new \XoopsFormSelect(\_AM_WGGITHUB_LOG_TYPE, 'log_type', $this->getVar('log_type'));
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect 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...
93
        $logTypeSelect->addOption(Constants::LOG_TYPE_NONE, \_AM_WGGITHUB_LOG_TYPE_NONE);
94
        $logTypeSelect->addOption(Constants::LOG_TYPE_UPDATE_START, \_AM_WGGITHUB_LOG_TYPE_UPDATE_START);
95
        $logTypeSelect->addOption(Constants::LOG_TYPE_UPDATE_END, \_AM_WGGITHUB_LOG_TYPE_UPDATE_END);
96
        $logTypeSelect->addOption(Constants::LOG_TYPE_REQUEST, \_AM_WGGITHUB_LOG_TYPE_REQUEST);
97
        $logTypeSelect->addOption(Constants::LOG_TYPE_ERROR, \_AM_WGGITHUB_LOG_TYPE_ERROR);
98
        $form->addElement($logTypeSelect);
99
        // Form Text logDetails
100
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_LOG_DETAILS, 'log_details', 50, 255, $this->getVar('log_details')), true);
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...
101
        // Form Text logResult
102
        $form->addElement(new \XoopsFormTextArea(\_AM_WGGITHUB_LOG_RESULT, 'log_result', $this->getVar('log_result', 'e'), 4, 47));
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...
103
        // Form Text Date Select logDatecreated
104
        $logDatecreated = $this->isNew() ?: $this->getVar('log_datecreated');
105
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_LOG_DATECREATED, 'log_datecreated', '', $logDatecreated));
0 ignored issues
show
Bug introduced by
The type XoopsFormTextDateSelect 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...
106
        // Form Select User reqSubmitter
107
        $form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_LOG_SUBMITTER, 'log_submitter', false, $this->getVar('log_submitter')));
0 ignored issues
show
Bug introduced by
The type XoopsFormSelectUser 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...
108
        // To Save
109
        $form->addElement(new \XoopsFormHidden('op', 'save'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden 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...
110
        $form->addElement(new \XoopsFormHidden('start', $start));
111
        $form->addElement(new \XoopsFormHidden('limit', $limit));
112
        $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
0 ignored issues
show
Bug introduced by
The type XoopsFormButtonTray 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...
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
113
        return $form;
114
    }
115
116
    /**
117
     * Get Values
118
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
119
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
120
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
121
     * @return array
122
     */
123
    public function getValuesLogs($keys = null, $format = null, $maxDepth = null)
124
    {
125
        $helper  = \XoopsModules\Wggithub\Helper::getInstance();
126
        $utility = new \XoopsModules\Wggithub\Utility();
127
        $editorMaxchar = $helper->getConfig('editor_maxchar');
128
        $ret = $this->getValues($keys, $format, $maxDepth);
129
        $ret['id']           = $this->getVar('log_id');
130
        $ret['type']         = $this->getVar('log_type');
131
        switch ($ret['type']) {
132
            case Constants::LOG_TYPE_NONE:
133
            default:
134
                $type_text = \_AM_WGGITHUB_LOG_TYPE_NONE;
135
                break;
136
            case Constants::LOG_TYPE_UPDATE_START:
137
                $type_text = \_AM_WGGITHUB_LOG_TYPE_UPDATE_START;
138
                break;
139
            case Constants::LOG_TYPE_UPDATE_END:
140
                $type_text = \_AM_WGGITHUB_LOG_TYPE_UPDATE_END;
141
                break;
142
            case Constants::LOG_TYPE_REQUEST:
143
                $type_text = \_AM_WGGITHUB_LOG_TYPE_REQUEST;
144
                break;
145
            case Constants::LOG_TYPE_ERROR:
146
                $type_text = \_AM_WGGITHUB_LOG_TYPE_ERROR;
147
                break;
148
        }
149
        $ret['type_text']    = $type_text;
150
        $ret['details']      = $this->getVar('log_details');
151
        $ret['result']       = \strip_tags($this->getVar('log_result', 'e'));
152
        $ret['result_short'] = $utility::truncateHtml($ret['result'], $editorMaxchar);
153
        $ret['datecreated']  = \formatTimestamp($this->getVar('log_datecreated'), 'm');
0 ignored issues
show
Bug introduced by
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

153
        $ret['datecreated']  = /** @scrutinizer ignore-call */ \formatTimestamp($this->getVar('log_datecreated'), 'm');
Loading history...
154
        $ret['submitter']    = \XoopsUser::getUnameFromId($this->getVar('log_submitter'));
0 ignored issues
show
Bug introduced by
The type XoopsUser 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...
155
        return $ret;
156
    }
157
158
    /**
159
     * Returns an array representation of the object
160
     *
161
     * @return array
162
     */
163
    public function toArrayRequests()
164
    {
165
        $ret = [];
166
        $vars = $this->getVars();
167
        foreach (\array_keys($vars) as $var) {
168
            $ret[$var] = $this->getVar('"{$var}"');
169
        }
170
        return $ret;
171
    }
172
}
173