ODMLuceneQuery::execute()   B
last analyzed

Complexity

Conditions 8
Paths 3

Size

Total Lines 26

Duplication

Lines 5
Ratio 19.23 %

Importance

Changes 0
Metric Value
dl 5
loc 26
rs 8.4444
c 0
b 0
f 0
cc 8
nc 3
nop 0
1
<?php
2
3
4
namespace Doctrine\ODM\CouchDB\View;
5
6
use Doctrine\CouchDB\View\LuceneQuery;
7
use Doctrine\ODM\CouchDB\DocumentManager;
8
9
class ODMLuceneQuery extends LuceneQuery
10
{
11
    /**
12
     * @var DocumentManager
13
     */
14
    private $dm;
15
16
    /**
17
     * @var bool
18
     */
19
    private $onlyDocs = false;
20
21
    private $documentName;
22
23
    public function getDocumentName()
24
    {
25
        return $this->documentName;
26
    }
27
28
    public function setDocumentName($documentName)
29
    {
30
        $this->documentName = $documentName;
31
        return $this;
32
    }
33
34
    public function execute()
35
    {
36
        $response = $this->doExecute();
37
        if ($this->dm && $this->getParameter('include_docs') === true) {
38
            $uow = $this->dm->getUnitOfWork();
0 ignored issues
show
Unused Code introduced by
$uow 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...
39
            foreach ($response->body['rows'] AS $k => $v) {
40
                if (!isset($v['type']) && !$this->documentName) {
41
                    throw new \InvalidArgumentException(
42
                        "Cannot query " . $this->getHttpQuery() . " lucene and convert to document instances, ".
43
                        "the type of document " . $v['id'] . " is not stored in Lucene. You can query without " .
44
                        "include_docs and pass the ids to findMany() of the repository you know this document is " .
45
                        "a type of.");
46
                }
47
                $v['type'] = isset($v['type']) ? $v['type'] : $this->documentName;
48
49
                $doc = $this->dm->find(str_replace(".", "\\", $v['type']), $v['id']);
50 View Code Duplication
                if ($this->onlyDocs) {
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...
51
                    $response->body['rows'][$k] = $doc;
52
                } else {
53
                    $response->body['rows'][$k]['doc'] = $doc;
54
                }
55
            }
56
        }
57
58
        return $this->createResult($response);
59
    }
60
61
62
    /**
63
     * @param DocumentManager $dm
64
     */
65
    public function setDocumentManager(DocumentManager $dm)
66
    {
67
        $this->dm = $dm;
68
    }
69
70
    /**
71
     * @param  bool $flag
72
     * @return LuceneQuery
73
     */
74
    public function onlyDocs($flag)
75
    {
76
        $this->setIncludeDocs(true);
77
        $this->onlyDocs = $flag;
78
        return $this;
79
    }
80
}
81