Passed
Push — develop ( 169afe...f2bd80 )
by Jens
02:39
created

SearchResult::getDocument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 10
rs 9.4285
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 library\search\results;
9
10
11
use library\storage\Document;
12
use library\storage\JsonStorage;
13
use library\storage\Repository;
14
15
class SearchResult
16
{
17
	/**
18
	 * @var string
19
	 */
20
	public $documentPath;
21
	/**
22
	 * @var array
23
	 */
24
	public $matchingTokens;
25
	/**
26
	 * @var float
27
	 */
28
	public $score;
29
30
	protected $document;
31
	/**
32
	 * @var JsonStorage
33
	 */
34
	protected $storage;
35
36
	/**
37
	 * @return Document
38
	 */
39
	public function getDocument()
40
	{
41
		if ($this->document instanceof Document) {
42
			return $this->document;
43
		} else {
44
			$this->document = $this->storage->getDocumentBySlug(substr($this->documentPath, 1));
45
			$this->document->dbHandle = $this->storage->getContentDbHandle();
46
			return $this->document;
47
		}
48
	}
49
50
	public function setStorage($storage)
51
	{
52
		$this->storage = $storage;
53
	}
54
}