Passed
Push — master ( 296641...7ec8c6 )
by Goffy
04:56
created

wggithub_search()   C

Complexity

Conditions 12
Paths 192

Size

Total Lines 58
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 12
eloc 41
c 1
b 0
f 1
nc 192
nop 5
dl 0
loc 58
rs 6.2

How to fix   Long Method    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
 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
 * wgGitHub module for xoops
14
 *
15
 * @copyright      2020 XOOPS Project (https://xooops.org)
16
 * @license        GPL 2.0 or later
17
 * @package        wggithub
18
 * @since          1.0
19
 * @min_xoops      2.5.10
20
 * @author         Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
21
 */
22
23
use XoopsModules\Wggithub;
24
25
26
/**
27
 * search callback functions
28
 *
29
 * @param $queryarray
30
 * @param $andor
31
 * @param $limit
32
 * @param $offset
33
 * @param $userid
34
 * @return mixed $itemIds
35
 */
36
function wggithub_search($queryarray, $andor, $limit, $offset, $userid)
0 ignored issues
show
Unused Code introduced by
The parameter $andor 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

36
function wggithub_search($queryarray, /** @scrutinizer ignore-unused */ $andor, $limit, $offset, $userid)

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...
37
{
38
    $ret = [];
39
    $helper = \XoopsModules\Wggithub\Helper::getInstance();
40
    $repositoriesHandler = $helper->getHandler('Repositories');
41
    $directoriesHandler  = $helper->getHandler('Directories');
42
43
    $directoriesAll = $directoriesHandler->getAll();
44
    foreach (\array_keys($directoriesAll) as $i) {
45
        $directories[$directoriesAll[$i]->getVar('dir_name')] = $directoriesAll[$i]->getVar('dir_id');
46
    }
47
    unset ($directoriesAll);
48
49
    // search in table repositories
50
    // search keywords
51
    $elementCount = 0;
52
    if (\is_array($queryarray)) {
53
        $elementCount = \count($queryarray);
54
    }
55
    if ($elementCount > 0) {
56
        $crKeywords = new \CriteriaCompo();
0 ignored issues
show
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...
57
        for ($i = 0; $i  <  $elementCount; $i++) {
58
            $crKeyword = new \CriteriaCompo();
59
            unset($crKeyword);
60
        }
61
    }
62
    // search user(s)
63
    if ($userid && \is_array($userid)) {
64
        $userid = array_map('intval', $userid);
65
        $crUser = new \CriteriaCompo();
66
        $crUser->add(new \Criteria('repo_submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR');
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...
67
    } elseif (is_numeric($userid) && $userid > 0) {
68
        $crUser = new \CriteriaCompo();
69
        $crUser->add(new \Criteria('repo_submitter', $userid), 'OR');
70
    }
71
    $crSearch = new \CriteriaCompo();
72
    if (isset($crKeywords)) {
73
        $crSearch->add($crKeywords, 'AND');
74
    }
75
    if (isset($crUser)) {
76
        $crSearch->add($crUser, 'AND');
77
    }
78
    $crSearch->setStart($offset);
79
    $crSearch->setLimit($limit);
80
    $crSearch->setSort('repo_datecreated');
81
    $crSearch->setOrder('DESC');
82
    $repositoriesAll = $repositoriesHandler->getAll($crSearch);
83
    foreach (\array_keys($repositoriesAll) as $i) {
84
        $ret[] = [
85
            'image'  => 'assets/icons/16/github.png',
86
            'link'   => 'index.php?op=show&amp;menu=' . $directories[$repositoriesAll[$i]->getVar('repo_user')],
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $directories seems to be defined by a foreach iteration on line 44. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
87
            'title'  => $repositoriesAll[$i]->getVar('repo_name'),
88
            'time'   => $repositoriesAll[$i]->getVar('repo_datecreated')
89
        ];
90
    }
91
    unset($crKeywords, $crKeyword, $crUser, $crSearch, $repositoriesAll);
92
93
    return $ret;
94
95
}
96