b_suico_lastpictures_edit()   F
last analyzed

Complexity

Conditions 17
Paths 256

Size

Total Lines 47
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 17
eloc 36
nc 256
nop 1
dl 0
loc 47
rs 3.6833
c 1
b 1
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
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
/**
13
 * @category        Module
14
 * @copyright       {@link https://xoops.org/ XOOPS Project}
15
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
17
 */
18
19
use XoopsModules\Suico\{
20
    Helper,
21
    ImageHandler
22
};
23
/** @var Helper $helper */
24
25
if (!defined('XOOPS_ROOT_PATH')) {
26
    exit();
27
}
28
//require_once XOOPS_ROOT_PATH."/class/criteria.php";
29
//require_once XOOPS_ROOT_PATH . '/modules/suico/class/Image.php';
30
/**
31
 * @param $options
32
 * @return array|false
33
 */
34
function b_suico_lastpictures_show($options)
35
{
36
    global $xoopsDB;
37
38
    /** @var Helper $helper */
39
    if (!class_exists(Helper::class)) {
40
        return false;
41
    }
42
43
    $helper = Helper::getInstance();
44
    $helper->loadLanguage('main');
45
46
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
47
    $block = [];
48
    /**
49
     * Criteria for Pictures Block
50
     */
51
    $criteria = new Criteria('image_id', 0, '>');
52
    $criteria->setSort('image_id');
53
    $criteria->setOrder('DESC');
54
    $criteria->setLimit($options[4]);
55
    /**
56
     * Creating factories of pictures
57
     */
58
    $imageFactory         = new ImageHandler($xoopsDB);
59
    $block['picture']     = $imageFactory->getLastPicturesForBlock($options[4]);
60
    $block['showtitle']   = $options[0];
61
    $block['showcaption'] = $options[1];
62
    $block['showdate']    = $options[2];
63
    $block['showowner']   = $options[3];
64
65
    return $block;
66
}
67
68
/**
69
 * @param $options
70
 * @return string
71
 */
72
function b_suico_lastpictures_edit($options)
73
{
74
    $form = _MB_SUICO_SHOWPICTURETITLE . '&nbsp;';
75
    $chk  = '';
76
    if (isset($options[0]) && 0 != $options[0]) {
77
        $chk = ' checked';
78
    }
79
    $form .= "<input type='radio' name='options[0]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
80
    $chk  = '';
81
    if (!isset($options[0]) || 0 == $options[0]) {
82
        $chk = ' checked';
83
    }
84
    $form .= "&nbsp;<input type='radio' name='options[0]' value='0'" . $chk . ' >' . _NO . '<br>';
85
    $form .= _MB_SUICO_SHOWPICTURECAPTION . '&nbsp;';
86
    if (isset($options[1]) && 1 == $options[1]) {
87
        $chk = ' checked';
88
    }
89
    $form .= "<input type='radio' name='options[1]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
90
    $chk  = '';
91
    if (!isset($options[1]) || 0 == $options[1]) {
92
        $chk = ' checked';
93
    }
94
    $form .= "&nbsp;<input type='radio' name='options[1]' value='0'" . $chk . ' >' . _NO . '<br>';
95
    $form .= _MB_SUICO_SHOWPICTUREDATE . '&nbsp;';
96
    if (isset($options[2]) && 1 == $options[2]) {
97
        $chk = ' checked';
98
    }
99
    $form .= "<input type='radio' name='options[2]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
100
    $chk  = '';
101
    if (!isset($options[2]) || 0 == $options[2]) {
102
        $chk = ' checked';
103
    }
104
    $form .= "&nbsp;<input type='radio' name='options[2]' value='0'" . $chk . ' >' . _NO . '<br>';
105
    $form .= _MB_SUICO_SHOWPICTUREOWNER . '&nbsp;';
106
    if (isset($options[3]) && 1 == $options[3]) {
107
        $chk = ' checked';
108
    }
109
    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
110
    $chk  = '';
111
    if (!isset($options[3]) || 0 == $options[3]) {
112
        $chk = ' checked';
113
    }
114
    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . ' >' . _NO . '<br>';
115
    $form .= _MB_SUICO_TOTALPICTUREDISPLAY . '&nbsp;';
116
    $form .= "<input type='text' name='options[4]' value='" . ($options[4] ?? 0) . "'>";
117
118
    return $form;
119
}
120