b_marquee_tplleaguestats()   B
last analyzed

Complexity

Conditions 8
Paths 24

Size

Total Lines 56
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 39
c 0
b 0
f 0
nc 24
nop 3
dl 0
loc 56
rs 8.0515

How to fix   Long Method   

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
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright         Hervé Thouzard (https://www.herve-thouzard.com)
15
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author            Hervé Thouzard (https://www.herve-thouzard.com)
17
 *
18
 * Version :
19
 * ****************************************************************************
20
 *
21
 * @param $limit
22
 * @param $dateFormat
23
 * @param $itemsSize
24
 *
25
 * @return array
26
 */
27
28
//  ------------------------------------------------------------------------ //
29
//  TplLeagueStats plugin for Marquee 2.4                                    //
30
//  written by Defkon1 [defkon1 at gmail dot com]                            //
31
//  ------------------------------------------------------------------------ //
32
function b_marquee_tplleaguestats($limit, $dateFormat, $itemsSize)
33
{
34
    //    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
35
    //######################## SETTINGS ######################
36
    $displaySeason  = false; // display season name?
37
    $hour           = 1; // GMT+1  -> var = 1
38
    $useItemSize    = false; // use marquee $itemsize value?
39
    $overwriteLimit = true; // overwrite marquee's limit settings?
40
    $newLimit       = 6; // new limit (valid only if
41
    //     overwrite_limit_settings = true)
42
    $overwriteDateformat = true; // overwrite marquee's dateformat?
43
    $newDateformat       = 'd/m/Y'; // new dateformat (valid only if
44
    //     overwrite_dateformat_settings=true)
45
    //######################## SETTINGS ######################
46
    global $xoopsDB;
47
    if ($overwriteLimit) {
0 ignored issues
show
introduced by
The condition $overwriteLimit is always true.
Loading history...
48
        $limit = $newLimit;
49
    }
50
    if ($overwriteDateformat) {
0 ignored issues
show
introduced by
The condition $overwriteDateformat is always true.
Loading history...
51
        $dateFormat = $newDateformat;
52
    }
53
    $block  = [];
54
    $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
55
    $sql    = 'SELECT H.OpponentName as home, A.OpponentName as away, M.LeagueMatchHomeGoals as home_p, M.LeagueMatchAwayGoals as away_p,
56
                  M.LeagueMatchDate as date, S.SeasonName as season
57
           FROM ' . $xoopsDB->prefix('tplls_leaguematches') . ' M
58
           LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS H ON M.LeagueMatchHomeID = H.OpponentID
59
           LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS A ON M.LeagueMatchAwayID = A.OpponentID
60
           LEFT JOIN ' . $xoopsDB->prefix('tplls_seasonnames') . " AS S ON M.LeagueMatchSeasonID = S.SeasonID
61
           ORDER BY M.LeagueMatchDate DESC
62
           LIMIT 0,$limit";
63
    $result = $xoopsDB->query($sql);
64
    if (!$xoopsDB->isResultSet($result)) {
65
        throw new \RuntimeException(
66
            \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR);
67
    }
68
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
69
        $title = htmlspecialchars($myrow['home'], ENT_QUOTES | ENT_HTML5) . ' - ' . htmlspecialchars($myrow['away'], ENT_QUOTES | ENT_HTML5) . ' ' . htmlspecialchars($myrow['home_p'], ENT_QUOTES | ENT_HTML5) . '-' . htmlspecialchars($myrow['away_p'], ENT_QUOTES | ENT_HTML5);
70
        if ($useItemSize && $itemsSize > 0) {
71
            $title = xoops_substr($title, 0, $itemsSize + 3);
72
        }
73
        $arrDate = explode('-', $myrow['date']);
74
        $season  = '';
75
        if ($displaySeason) {
76
            $season = $myrow['season'];
77
        }
78
        $block[] = [
79
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], $arrDate[0]), $dateFormat),
0 ignored issues
show
Bug introduced by
$arrDate[1] of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

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

79
            'date'     => formatTimestamp(mktime($hour, 0, 0, /** @scrutinizer ignore-type */ $arrDate[1], $arrDate[2], $arrDate[0]), $dateFormat),
Loading history...
Bug introduced by
$arrDate[0] of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

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

79
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], /** @scrutinizer ignore-type */ $arrDate[0]), $dateFormat),
Loading history...
Bug introduced by
$arrDate[2] of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

79
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], /** @scrutinizer ignore-type */ $arrDate[2], $arrDate[0]), $dateFormat),
Loading history...
80
            'category' => $season,
81
            'author'   => '',
82
            'title'    => $title,
83
            'link'     => '<a href="' . XOOPS_URL . '/modules/tplleaguestats">' . $title . '</a>',
84
        ];
85
    }
86
87
    return $block;
88
}
89