Result::getResultsByField()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Query\Suggest\Result;
4
5
use Mdiyakov\DoctrineSolrBundle\Exception\SuggestResultException;
6
7
class Result
8
{
9
    /**
10
     * @var FieldResult[]
11
     */
12
    private $data;
13
14
    /**
15
     * @param FieldResult $fieldResult
16
     */
17
    public function addFieldResult(FieldResult $fieldResult)
18
    {
19
        $this->data[$fieldResult->getEntityFieldName()] = $fieldResult;
20
    }
21
22
    /**
23
     * @param $entityFieldName
24
     * @return FieldResult
25
     * @throws SuggestResultException
26
     */
27
    public function getResultsByField($entityFieldName)
28
    {
29
        if (!array_key_exists($entityFieldName, $this->data)) {
30
            throw new SuggestResultException(
31
                sprintf('There is no result for %s entity field', $entityFieldName)
32
            );
33
        }
34
35
        return $this->data[$entityFieldName];
36
    }
37
}