Passed
Push — master ( 6d3e95...4ad186 )
by Goffy
03:09
created

Releases::getFormReleases()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 28
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 43
rs 9.1608
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 Releases
32
 */
33
class Releases 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('rel_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('rel_repoid', \XOBJ_DTYPE_INT);
44
        $this->initVar('rel_type', \XOBJ_DTYPE_INT);
45
        $this->initVar('rel_name', \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...
46
        $this->initVar('rel_prerelease', \XOBJ_DTYPE_INT);
47
        $this->initVar('rel_publishedat', \XOBJ_DTYPE_INT);
48
        $this->initVar('rel_tarballurl', \XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('rel_zipballurl', \XOBJ_DTYPE_TXTBOX);
50
        $this->initVar('rel_datecreated', \XOBJ_DTYPE_INT);
51
        $this->initVar('rel_submitter', \XOBJ_DTYPE_INT);
52
    }
53
54
    /**
55
     * @static function &getInstance
56
     *
57
     * @param null
58
     */
59
    public static function getInstance()
60
    {
61
        static $instance = false;
62
        if (!$instance) {
63
            $instance = new self();
64
        }
65
    }
66
67
    /**
68
     * The new inserted $Id
69
     * @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...
70
     */
71
    public function getNewInsertedIdReleases()
72
    {
73
        $newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
74
        return $newInsertedId;
75
    }
76
77
    /**
78
     * @public function getForm
79
     * @param bool $action
80
     * @param int  $start
81
     * @param int  $limit
82
     * @return \XoopsThemeForm
83
     */
84
    public function getFormReleases($action = false, $start = 0, $limit = 0)
85
    {
86
        $helper = \XoopsModules\Wggithub\Helper::getInstance();
87
        if (!$action) {
88
            $action = $_SERVER['REQUEST_URI'];
89
        }
90
91
        // Get Theme Form
92
        \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

92
        /** @scrutinizer ignore-call */ \xoops_load('XoopsFormLoader');
Loading history...
93
        $form = new \XoopsThemeForm(\_AM_WGGITHUB_RELEASE_EDIT, '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...
94
        $form->setExtra('enctype="multipart/form-data"');
95
        // Form Table repositories
96
        $repositoriesHandler = $helper->getHandler('Repositories');
97
        $rmRepoidSelect = new \XoopsFormSelect(\_AM_WGGITHUB_README_REPOID, 'rel_repoid', $this->getVar('rel_repoid'));
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...
98
        $rmRepoidSelect->addOptionArray($repositoriesHandler->getList());
99
        $form->addElement($rmRepoidSelect);
100
        // Form Select relType
101
        $relTypeSelect = new \XoopsFormSelect(\_AM_WGGITHUB_RELEASE_TYPE, 'rel_type', $this->getVar('rel_type'));
102
        $relTypeSelect->addOption('file');
103
        $form->addElement($relTypeSelect);
104
        // Form Text relName
105
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_RELEASE_NAME, 'rel_name', 50, 255, $this->getVar('rel_name')), 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...
106
        // Form Radio Yes/No relPrerelease
107
        $relPrerelease = $this->isNew() ?: $this->getVar('rel_prerelease');
108
        $form->addElement(new \XoopsFormRadioYN(\_AM_WGGITHUB_RELEASE_PRERELEASE, 'rel_prerelease', $relPrerelease));
0 ignored issues
show
Bug introduced by
The type XoopsFormRadioYN 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 relPublishedat
110
        $relPublishedat = $this->isNew() ?: $this->getVar('rel_publishedat');
111
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_RELEASE_PUBLISHEDAT, 'rel_publishedat', '', $relPublishedat));
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...
112
        // Form Text relTarballurl
113
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_RELEASE_TARBALLURL, 'rel_tarballurl', 50, 255, $this->getVar('rel_tarballurl')));
114
        // Form Text relZipballurl
115
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_RELEASE_ZIPBALLURL, 'rel_zipballurl', 50, 255, $this->getVar('rel_zipballurl')));
116
        // Form Text Date Select relDatecreated
117
        $relDatecreated = $this->isNew() ?: $this->getVar('rel_datecreated');
118
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_RELEASE_DATECREATED, 'rel_datecreated', '', $relDatecreated));
119
        // Form Select User relSubmitter
120
        $form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_RELEASE_SUBMITTER, 'rel_submitter', false, $this->getVar('rel_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...
121
        // To Save
122
        $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...
123
        $form->addElement(new \XoopsFormHidden('start', $start));
124
        $form->addElement(new \XoopsFormHidden('limit', $limit));
125
        $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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...
126
        return $form;
127
    }
128
129
    /**
130
     * Get Values
131
     * @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...
132
     * @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...
133
     * @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...
134
     * @return array
135
     */
136
    public function getValuesReleases($keys = null, $format = null, $maxDepth = null)
137
    {
138
        $helper  = \XoopsModules\Wggithub\Helper::getInstance();
139
        $ret = $this->getValues($keys, $format, $maxDepth);
140
        $ret['id']          = $this->getVar('rel_id');
141
        $repositoriesHandler = $helper->getHandler('Repositories');
142
        $repositoriesObj = $repositoriesHandler->get($this->getVar('rel_repoid'));
143
        if (\is_object($repositoriesObj)) {
144
            $ret['repoid']        = $repositoriesObj->getVar('repo_name');
145
        } else {
146
            $ret['repoid']        = '*****missing repo_name*****';
147
        }
148
        $ret['type']        = $this->getVar('rel_type');
149
        $ret['name']        = $this->getVar('rel_name');
150
        $ret['prerelease']  = (int)$this->getVar('rel_prerelease') > 0 ? _YES : _NO;
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\_NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XoopsModules\Wggithub\_YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
151
        $ret['publishedat'] = \formatTimestamp($this->getVar('rel_publishedat'), '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

151
        $ret['publishedat'] = /** @scrutinizer ignore-call */ \formatTimestamp($this->getVar('rel_publishedat'), 'm');
Loading history...
152
        $ret['tarballurl']  = $this->getVar('rel_tarballurl');
153
        $ret['zipballurl']  = $this->getVar('rel_zipballurl');
154
        $ret['datecreated'] = \formatTimestamp($this->getVar('rel_datecreated'), 'm');
155
        $ret['submitter']   = \XoopsUser::getUnameFromId($this->getVar('rel_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...
156
        return $ret;
157
    }
158
159
    /**
160
     * Returns an array representation of the object
161
     *
162
     * @return array
163
     */
164
    public function toArrayReleases()
165
    {
166
        $ret = [];
167
        $vars = $this->getVars();
168
        foreach (\array_keys($vars) as $var) {
169
            $ret[$var] = $this->getVar('"{$var}"');
170
        }
171
        return $ret;
172
    }
173
}
174