b_marquee_wfdownloads()   A
last analyzed

Complexity

Conditions 5
Paths 10

Size

Total Lines 46
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 36
c 1
b 0
f 0
nc 10
nop 3
dl 0
loc 46
rs 9.0328
1
<?php declare(strict_types=1);
2
3
/**
4
 * ****************************************************************************
5
 * marquee - MODULE FOR XOOPS
6
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright         Hervé Thouzard (https://www.herve-thouzard.com)
16
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @author            Hervé Thouzard (https://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\Wfdownloads;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wfdownloads 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 files from the wfdownloads module (tested with wfdownloads 3.1)
32
/**
33
 * @param $limit
34
 * @param $dateFormat
35
 * @param $itemsSize
36
 * @return array
37
 */
38
function b_marquee_wfdownloads($limit, $dateFormat, $itemsSize)
0 ignored issues
show
Unused Code introduced by
The parameter $dateFormat is not used and could be removed. ( Ignorable by Annotation )

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

38
function b_marquee_wfdownloads($limit, /** @scrutinizer ignore-unused */ $dateFormat, $itemsSize)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
{
40
    $block = [];
41
    global $xoopsUser;
42
    /** @var \XoopsModuleHandler $moduleHandler */
43
    $moduleHandler = xoops_getHandler('module');
44
    $wfModule      = $moduleHandler->getByDirname('wfdownloads');
45
    /** @var \XoopsConfigHandler $configHandler */
46
    $configHandler  = xoops_getHandler('config');
47
    $wfModuleConfig = $configHandler->getConfigsByCat(0, $wfModule->getVar('mid'));
48
    $groups         = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
49
    /** @var \XoopsGroupPermHandler $grouppermHandler */
50
    $grouppermHandler = xoops_getHandler('groupperm');
51
    $allowed_cats     = $grouppermHandler->getItemIds('WFDownCatPerm', $groups, $wfModule->getVar('mid'));
52
    $criteria         = new \Criteria('cid', '(' . implode(',', $allowed_cats) . ')', 'IN');
0 ignored issues
show
Unused Code introduced by
The assignment to $criteria is dead and can be removed.
Loading history...
53
    $criteria         = new \CriteriaCompo(new \Criteria('offline', 0));
54
    $criteria->setSort('published');
55
    $criteria->setOrder('DESC');
56
    $criteria->setLimit($limit);
57
    $downloadHandler = Wfdownloads\Helper::getInstance()->getHandler('Download');
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wfdownloads\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...
58
    $categoryHandler = Wfdownloads\Helper::getInstance()->getHandler('Category');
59
    $buffer_category = [];
60
    $downloads       = $downloadHandler->getObjects($criteria);
61
    foreach (array_keys($downloads) as $i) {
62
        $download = $downloads[$i]->toArray();
63
        if ($itemsSize > 0) {
64
            $title = xoops_substr($download['title'], 0, $itemsSize);
65
        } else {
66
            $title = $download['title'];
67
        }
68
        if (isset($buffer_category[$download['cid']])) {
69
            $categtitle = $buffer_category[$download['cid']];
70
        } else {
71
            $category   = $categoryHandler->get($download['cid']);
72
            $categtitle = $buffer_category[$download['cid']] = $category->getVar('title');
73
        }
74
        $block[] = [
75
            'date'     => formatTimestamp($download['published'], $wfModuleConfig['dateformat']),
76
            'category' => $categtitle,
77
            'author'   => $download['publisher'],
78
            'title'    => $title,
79
            'link'     => "<a href='" . XOOPS_URL . '/modules/wfdownloads/singlefile.php?cid=' . $download['cid'] . '&lid=' . $download['lid'] . "'>" . $title . '</a>',
80
        ];
81
    }
82
83
    return $block;
84
}
85