Passed
Pull Request — master (#9)
by Michael
03:24
created

CategoryHandler::getCatTitles()   B

Complexity

Conditions 10
Paths 12

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 22
rs 7.6666
c 1
b 0
f 0
cc 10
nc 12
nop 1

How to fix   Complexity   

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
namespace XoopsModules\Mylinks;
4
5
/**
6
 * MyLinks category.php
7
 *
8
 * Xoops mylinks - a multicategory links module
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 ::  &copy; ZySpec Incorporated
18
 * @license   ::    {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
19
 * @package   ::    mylinks
20
 * @subpackage:: class
21
 * @since     ::      File available since version 3.11
22
 * @author    ::     zyspec ([email protected])
23
 */
24
25
26
27
$mylinksDir = basename(dirname(__DIR__));
28
29
/**
30
 * Class mylinksCategoryHandler_base
31
 */
32
class CategoryHandler extends \XoopsPersistableObjectHandler
33
{
34
    /**
35
     * @param \XoopsDatabase|null $db
36
     */
37
    public function mylinksCategoryHandler(\XoopsDatabase $db = null)
38
    {
39
        $this->__construct($db);
40
    }
41
42
    /**
43
     * mylinksCategoryHandler_base constructor.
44
     * @param \XoopsDatabase|null $db
45
     */
46
    public function __construct(\XoopsDatabase $db = null)
47
    {
48
        $mylinksDir = basename(dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $mylinksDir is dead and can be removed.
Loading history...
49
        parent::__construct($db, 'mylinks_cat', Category::class, 'cid');
50
    }
51
52
    /**
53
     * Retrieve category names from Database
54
     * @param unknown $cats  - integer, returns single category name,
0 ignored issues
show
Bug introduced by
The type XoopsModules\Mylinks\unknown 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
     *                       array returns array of category names
56
     *                       NULL return all category names
57
     * @return array   return category titles with category ID as key
58
     */
59
    public function getCatTitles($cats = null)
60
    {
61
        $catTitles = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $catTitles is dead and can be removed.
Loading history...
62
        $criteria  = new \CriteriaCompo();
63
        if (isset($cats) && is_array($cats)) {
0 ignored issues
show
introduced by
The condition is_array($cats) is always false.
Loading history...
64
            $catIdString = !empty($cats) ? '(' . implode(',', $cats) . ')' : '';
65
            if ($catIdString) {
66
                $criteria->add(new \Criteria('cid', $catIdString, 'IN'));
67
            }
68
        } elseif (isset($cats) && ((int)$cats > 0)) {
69
            $criteria->add(new \Criteria('cid', (int)$cats, '='));
70
        }
71
        $catFields     = ['title'];
72
        $categoryArray = $this->getAll($criteria, $catFields, false);
73
        $catTitles     = [];
74
        if (is_array($categoryArray) && count($categoryArray)) {
75
            foreach ($categoryArray as $catItem) {
76
                $catTitles[$catItem['cid']] = $catItem['title'];
77
            }
78
        }
79
80
        return $catTitles;
81
    }
82
}
83
84
//eval('class ' . $mylinksDir . 'Category extends CategoryBase
85
//        {
86
//        }
87
//
88
//        class ' . $mylinksDir . 'CategoryHandler extends mylinksCategoryHandler_base
89
//        {
90
//        }
91
//    ');
92