wggithub_search()   F
last analyzed

Complexity

Conditions 13
Paths 384

Size

Total Lines 62
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 13
eloc 44
c 1
b 0
f 1
nc 384
nop 5
dl 0
loc 62
rs 3.4833

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
use XoopsModules\Wggithub\ {
25
    Helper,
26
    Constants
27
};
28
29
30
/**
31
 * search callback functions
32
 *
33
 * @param $queryarray
34
 * @param $andor
35
 * @param $limit
36
 * @param $offset
37
 * @param $userid
38
 * @return mixed $itemIds
39
 */
40
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

40
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...
41
{
42
    $ret = [];
43
    $helper = Helper::getInstance();
44
    $repositoriesHandler = $helper->getHandler('Repositories');
45
    $directoriesHandler  = $helper->getHandler('Directories');
46
47
    // search in table wggithub_repositories
48
    $directories = [];
49
    $directoriesAll = $directoriesHandler->getAll();
50
    foreach (\array_keys($directoriesAll) as $i) {
51
        $directories[$directoriesAll[$i]->getVar('dir_name')] = $directoriesAll[$i]->getVar('dir_id');
52
    }
53
    unset ($directoriesAll);
54
55
    // search keywords
56
    $elementCount = 0;
57
    if (\is_array($queryarray)) {
58
        $elementCount = \count($queryarray);
59
    }
60
    if ($elementCount > 0) {
61
        $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...
62
        for ($i = 0; $i  <  $elementCount; $i++) {
63
            $crKeywords->add(new \Criteria('repo_name', '%' . $queryarray[$i] . '%', 'LIKE'), '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...
64
        }
65
    }
66
    // search user(s)
67
    if ($userid && \is_array($userid)) {
68
        $userid = array_map('intval', $userid);
69
        $crUser = new \CriteriaCompo();
70
        $crUser->add(new \Criteria('repo_submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR');
71
    } elseif (is_numeric($userid) && $userid > 0) {
72
        $crUser = new \CriteriaCompo();
73
        $crUser->add(new \Criteria('repo_submitter', $userid), 'OR');
74
    }
75
    $crSearch = new \CriteriaCompo();
76
    if (isset($crKeywords)) {
77
        $crSearch->add($crKeywords, 'AND');
78
    }
79
    if (isset($crUser)) {
80
        $crSearch->add($crUser, 'AND');
81
    }
82
    if (0 === (int)$helper->getConfig('autoapproved')) {
83
        $crSearch->add(new \Criteria('repo_approved', 1));
84
    }
85
    $crSearch->add(new \Criteria('repo_status', Constants::STATUS_UPTODATE));
86
    $crSearch->setStart($offset);
87
    $crSearch->setLimit($limit);
88
    $crSearch->setSort('repo_datecreated');
89
    $crSearch->setOrder('DESC');
90
    $repositoriesAll = $repositoriesHandler->getAll($crSearch);
91
    foreach (\array_keys($repositoriesAll) as $i) {
92
        $ret[] = [
93
            'image'  => 'assets/icons/16/github.png',
94
            'link'   => 'index.php?op=show&amp;dir_id=' . $directories[$repositoriesAll[$i]->getVar('repo_user')] . '&amp;repo_id=' . $i,
95
            'title'  => $repositoriesAll[$i]->getVar('repo_name') . ' (' . $repositoriesAll[$i]->getVar('repo_user') . ')',
96
            'time'   => $repositoriesAll[$i]->getVar('repo_datecreated')
97
        ];
98
    }
99
    unset($crKeywords, $crUser, $crSearch, $repositoriesAll);
100
101
    return $ret;
102
103
}
104