SearchResult::setStorage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: jensk
4
 * Date: 3-3-2017
5
 * Time: 16:56
6
 */
7
8
namespace CloudControl\Cms\search\results;
9
10
11
use CloudControl\Cms\storage\entities\Document;
12
use CloudControl\Cms\storage\Storage;
13
14
class SearchResult
15
{
16
    /**
17
     * @var string
18
     */
19
    public $documentPath;
20
    /**
21
     * @var array
22
     */
23
    public $matchingTokens;
24
    /**
25
     * @var float
26
     */
27
    public $score;
28
29
    protected $document;
30
    /**
31
     * @var Storage
32
     */
33
    protected $storage;
34
35
    /**
36
     * @return Document
37
     * @throws \Exception
38
     */
39
    public function getDocument()
40
    {
41
        if ($this->document instanceof Document) {
42
            return $this->document;
43
        } else {
44
            $this->document = $this->storage->getDocuments()->getDocumentBySlug(substr($this->documentPath, 1));
45
            if ($this->document !== false) {
0 ignored issues
show
introduced by
The condition $this->document !== false is always true.
Loading history...
46
                $this->document->dbHandle = $this->storage->getContentDbHandle();
47
                $this->document->documentStorage = $this->storage->getDocuments();
48
            }
49
50
            return $this->document;
51
        }
52
    }
53
54
    public function setStorage($storage)
55
    {
56
        $this->storage = $storage;
57
    }
58
}