Passed
Branch master (8cb5b2)
by Christopher
04:33 queued 12s
created

AbstractQuery::toDsl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
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\BoolQuery;
6
use ONGR\ElasticsearchDSL\Search;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Triadev\Leopard\Business\Dsl\Search. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Triadev\Leopard\Busines\Dsl\Query\Specialized;
8
use Triadev\Leopard\Business\Dsl\Query\TermLevel;
9
use Triadev\Leopard\Business\Dsl\Query\Fulltext;
10
use Triadev\Leopard\Business\Dsl\Query\Geo;
11
use Triadev\Leopard\Business\Dsl\Query\Joining;
12
use Triadev\Leopard\Business\Dsl\Query\InnerHit;
13
14
abstract class AbstractQuery
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
15
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AbstractQuery
Loading history...
16
    /** @var \ONGR\ElasticsearchDSL\Search */
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...
17
    public $search;
1 ignored issue
show
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
18
    
19
    /** @var string */
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...
20
    public $boolState = BoolQuery::MUST;
21
    
22
    /**
23
     * BoolQuery constructor.
24
     * @param Search|null $search
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...
25
     */
26 35
    public function __construct(?Search $search = null)
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 "$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...
27
    {
28 35
        $this->search = $search ?: new Search();
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
29 35
    }
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...
30
    
31
    /**
32
     * To dsl
33
     *
34
     * @return array
35
     */
36 32
    public function toDsl() : array
37
    {
38 32
        return $this->search->toArray();
39
    }
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 toDsl()
Loading history...
40
    
41
    /**
42
     * Get search
43
     *
44
     * @return Search
45
     */
46 4
    public function getSearch() : Search
47
    {
48 4
        return $this->search;
49
    }
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 getSearch()
Loading history...
50
    
51
    /**
52
     * Get query
53
     *
54
     * @return BuilderInterface
55
     */
56 11
    public function getQuery() : BuilderInterface
57
    {
58 11
        return $this->search->getQueries();
59
    }
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...
60
    
61
    /**
62
     * Append
63
     *
64
     * @param BuilderInterface $query
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
     * @return AbstractQuery|TermLevel|Fulltext|Geo|\Triadev\Leopard\Business\Dsl\Search|Joining|Specialized|InnerHit
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
66
     */
67 31
    public function append(BuilderInterface $query) : AbstractQuery
68
    {
69 31
        $this->search->addQuery($query, $this->boolState);
70 31
        return $this;
71
    }
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 append()
Loading history...
72
    
73
    /**
74
     * Bool state: must
75
     *
76
     * @return AbstractQuery|TermLevel|Fulltext|Geo|\Triadev\Leopard\Business\Dsl\Search|Joining|Specialized|InnerHit
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
77
     */
78 3
    public function must(): AbstractQuery
79
    {
80 3
        $this->boolState = BoolQuery::MUST;
81 3
        return $this;
82
    }
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 must()
Loading history...
83
    
84
    /**
85
     * Bool state: must not
86
     *
87
     * @return AbstractQuery|TermLevel|Fulltext|Geo|\Triadev\Leopard\Business\Dsl\Search|Joining|Specialized|InnerHit
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
88
     */
89 1
    public function mustNot(): AbstractQuery
90
    {
91 1
        $this->boolState = BoolQuery::MUST_NOT;
92 1
        return $this;
93
    }
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 mustNot()
Loading history...
94
    
95
    /**
96
     * Bool state: should
97
     *
98
     * @return AbstractQuery|TermLevel|Fulltext|Geo|\Triadev\Leopard\Business\Dsl\Search|Joining|Specialized|InnerHit
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
99
     */
100 1
    public function should(): AbstractQuery
101
    {
102 1
        $this->boolState = BoolQuery::SHOULD;
103 1
        return $this;
104
    }
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 should()
Loading history...
105
    
106
    /**
107
     * Bool state: filter
108
     *
109
     * @return AbstractQuery|TermLevel|Fulltext|Geo|\Triadev\Leopard\Business\Dsl\Search|Joining|Specialized|InnerHit
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
110
     */
111 7
    public function filter(): AbstractQuery
112
    {
113 7
        $this->boolState = BoolQuery::FILTER;
114 7
        return $this;
115
    }
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 filter()
Loading history...
116
}
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...
117