Cancelled
Branch master (8cb5b2)
by Christopher
04:16
created

FunctionScore   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 162
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A decay() 0 18 1
A weight() 0 4 1
A script() 0 14 1
A __construct() 0 3 1
A getQuery() 0 3 1
A random() 0 4 1
A simple() 0 4 1
A buildQueryFromSearchClosure() 0 12 2
A field() 0 14 1
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
2
namespace Triadev\Leopard\Business\Dsl;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use ONGR\ElasticsearchDSL\BuilderInterface;
5
use ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery;
6
7
class FunctionScore
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
8
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class FunctionScore
Loading history...
9
    /** @var FunctionScoreQuery */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
10
    private $query;
1 ignored issue
show
Coding Style introduced by
Private member variable "query" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "query" must be prefixed with an underscore
Loading history...
11
    
12
    /**
13
     * FunctionScore constructor.
14
     * @param BuilderInterface $query
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
15
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
16
     */
17 6
    public function __construct(BuilderInterface $query, array $params = [])
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$params" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$params"; expected 0 but found 1
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
18
    {
19 6
        $this->query = new FunctionScoreQuery($query, $params);
20 6
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
21
    
22
    /**
23
     * Get query
24
     *
25
     * @return BuilderInterface
26
     */
27 6
    public function getQuery() : BuilderInterface
28
    {
29 6
        return $this->query;
30
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getQuery()
Loading history...
31
    
32
    /**
33
     * Field
34
     *
35
     * @param string $field
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
36
     * @param float $factor
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
37
     * @param string $modifier
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
38
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
39
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
40
     */
41 1
    public function field(
42
        string $field,
43
        float $factor,
44
        string $modifier = 'none',
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$modifier" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$modifier"; expected 0 but found 1
Loading history...
45
        ?\Closure $search = null
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$search" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$search"; expected 0 but found 1
Loading history...
46
    ) : FunctionScore {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
47 1
        $this->query->addFieldValueFactorFunction(
48 1
            $field,
49 1
            $factor,
50 1
            $modifier,
51 1
            $this->buildQueryFromSearchClosure($search)
52
        );
53
        
54 1
        return $this;
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end field()
Loading history...
56
    
57
    /**
58
     * Decay
59
     *
60
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
61
     * @param string $field
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
62
     * @param array $function
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
63
     * @param array $options
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
64
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
65
     * @param int|null $weight
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer|null" but found "int|null" for parameter type
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
66
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
67
     */
68 1
    public function decay(
69
        string $type,
70
        string $field,
71
        array $function,
72
        array $options = [],
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$options" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$options"; expected 0 but found 1
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
73
        ?\Closure $search = null,
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$search" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$search"; expected 0 but found 1
Loading history...
74
        int $weight = null
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$weight" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$weight"; expected 0 but found 1
Loading history...
75
    ) : FunctionScore {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
76 1
        $this->query->addDecayFunction(
77 1
            $type,
78 1
            $field,
79 1
            $function,
80 1
            $options,
81 1
            $this->buildQueryFromSearchClosure($search),
82 1
            $weight
83
        );
84
        
85 1
        return $this;
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end decay()
Loading history...
87
    
88
    /**
89
     * Weight
90
     *
91
     * @param float $weight
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
92
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
93
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
94
     */
95 1
    public function weight(float $weight, ?\Closure $search = null) : FunctionScore
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$search" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$search"; expected 0 but found 1
Loading history...
96
    {
97 1
        $this->query->addWeightFunction($weight, $this->buildQueryFromSearchClosure($search));
98 1
        return $this;
99
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end weight()
Loading history...
100
    
101
    /**
102
     * Random
103
     *
104
     * @param int|null $seed
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer|null" but found "int|null" for parameter type
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
105
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
106
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
107
     */
108 1
    public function random(?int $seed = null, ?\Closure $search = null) : FunctionScore
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$seed" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$seed"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$search" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$search"; expected 0 but found 1
Loading history...
109
    {
110 1
        $this->query->addRandomFunction($seed, $this->buildQueryFromSearchClosure($search));
111 1
        return $this;
112
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end random()
Loading history...
113
    
114
    /**
115
     * Script
116
     *
117
     * @param string $inline
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
118
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
119
     * @param array $options
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
120
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
121
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
122
     */
123 1
    public function script(
124
        string $inline,
125
        array $params = [],
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$params" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$params"; expected 0 but found 1
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
126
        array $options = [],
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$options" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$options"; expected 0 but found 1
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
127
        ?\Closure $search = null
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$search" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$search"; expected 0 but found 1
Loading history...
128
    ) : FunctionScore {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
129 1
        $this->query->addScriptScoreFunction(
130 1
            $inline,
131 1
            $params,
132 1
            $options,
133 1
            $this->buildQueryFromSearchClosure($search)
134
        );
135
        
136 1
        return $this;
137
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end script()
Loading history...
138
    
139
    /**
140
     * Simple
141
     *
142
     * @param array $functions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
143
     * @return FunctionScore
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
144
     */
145 1
    public function simple(array $functions) : FunctionScore
146
    {
147 1
        $this->query->addSimpleFunction($functions);
148 1
        return $this;
149
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end simple()
Loading history...
150
    
151
    /**
152
     * Build query from search closure
153
     *
154
     * @param \Closure|null $search
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
155
     * @return BuilderInterface|null
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
156
     */
157 5
    private function buildQueryFromSearchClosure(?\Closure $search) : ?BuilderInterface
0 ignored issues
show
Coding Style introduced by
Private method name "FunctionScore::buildQueryFromSearchClosure" must be prefixed with an underscore
Loading history...
158
    {
159 5
        $query = null;
160
    
161 5
        if ($search) {
162 3
            $searchBuilder = app()->make(Search::class);
163 3
            $search($searchBuilder);
164
        
165 3
            $query = $searchBuilder->getQuery();
166
        }
167
        
168 5
        return $query;
169
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end buildQueryFromSearchClosure()
Loading history...
170
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
171