Passed
Push — master ( 8085c4...3786e6 )
by Goffy
03:03
created

Repositories   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 165
rs 10
c 0
b 0
f 0
wmc 18

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A getNewInsertedIdRepositories() 0 4 1
B getFormRepositories() 0 50 6
A getInstance() 0 5 2
B getValuesRepositories() 0 38 6
A toArrayRepositories() 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 Repositories
32
 */
33
class Repositories 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('repo_id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43
        $this->initVar('repo_nodeid', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
        $this->initVar('repo_user', XOBJ_DTYPE_TXTBOX);
45
        $this->initVar('repo_name', XOBJ_DTYPE_TXTBOX);
46
        $this->initVar('repo_fullname', XOBJ_DTYPE_TXTBOX);
47
        $this->initVar('repo_createdat', XOBJ_DTYPE_INT);
48
        $this->initVar('repo_updatedat', XOBJ_DTYPE_INT);
49
        $this->initVar('repo_htmlurl', XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('repo_readme', XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('repo_prerelease', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('repo_release', XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('repo_status', XOBJ_DTYPE_INT);
54
        $this->initVar('repo_datecreated', XOBJ_DTYPE_INT);
55
        $this->initVar('repo_submitter', XOBJ_DTYPE_INT);
56
    }
57
58
    /**
59
     * @static function &getInstance
60
     *
61
     * @param null
62
     */
63
    public static function getInstance()
64
    {
65
        static $instance = false;
66
        if (!$instance) {
67
            $instance = new self();
68
        }
69
    }
70
71
    /**
72
     * The new inserted $Id
73
     * @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...
74
     */
75
    public function getNewInsertedIdRepositories()
76
    {
77
        $newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
78
        return $newInsertedId;
79
    }
80
81
    /**
82
     * @public function getForm
83
     * @param bool $action
84
     * @return \XoopsThemeForm
85
     */
86
    public function getFormRepositories($action = false)
87
    {
88
        $helper = \XoopsModules\Wggithub\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
89
        if (!$action) {
90
            $action = $_SERVER['REQUEST_URI'];
91
        }
92
        // Title
93
        $title = $this->isNew() ? \sprintf(_AM_WGGITHUB_REPOSITORY_ADD) : \sprintf(_AM_WGGITHUB_REPOSITORY_EDIT);
94
        // Get Theme Form
95
        \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

95
        /** @scrutinizer ignore-call */ 
96
        \xoops_load('XoopsFormLoader');
Loading history...
96
        $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...
97
        $form->setExtra('enctype="multipart/form-data"');
98
        // Form Text repoNodeid
99
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_NODEID, 'repo_nodeid', 50, 255, $this->getVar('repo_nodeid')));
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...
100
        // Form Text repoUser
101
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_USER, 'repo_user', 50, 255, $this->getVar('repo_user')), true);
102
        // Form Text repoName
103
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_NAME, 'repo_name', 50, 255, $this->getVar('repo_name')), true);
104
        // Form Text repoFullname
105
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_FULLNAME, 'repo_fullname', 50, 255, $this->getVar('repo_fullname')));
106
        // Form Text Date Select repoCreatedat
107
        $repoCreatedat = $this->isNew() ?: $this->getVar('repo_createdat');
108
        $form->addElement(new \XoopsFormTextDateSelect(_AM_WGGITHUB_REPOSITORY_CREATEDAT, 'repo_createdat', '', $repoCreatedat));
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...
109
        // Form Text Date Select repoUpdatedat
110
        $repoUpdatedat = $this->isNew() ?: $this->getVar('repo_updatedat');
111
        $form->addElement(new \XoopsFormTextDateSelect(_AM_WGGITHUB_REPOSITORY_UPDATEDAT, 'repo_updatedat', '', $repoUpdatedat));
112
        // Form Text repoHtmlurl
113
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_HTMLURL, 'repo_htmlurl', 50, 255, $this->getVar('repo_htmlurl')));
114
        // Form Text repoReadme
115
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_README, 'repo_readme', 50, 255, $this->getVar('repo_readme')));
116
        // Form Text repoPrerelease
117
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_PRERELEASE, 'repo_prerelease', 50, 255, $this->getVar('repo_prerelease')));
118
        // Form Text repoRelease
119
        $form->addElement(new \XoopsFormText(_AM_WGGITHUB_REPOSITORY_RELEASE, 'repo_release', 50, 255, $this->getVar('repo_prelease')));
120
        // Form Select Status repoStatus
121
        $repoStatusSelect = new \XoopsFormSelect(_AM_WGGITHUB_REPOSITORY_STATUS, 'repo_status', $this->getVar('repo_status'));
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...
122
        $repoStatusSelect->addOption(Constants::STATUS_NONE, _AM_WGGITHUB_STATUS_NONE);
123
        $repoStatusSelect->addOption(Constants::STATUS_UPTODATE, _AM_WGGITHUB_STATUS_UPTODATE);
124
        $repoStatusSelect->addOption(Constants::STATUS_UPDATED, _AM_WGGITHUB_STATUS_UPDATED);
125
        $repoStatusSelect->addOption(Constants::STATUS_OFFLINE, _AM_WGGITHUB_STATUS_OFFLINE);
126
        $form->addElement($repoStatusSelect);
127
        // Form Text Date Select repoDatecreated
128
        $repoDatecreated = $this->isNew() ?: $this->getVar('repo_datecreated');
129
        $form->addElement(new \XoopsFormTextDateSelect(_AM_WGGITHUB_REPOSITORY_DATECREATED, 'repo_datecreated', '', $repoDatecreated));
130
        // Form Select User repoSubmitter
131
        $form->addElement(new \XoopsFormSelectUser(_AM_WGGITHUB_REPOSITORY_SUBMITTER, 'repo_submitter', false, $this->getVar('repo_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...
132
        // To Save
133
        $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...
134
        $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 XoopsModules\Wggithub\_SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
135
        return $form;
136
    }
137
138
    /**
139
     * Get Values
140
     * @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...
141
     * @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...
142
     * @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...
143
     * @return array
144
     */
145
    public function getValuesRepositories($keys = null, $format = null, $maxDepth = null)
146
    {
147
        $ret = $this->getValues($keys, $format, $maxDepth);
148
        $ret['id']          = $this->getVar('repo_id');
149
        $ret['nodeid']      = $this->getVar('repo_nodeid');
150
        $ret['user']        = $this->getVar('repo_user');
151
        $ret['name']        = $this->getVar('repo_name');
152
        $ret['fullname']    = $this->getVar('repo_fullname');
153
        $ret['createdat']   = \formatTimestamp($this->getVar('repo_createdat'), '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['createdat']   = /** @scrutinizer ignore-call */ \formatTimestamp($this->getVar('repo_createdat'), 'm');
Loading history...
154
        $ret['updatedat']   = \formatTimestamp($this->getVar('repo_updatedat'), 'm');
155
        $ret['htmlurl']     = $this->getVar('repo_htmlurl');
156
        $ret['readme']      = $this->getVar('repo_readme');
157
        $ret['prerelease']  = $this->getVar('repo_prerelease');
158
        $ret['release']     = $this->getVar('repo_release');
159
        $status             = $this->getVar('repo_status');
160
        $ret['status']      = $status;
161
        switch ($status) {
162
            case Constants::STATUS_NONE:
163
            default:
164
                $status_text = \_AM_WGGITHUB_STATUS_NONE;
165
                break;
166
            case Constants::STATUS_NEW:
167
                $status_text = \_AM_WGGITHUB_STATUS_NEW;
168
                break;
169
            case Constants::STATUS_UPTODATE:
170
                $status_text = \_AM_WGGITHUB_STATUS_UPTODATE;
171
                break;
172
            case Constants::STATUS_UPDATED:
173
                $status_text = \_AM_WGGITHUB_STATUS_UPDATED;
174
                break;
175
            case Constants::STATUS_OFFLINE:
176
                $status_text = _AM_WGGITHUB_STATUS_OFFLINE;
177
                break;
178
        }
179
        $ret['status_text'] = $status_text;
180
        $ret['datecreated'] = \formatTimestamp($this->getVar('repo_datecreated'), 'm');
181
        $ret['submitter']   = \XoopsUser::getUnameFromId($this->getVar('repo_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...
182
        return $ret;
183
    }
184
185
    /**
186
     * Returns an array representation of the object
187
     *
188
     * @return array
189
     */
190
    public function toArrayRepositories()
191
    {
192
        $ret = [];
193
        $vars = $this->getVars();
194
        foreach (\array_keys($vars) as $var) {
195
            $ret[$var] = $this->getVar('"{$var}"');
196
        }
197
        return $ret;
198
    }
199
}
200