ItemAbstract::toLineString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of gpupo/search
5
 *
6
 * (c) Gilmar Pupo <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gpupo\Search\Result;
13
14
use Gpupo\Common\Entity\CollectionAbstract;
15
16
abstract class ItemAbstract extends CollectionAbstract
17
{
18
    /**
19
     * Acesso aos atributos fornecidos pelo SphinxSearch.
20
     *
21
     * @return array
22
     */
23
    protected function getAtributos()
24
    {
25
        return $this->get('attrs');
26
    }
27
28
    /**
29
     * Acesso a um atributo específico.
30
     *
31
     * @param string $key
32
     */
33
    protected function getAtributo($key)
34
    {
35
        $attrs = $this->get('attrs');
36
37
        if (isset($attrs[$key])) {
38
            return $attrs[$key];
39
        }
40
41
        return;
42
    }
43
44
    protected function toLineString($chave)
45
    {
46
        $method = 'get'.ucfirst($chave);
47
48
        $string = ' - '.$chave.':'.$this->$method();
49
        $string .= "\n";
50
51
        return $string;
52
    }
53
54
    /**
55
     * @param string $key
56
     */
57
    public function find($key)
58
    {
59
        if ($attr = $this->getAtributo($key)) {
60
            return $attr;
61
        }
62
63
        return $this->get($key);
64
    }
65
}
66