FullText   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 56.36 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 31
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A accept() 0 4 1
A handle() 31 38 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler;
4
5
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
6
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriteriaConverter;
7
use Kaliop\EzFindSearchEngineBundle\Core\Persistence\eZFind\Content\Search\Common\Gateway\CriterionHandler;
8
9
class FullText extends CriterionHandler
10
{
11
    /**
12
     * @inheritdoc
13
     */
14
    public function accept(Criterion $criterion)
15
    {
16
        return $criterion instanceof Criterion\FullText;
17
    }
18
19
    /**
20
     * If the FullText search contain wildcard search, build correct wildcard query
21
     * with non-truncated words boosted.
22
     *
23
     * @inheritdoc
24
     */
25
    public function handle(CriteriaConverter $converter, Criterion $criterion)
26
    {
27
        $value = trim($criterion->value);
28
29 View Code Duplication
        if ($value == '*') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
            // Pure wildcard query
31
            return 'ezf_df_text:*';
32
33
        } else if (preg_match('/^".+"$/', $value)) {
34
            // Quoted-string query: escape everything but the outher quotes
35
            $value = '"' . $this->escapeValue(substr($value, 1, -1)) . '"';
36
37
        } else if (preg_match('/(^\*|\*$)/', $value)) {
38
            // Wildcard query: make the exact match stronger than the wildcard
39
40
            // @bug we do not support wildcard chars in the middle of phrases
41
42
            $value = $this->escapeValue($value);
43
44
            // Escape spaces
45
            $value = str_replace(' ', '\\ ', $value);
46
47
            // wildcard match: un-escape wildcard char
48
            $wildcard = str_replace('\\*', '*', $value);
49
50
            // Non-wildcard match
51
            $value = trim($value, '*');
52
            $value = rtrim($value, '\\');
53
54
            $value = $value . '^2 OR ' . $wildcard;
55
56
        } else {
57
            // plain query
58
            $value = $this->escapeValue($value);
59
        }
60
61
        return 'ezf_df_text:(' . $value . ')';
62
    }
63
}
64