publisher_items_menu_show()   B
last analyzed

Complexity

Conditions 7
Paths 19

Size

Total Lines 41
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
c 0
b 0
f 0
nc 19
nop 1
dl 0
loc 41
rs 8.8333
1
<?php declare(strict_types=1);
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         https://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @since           1.0
16
 * @author          trabis <[email protected]>
17
 * @author          The SmartFactory <www.smartfactory.ca>
18
 */
19
20
use Xmf\Request;
1 ignored issue
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use XoopsModules\Publisher\BlockForm;
22
use XoopsModules\Publisher\CategoryHandler;
23
use XoopsModules\Publisher\Helper;
24
use XoopsModules\Publisher\Utility;
25
26
require_once \dirname(__DIR__) . '/include/common.php';
27
28
/**
29
 * @param $options
30
 *
31
 * @return array
32
 */
33
function publisher_items_menu_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

33
function publisher_items_menu_show(/** @scrutinizer ignore-unused */ $options)

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...
34
{
35
    $block = [];
36
37
    $helper = Helper::getInstance();
38
39
    // Getting all top cats
40
    /** @var CategoryHandler $categoryHandler */
41
    $categoryHandler    = $helper->getHandler('Category');
42
    $blockCategoriesObj = $categoryHandler->getCategories(0, 0, 0);
43
44
    if (0 == count($blockCategoriesObj)) {
45
        return $block;
46
    }
47
48
    // Are we in Publisher ?
49
    $block['inModule'] = (isset($GLOBALS['xoopsModule']) && $GLOBALS['xoopsModule']->getVar('dirname') == $helper->getDirname());
50
51
    $catLinkClass = 'menuMain';
52
53
    $categoryid = 0;
54
55
    if ($block['inModule']) {
56
        // Are we in a category and if yes, in which one ?
57
        $categoryid = Request::getInt('categoryid', 0, 'GET');
58
59
        if (0 != $categoryid) {
60
            // if we are in a category, then the $categoryObj is already defined in publisher/category.php
61
            global $categoryObj;
62
            $block['currentcat'] = $categoryObj->getCategoryLink('menuTop');
63
            $catLinkClass        = 'menuSub';
64
        }
65
    }
66
67
    foreach ($blockCategoriesObj as $catId => $blockCategoryObj) {
68
        if ($catId != $categoryid) {
69
            $block['categories'][$catId]['categoryLink'] = $blockCategoryObj->getCategoryLink($catLinkClass);
70
        }
71
    }
72
73
    return $block;
74
}
75
76
/**
77
 * @param $options
78
 *
79
 * @return string
80
 */
81
function publisher_items_menu_edit($options)
82
{
83
    // require_once PUBLISHER_ROOT_PATH . '/class/blockform.php';
84
    xoops_load('XoopsFormLoader');
85
86
    $form = new BlockForm();
87
88
    $catEle   = new \XoopsFormLabel(_MB_PUBLISHER_SELECTCAT, Utility::createCategorySelect($options[0], 0, true, 'options[0]'));
89
    $orderEle = new \XoopsFormSelect(_MB_PUBLISHER_ORDER, 'options[1]', $options[1]);
90
    $orderEle->addOptionArray(
91
        [
92
            'datesub' => _MB_PUBLISHER_DATE,
93
            'counter' => _MB_PUBLISHER_HITS,
94
            'weight'  => _MB_PUBLISHER_WEIGHT,
95
        ]
96
    );
97
    $dispEle = new \XoopsFormText(_MB_PUBLISHER_DISP, 'options[2]', 10, 255, $options[2]);
98
99
    $form->addElement($catEle);
100
    $form->addElement($orderEle);
101
    $form->addElement($dispEle);
102
103
    return $form->render();
104
}
105