b_suico_lastpictures_edit()   F
last analyzed

Complexity

Conditions 17
Paths 256

Size

Total Lines 46
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 46
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
2
3
declare(strict_types=1);
4
/*
5
 You may not change or alter any portion of this comment or credits
6
 of supporting developers from this source code or any supporting source code
7
 which is considered copyrighted (c) material of the original comment or credit authors.
8
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
*/
13
14
/**
15
 * @category        Module
16
 * @package         suico
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use XoopsModules\Suico\{
23
    Helper,
24
    ImageHandler
25
};
26
/** @var Helper $helper */
27
28
if (!defined('XOOPS_ROOT_PATH')) {
29
    exit();
30
}
31
//include_once(XOOPS_ROOT_PATH."/class/criteria.php");
32
//require_once XOOPS_ROOT_PATH . '/modules/suico/class/Image.php';
33
/**
34
 * @param $options
35
 * @return array
36
 */
37
function b_suico_lastpictures_show($options)
38
{
39
    global $xoopsDB;
40
41
    /** @var Helper $helper */
42
    if (!class_exists(Helper::class)) {
43
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type array.
Loading history...
44
    }
45
46
    $helper = Helper::getInstance();
47
    $helper->loadLanguage('main');
48
49
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
50
    $block = [];
51
    /**
52
     * Criteria for Pictures Block
53
     */
54
    $criteria = new Criteria('image_id', 0, '>');
55
    $criteria->setSort('image_id');
56
    $criteria->setOrder('DESC');
57
    $criteria->setLimit($options[4]);
58
    /**
59
     * Creating factories of pictures
60
     */
61
    $imageFactory         = new ImageHandler($xoopsDB);
62
    $block['picture']     = $imageFactory->getLastPicturesForBlock($options[4]);
63
    $block['showtitle']   = $options[0];
64
    $block['showcaption'] = $options[1];
65
    $block['showdate']    = $options[2];
66
    $block['showowner']   = $options[3];
67
    return $block;
68
}
69
70
/**
71
 * @param $options
72
 * @return string
73
 */
74
function b_suico_lastpictures_edit($options)
75
{
76
    $form = _MB_SUICO_SHOWPICTURETITLE . '&nbsp;';
77
    $chk  = '';
78
    if (isset($options[0]) && 0 != $options[0]) {
79
        $chk = ' checked';
80
    }
81
    $form .= "<input type='radio' name='options[0]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
82
    $chk  = '';
83
    if (!isset($options[0]) || 0 == $options[0]) {
84
        $chk = ' checked';
85
    }
86
    $form .= "&nbsp;<input type='radio' name='options[0]' value='0'" . $chk . ' >' . _NO . '<br>';
87
    $form .= _MB_SUICO_SHOWPICTURECAPTION . '&nbsp;';
88
    if (isset($options[1]) && 1 == $options[1]) {
89
        $chk = ' checked';
90
    }
91
    $form .= "<input type='radio' name='options[1]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
92
    $chk  = '';
93
    if (!isset($options[1]) || 0 == $options[1]) {
94
        $chk = ' checked';
95
    }
96
    $form .= "&nbsp;<input type='radio' name='options[1]' value='0'" . $chk . ' >' . _NO . '<br>';
97
    $form .= _MB_SUICO_SHOWPICTUREDATE . '&nbsp;';
98
    if (isset($options[2]) && 1 == $options[2]) {
99
        $chk = ' checked';
100
    }
101
    $form .= "<input type='radio' name='options[2]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
102
    $chk  = '';
103
    if (!isset($options[2]) || 0 == $options[2]) {
104
        $chk = ' checked';
105
    }
106
    $form .= "&nbsp;<input type='radio' name='options[2]' value='0'" . $chk . ' >' . _NO . '<br>';
107
    $form .= _MB_SUICO_SHOWPICTUREOWNER . '&nbsp;';
108
    if (isset($options[3]) && 1 == $options[3]) {
109
        $chk = ' checked';
110
    }
111
    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
112
    $chk  = '';
113
    if (!isset($options[3]) || 0 == $options[3]) {
114
        $chk = ' checked';
115
    }
116
    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . ' >' . _NO . '<br>';
117
    $form .= _MB_SUICO_TOTALPICTUREDISPLAY . '&nbsp;';
118
    $form .= "<input type='text' name='options[4]' value='" . ($options[4] ?? 0) . "'>";
119
    return $form;
120
}
121