Completed
Push — master ( e24a08...649c71 )
by Joshua
9s
created

PropertiesTrait::getAutocompleteAttributes()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.2
cc 4
eloc 10
nc 4
nop 0
1
<?php
2
3
namespace As3\Modlr\Metadata\Traits;
4
5
use As3\Modlr\Metadata\FieldMetadata;
6
7
/**
8
 * Common property metadata get methods.
9
 *
10
 * @author Jacob Bare <[email protected]>
11
 */
12
trait PropertiesTrait
13
{
14
    /**
15
     * Gets merged properties that this object contains.
16
     * Is a combination of attributes, relationships, and/or embeds, depending what the object supports.
17
     *
18
     * @return  FieldMetadata[]
19
     */
20
    abstract public function getProperties();
21
22
    /**
23
     * Determines whether search is enabled.
24
     *
25
     * @return  bool
26
     */
27
    public function isSearchEnabled()
28
    {
29
        $propertes = $this->getSearchProperties();
30
        return !empty($propertes);
31
    }
32
33
    /**
34
     * Gets all properties that are flagged for storage in search.
35
     *
36
     * @return  FieldMetadata[]
37
     */
38
    public function getSearchProperties()
39
    {
40
        static $props;
41
        if (null !== $props) {
42
            return $props;
43
        }
44
45
        $props = [];
46
        foreach ($this->getProperties() as $key => $property) {
47
            if (false === $property->isSearchProperty()) {
48
                continue;
49
            }
50
            $props[$key] = $property;
51
        }
52
        return $props;
53
    }
54
55
    /**
56
     * Determines if a property (attribute or relationship) is indexed for search.
57
     *
58
     * @param   string  $key    The property key.
59
     * @return  bool
60
     */
61
    public function propertySupportsSearch($key)
62
    {
63
        return isset($this->getSearchProperties()[$key]);
64
    }
65
}
66