AttributeMetadata::hasDefaultValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace As3\Modlr\Metadata;
4
5
/**
6
 * Defines metadata for a "standard" field.
7
 * Should be loaded using the MetadataFactory, not instantiated directly.
8
 *
9
 * @author Jacob Bare <[email protected]>
10
 */
11
class AttributeMetadata extends FieldMetadata
12
{
13
    /**
14
     * The attribute type, such as string, integer, float, etc.
15
     *
16
     * @var string
17
     */
18
    public $dataType;
19
20
    /**
21
     * The attribute's default value, if set.
22
     *
23
     * @var mixed
24
     */
25
    public $defaultValue;
26
27
    /**
28
     * Contains the caculated field parameters.
29
     *
30
     * @var array
31
     */
32
    public $calculated = [
33
        'class'     => null,
34
        'method'    => null,
35
    ];
36
37
    /**
38
     * Whether this attribute is flagged to be stored as an autocomplete field in search.
39
     *
40
     * @var bool
41
     */
42
    public $autocomplete = false;
43
44
    /**
45
     * Constructor.
46
     *
47
     * @param   string  $key        The attribute field key.
48
     * @param   string  $dataType   The attribute data type.
49
     * @param   bool    $mixin
50
     */
51
    public function __construct($key, $dataType, $mixin = false)
52
    {
53
        parent::__construct($key, $mixin);
54
        $this->dataType = $dataType;
55
    }
56
57
    /**
58
     * Determines if this attribute has a default value.
59
     *
60
     * @return  bool
61
     */
62
    public function hasDefaultValue()
63
    {
64
        null !== $this->defaultValue;
65
    }
66
67
    /**
68
     * Determines if this attribute is calculated.
69
     *
70
     * @return  bool
71
     */
72
    public function isCalculated()
73
    {
74
        return null !== $this->calculated['class'] && null !== $this->calculated['method'];
75
    }
76
77
    /**
78
     * Determines whether this attribute is flagged to be stored as an autocomplete field in search.
79
     *
80
     * @return  bool
81
     */
82
    public function hasAutocomplete()
83
    {
84
        return $this->autocomplete;
85
    }
86
87
    /**
88
     * Sets whether this attribute will be set as an autocomplete field in search.
89
     *
90
     * @param   bool    $bit
91
     * @return  self
92
     */
93
    public function setAutocomplete($bit = true)
94
    {
95
        $this->autocomplete = (Boolean) $bit;
96
        $this->setSearchProperty($bit);
97
        return $this;
98
    }
99
}
100