b_marquee_smartfaq()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 50
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 34
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 50
rs 8.7537
1
<?php declare(strict_types=1);
2
3
use XoopsModules\Smartfaq\Helper;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Smartfaq\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...
4
5
/**
6
 * ****************************************************************************
7
 * marquee - MODULE FOR XOOPS
8
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
9
 *
10
 * You may not change or alter any portion of this comment or credits
11
 * of supporting developers from this source code or any supporting source code
12
 * which is considered copyrighted (c) material of the original comment or credit authors.
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 * @copyright         Hervé Thouzard (https://www.herve-thouzard.com)
18
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author            Hervé Thouzard (https://www.herve-thouzard.com)
20
 *
21
 * Version :
22
 * ****************************************************************************
23
 *
24
 * @param $limit
25
 * @param $dateFormat
26
 * @param $itemsSize
27
 *
28
 * @return array
29
 */
30
31
// Script to list recent FAQ from the smartfaq module (tested with smartfaq 1.04)
32
function b_marquee_smartfaq($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

32
function b_marquee_smartfaq($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...
33
{
34
    require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
35
    $block             = [];
36
    $smartModule       = &sf_getModuleInfo();
0 ignored issues
show
Unused Code introduced by
The assignment to $smartModule is dead and can be removed.
Loading history...
Bug introduced by
The function sf_getModuleInfo 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

36
    $smartModule       = &/** @scrutinizer ignore-call */ sf_getModuleInfo();
Loading history...
37
    $smartModuleConfig = &sf_getModuleConfig();
0 ignored issues
show
Bug introduced by
The function sf_getModuleConfig 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

37
    $smartModuleConfig = &/** @scrutinizer ignore-call */ sf_getModuleConfig();
Loading history...
38
    $categoryid        = -1;
39
    $sort              = 'datesub';
40
    $maxQuestionLength = 99999;
41
    if ($itemsSize > 0) {
42
        $maxQuestionLength = $itemsSize;
43
    }
44
    // Creating the faq handler object
45
    /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
46
    $faqHandler = Helper::getInstance()->getHandler('Faq');
47
    // Creating the category handler object
48
    /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
49
    $categoryHandler = Helper::getInstance()->getHandler('Category');
50
    // Creating the last FAQs
51
    $faqsObj       = $faqHandler->getAllPublished($limit, 0, $categoryid, $sort);
52
    $allcategories = $categoryHandler->getObjects(null, true);
53
    if ($faqsObj) {
54
        $userids = $faqids = [];
55
        foreach ($faqsObj as $key => $thisfaq) {
56
            $faqids[]                 = $thisfaq->getVar('faqid');
57
            $userids[$thisfaq->uid()] = 1;
58
        }
59
        /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
60
        $answerHandler = Helper::getInstance()->getHandler('Answer');
61
        $allanswers    = $answerHandler->getLastPublishedByFaq($faqids);
62
        foreach ($allanswers as $key => $thisanswer) {
63
            $userids[$thisanswer->uid()] = 1;
64
        }
65
        /** @var \XoopsMemberHandler $memberHandler */
66
        $memberHandler = xoops_getHandler('member');
67
        $users         = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true);
68
        for ($i = 0, $iMax = count($faqsObj); $i < $iMax; ++$i) {
69
            $answerObj = $allanswers[$faqsObj[$i]->faqid()];
70
            $title     = $faqsObj[$i]->question($maxQuestionLength);
71
            $block[]   = [
72
                'date'     => $faqsObj[$i]->datesub(),
73
                'category' => $allcategories[$faqsObj[$i]->categoryid()]->getVar('name'),
74
                'author'   => sf_getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users),
0 ignored issues
show
Bug introduced by
The function sf_getLinkedUnameFromId 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
                'author'   => /** @scrutinizer ignore-call */ sf_getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users),
Loading history...
75
                'title'    => $title,
76
                'link'     => "<a href='" . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $faqsObj[$i]->faqid() . "'>" . $title . '</a>',
77
            ];
78
        }
79
    }
80
81
    return $block;
82
}
83