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

b_marquee_catads()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 56
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 43
c 0
b 0
f 0
nc 4
nop 3
dl 0
loc 56
rs 7.7489

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
use XoopsModules\Catads;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Catads 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...
30
31
// Script to list recent ads from the catads module (tested with catads v 1.4)
32
/**
33
 * @param $limit
34
 * @param $dateFormat
35
 * @param $itemsSize
36
 * @return array
37
 */
38
function b_marquee_catads($limit, $dateFormat, $itemsSize)
39
{
40
    global $xoopsModule, $xoopsModuleConfig, $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...
41
    require_once XOOPS_ROOT_PATH . '/modules/catads/class/cat.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
42
    $block = [];
43
    if (empty($xoopsModule) || 'catads' !== $xoopsModule->getVar('dirname')) {
44
        /** @var \XoopsModuleHandler $moduleHandler */
45
        $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler 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

45
        $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
46
        $module        = $moduleHandler->getByDirname('catads');
47
        $configHandler = xoops_getHandler('config');
48
        $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
49
    } else {
50
        $module = $xoopsModule;
0 ignored issues
show
Unused Code introduced by
The assignment to $module is dead and can be removed.
Loading history...
51
        $config = $xoopsModuleConfig;
52
    }
53
    //echo '<br>ok';
54
    $ads_hnd  = Catads\Helper::getInstance()->getHandler('Ads');
0 ignored issues
show
Bug introduced by
The type XoopsModules\Catads\Helper 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...
55
    $criteria = new \CriteriaCompo(new \Criteria('waiting', '0'));
0 ignored issues
show
Bug introduced by
The type Criteria 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...
Bug introduced by
The type CriteriaCompo 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...
56
    $criteria->add(new \Criteria('published', time(), '<'));
57
    $criteria->add(new \Criteria('expired', time(), '>'));
58
    $criteria->setSort('published');
59
    $criteria->setOrder('DESC');
60
    $criteria->setLimit($limit);
61
    $nbads = $ads_hnd->getCount($criteria);
62
63
    $itemArray = [];
64
    $catBuffer = [];
65
66
    if ($nbads > 0) {
67
        $ads  = $ads_hnd->getObjects($criteria);
68
        $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...
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
69
        foreach ($ads as $oneads) {
70
            if ($itemsSize > 0) {
71
                $title = xoops_substr($oneads->getVar('ads_title'), 0, $itemsSize);
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

71
                $title = /** @scrutinizer ignore-call */ xoops_substr($oneads->getVar('ads_title'), 0, $itemsSize);
Loading history...
72
            } else {
73
                $title = $oneads->getVar('ads_title');
74
            }
75
            if (!isset($catBuffer[$oneads->getVar('cat_id')])) {
76
                $tmpcat                               = new Catads\AdsCategory($oneads->getVar('cat_id'));
0 ignored issues
show
Bug introduced by
The type XoopsModules\Catads\AdsCategory 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...
77
                $catBuffer[$oneads->getVar('cat_id')] = $tmpcat->title();
78
                $catTitle                             = $tmpcat->title();
0 ignored issues
show
Unused Code introduced by
The assignment to $catTitle is dead and can be removed.
Loading history...
79
            } else {
80
                $catTitle = $catBuffer[$oneads->getVar('cat_id')];
81
            }
82
            $block[] = [
83
                'date'     => formatTimestamp($oneads->getVar('published'), $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

83
                'date'     => /** @scrutinizer ignore-call */ formatTimestamp($oneads->getVar('published'), $dateFormat),
Loading history...
84
                'category' => '',
85
                'author'   => \XoopsUser::getUnameFromId($oneads->getVar('uid')),
0 ignored issues
show
Bug introduced by
The type XoopsUser 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...
86
                'title'    => $title,
87
                'link'     => "<a href='" . XOOPS_URL . '/modules/catads/adsitem.php?ads_id=' . $oneads->getVar('ads_id') . "'>" . $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...
88
            ];
89
            unset($itemArray);
90
        }
91
    }
92
93
    return $block;
94
}
95