GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 81a8a0...75582b )
by Vincent
11:02 queued 02:43
created

ACF::advanced_custom_search()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 68
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 9
nop 2
dl 0
loc 68
rs 6.9654
c 0
b 0
f 0

How to fix   Long Method   

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 96.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Undefined\Stash\ACF;
4
5
/**
6
 * Get paths for assets
7
 */
8
class ACF
9
{
10
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
    {
12
        $this->list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
0 ignored issues
show
Bug introduced by
The property list_searcheable_acf does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
14
        if (!class_exists('acf')) {
15
            add_filter('posts_search', [$this, 'advanced_custom_search'], 500, 2);
16
        }
17
    }
18
19
    /**
20
     * Make ACF fields searchable
21
     *
22
     * @param $where
23
     * @param $wp_query
24
     * @return string
25
     */
26
    public function advanced_custom_search($where, &$wp_query)
27
    {
28
        global $wpdb;
29
30
        if (empty($where)) {
31
            return $where;
32
        }
33
34
        // get search expression
35
        $terms = $wp_query->query_vars['s'];
36
37
        // explode search expression to get search terms
38
        $exploded = explode(' ', $terms);
39
40
        if ($exploded === false || count($exploded) == 0) {
41
            $exploded = array(0 => $terms);
42
        }
43
44
        // reset search in order to rebuilt it as we whish
45
        $where = '';
46
47
        // get searcheable_acf, a list of advanced custom fields you want to search content in
48
        $list_searcheable_acf = $this->list_searcheable_acf;
49
50
        foreach ($exploded as $tag) {
51
            $where .= "
52
          AND (
53
            (wp_posts.post_title LIKE '%$tag%')
54
            OR (wp_posts.post_content LIKE '%$tag%')
55
            OR EXISTS (
56
              SELECT * FROM wp_postmeta
57
	              WHERE post_id = wp_posts.ID
58
	                AND (";
59
60
            foreach ($list_searcheable_acf as $searcheable_acf) {
61
                if ($searcheable_acf == $list_searcheable_acf[0]) {
62
                    $where .= " (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') ";
63
                } else {
64
                    $where .= " OR (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') ";
65
                }
66
67
                $where .= ")
68
            )
69
            OR EXISTS (
70
              SELECT * FROM wp_comments
71
              WHERE comment_post_ID = wp_posts.ID
72
                AND comment_content LIKE '%$tag%'
73
            )
74
            OR EXISTS (
75
              SELECT * FROM wp_terms
76
              INNER JOIN wp_term_taxonomy
77
                ON wp_term_taxonomy.term_id = wp_terms.term_id
78
              INNER JOIN wp_term_relationships
79
                ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
80
              WHERE (
81
          		taxonomy = 'post_tag'
82
            		OR taxonomy = 'category'
83
            		OR taxonomy = 'myCustomTax'
84
          		)
85
              	AND object_id = wp_posts.ID
86
              	AND wp_terms.name LIKE '%$tag%'
87
            )
88
        )";
89
            }
90
91
            return $where;
92
        }
93
    }
94
}
95
96
add_action('init', function () {
97
    $acf = new ACF();
0 ignored issues
show
Unused Code introduced by
$acf is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
98
});