Completed
Push — master ( 66731e...5478d6 )
by Michael
02:20
created

tplleaguestats.php ➔ b_marquee_tplleaguestats()   B

Complexity

Conditions 7
Paths 20

Size

Total Lines 62
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 38
nc 20
nop 3
dl 0
loc 62
rs 7.3333
c 0
b 0
f 0

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
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (http://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 (http://www.herve-thouzard.com)
15
 * @license           http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package           marquee
17
 * @author            Hervé Thouzard (http://www.herve-thouzard.com)
18
 *
19
 * Version : $Id:
20
 * ****************************************************************************
21
 *
22
 * @param $limit
23
 * @param $dateFormat
24
 * @param $itemsSize
25
 *
26
 * @return array
27
 */
28
29
//  ------------------------------------------------------------------------ //
30
//  TplLeagueStats plugin for Marquee 2.4                                    //
31
//  written by Defkon1 [defkon1 at gmail dot com]                            //
32
//  ------------------------------------------------------------------------ //
33
34
function b_marquee_tplleaguestats($limit, $dateFormat, $itemsSize)
35
{
36
    include_once XOOPS_ROOT_PATH . '/modules/marquee/include/functions.php';
37
38
    //######################## SETTINGS ######################
39
    $displaySeason  = false; // display season name?
40
    $hour           = 1; // GMT+1  -> var = 1
41
    $useItemSize   = false; // use marquee $itemsize value?
42
    $overwriteLimit = true; // overwrite marquee's limit settings?
43
    $newLimit       = 6; // new limit (valid only if
44
    //     overwrite_limit_settings = true)
45
    $overwriteDateformat = true; // overwrite marquee's dateformat?
46
    $newDateformat       = 'd/m/Y'; // new dateformat (valid only if
47
    //     overwrite_dateformat_settings=true)
48
    //######################## SETTINGS ######################
49
50
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
51
52
    if ($overwriteLimit) {
53
        $limit = $newLimit;
54
    }
55
    if ($overwriteDateformat) {
56
        $dateFormat = $newDateformat;
57
    }
58
59
    $block  = array();
60
    $myts   = MyTextSanitizer::getInstance();
61
    $sql    = 'SELECT H.OpponentName as home, A.OpponentName as away, M.LeagueMatchHomeGoals as home_p, M.LeagueMatchAwayGoals as away_p,
62
                  M.LeagueMatchDate as date, S.SeasonName as season
63
           FROM ' . $xoopsDB->prefix('tplls_leaguematches') . ' M
64
           LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS H ON M.LeagueMatchHomeID = H.OpponentID
65
           LEFT JOIN ' . $xoopsDB->prefix('tplls_opponents') . ' AS A ON M.LeagueMatchAwayID = A.OpponentID
66
           LEFT JOIN ' . $xoopsDB->prefix('tplls_seasonnames') . " AS S ON M.LeagueMatchSeasonID = S.SeasonID
67
           ORDER BY M.LeagueMatchDate DESC
68
           LIMIT 0,$limit";
69
    $result = $xoopsDB->query($sql);
70
    while ($myrow = $xoopsDB->fetchArray($result)) {
71
        $title = $myts->htmlSpecialChars($myrow['home']) . ' - ' . $myts->htmlSpecialChars($myrow['away']) . ' ' . $myts->htmlSpecialChars($myrow['home_p']) . '-' . $myts->htmlSpecialChars($myrow['away_p']);
72
73
        if ($useItemSize && $itemsSize > 0) {
74
            $title = xoops_substr($title, 0, $itemsSize + 3);
75
        }
76
77
        $arrDate = explode('-', $myrow['date']);
78
79
        $season = '';
80
81
        if ($displaySeason) {
82
            $season = $myrow['season'];
83
        }
84
85
        $block[] = array(
86
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], $arrDate[0]), $dateFormat),
87
            'category' => $season,
88
            'author'   => '',
89
            'title'    => $title,
90
            'link'     => "<a href=\"" . XOOPS_URL . "/modules/tplleaguestats\">" . $title . '</a>'
91
        );
92
    }
93
94
    return $block;
95
}
96