Passed
Push — master ( dcbd4a...4bb7b0 )
by Michael
02:37
created

b_marquee_tplleaguestats()   B

Complexity

Conditions 7
Paths 20

Size

Total Lines 61
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 36
c 0
b 0
f 0
nc 20
nop 3
dl 0
loc 61
rs 7.399

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 :
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
//    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.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) {
0 ignored issues
show
introduced by
The condition $overwriteLimit is always true.
Loading history...
53
        $limit = $newLimit;
54
    }
55
    if ($overwriteDateformat) {
0 ignored issues
show
introduced by
The condition $overwriteDateformat is always true.
Loading history...
56
        $dateFormat = $newDateformat;
57
    }
58
59
    $block  = [];
60
    $myts   = \MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer 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...
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 (false !== ($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);
0 ignored issues
show
Bug introduced by
The function xoops_substr 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

74
            $title = /** @scrutinizer ignore-call */ xoops_substr($title, 0, $itemsSize + 3);
Loading history...
75
        }
76
77
        $arrDate = explode('-', $myrow['date']);
78
79
        $season = '';
80
81
        if ($displaySeason) {
82
            $season = $myrow['season'];
83
        }
84
85
        $block[] = [
86
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], $arrDate[0]), $dateFormat),
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

86
            'date'     => /** @scrutinizer ignore-call */ formatTimestamp(mktime($hour, 0, 0, $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

86
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], $arrDate[2], /** @scrutinizer ignore-type */ $arrDate[0]), $dateFormat),
Loading history...
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

86
            'date'     => formatTimestamp(mktime($hour, 0, 0, /** @scrutinizer ignore-type */ $arrDate[1], $arrDate[2], $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

86
            'date'     => formatTimestamp(mktime($hour, 0, 0, $arrDate[1], /** @scrutinizer ignore-type */ $arrDate[2], $arrDate[0]), $dateFormat),
Loading history...
87
            'category' => $season,
88
            'author'   => '',
89
            'title'    => $title,
90
            'link'     => '<a href="' . XOOPS_URL . '/modules/tplleaguestats">' . $title . '</a>'
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
91
        ];
92
    }
93
94
    return $block;
95
}
96