Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
Attribute_Definition
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 12
156
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 get_slug
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_slug
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_title
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_title
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_description
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_description
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_type
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_type
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_data
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_data
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 to_array
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Attribute Definition
4 *
5 * @package automattic/jetpack-crm
6 * @since 6.2.0
7 */
8
9namespace Automattic\Jetpack\CRM\Automation;
10
11/**
12 * Attribute Definition.
13 *
14 * An attribute represents how a step is configured. For example, a step that
15 * sends an email to a contact may have an attribute that represents the email
16 * subject, another attribute that represents the email body, and so on.
17 *
18 * @since 6.2.0
19 */
20class Attribute_Definition {
21
22    /**
23     * Represents a dropdown selection input.
24     *
25     * @since 6.2.0
26     * @var string
27     */
28    const SELECT = 'select';
29
30    /**
31     * Represents a checkbox input.
32     *
33     * @since 6.2.0
34     * @var string
35     */
36    const CHECKBOX = 'checkbox';
37
38    /**
39     * Represents a textarea input.
40     *
41     * @since 6.2.0
42     * @var string
43     */
44    const TEXTAREA = 'textarea';
45
46    /**
47     * Represents a text input.
48     *
49     * @since 6.2.0
50     * @var string
51     */
52    const TEXT = 'text';
53
54    /**
55     * Represents a date input.
56     *
57     * @since 6.2.0
58     * @var string
59     */
60    const DATE = 'date';
61
62    /**
63     * Represents a numerical input.
64     *
65     * @since 6.2.0
66     * @var string
67     */
68    const NUMBER = 'number';
69
70    /**
71     * The slug (key) that identifies this attribute.
72     *
73     * @since 6.2.0
74     * @var string
75     */
76    protected $slug;
77
78    /**
79     * The title (label) for this attribute.
80     *
81     * @since 6.2.0
82     * @var string
83     */
84    protected $title;
85
86    /**
87     * The description for this attribute.
88     *
89     * @since 6.2.0
90     * @var string
91     */
92    protected $description;
93
94    /**
95     * Attribute type.
96     *
97     * This is a string that represents the type of the attribute.
98     * E.g.: 'text', 'number', 'select', etc.
99     *
100     * @since 6.2.0
101     * @var string
102     */
103    protected $type;
104
105    /**
106     * Data needed by this attribute (e.g. a map of "key -> description" in the case of a select).
107     *
108     * @since 6.2.0
109     * @var array|null
110     */
111    protected $data;
112
113    /**
114     * Constructor.
115     *
116     * @since 6.2.0
117     *
118     * @param string     $slug The slug (key) that identifies this attribute.
119     * @param string     $title The title (label) for this attribute.
120     * @param string     $description The description for this attribute.
121     * @param string     $type Attribute type.
122     * @param array|null $data Data needed by this attribute.
123     */
124    public function __construct( string $slug, string $title, string $description, string $type, ?array $data = null ) {
125        $this->slug        = $slug;
126        $this->title       = $title;
127        $this->description = $description;
128        $this->type        = $type;
129        $this->data        = $data;
130    }
131
132    /**
133     * Get the slug.
134     *
135     * @since 6.2.0
136     *
137     * @return string
138     */
139    public function get_slug(): string {
140        return $this->slug;
141    }
142
143    /**
144     * Set the slug.
145     *
146     * @since 6.2.0
147     *
148     * @param string $slug The slug (key) that identifies this attribute.
149     */
150    public function set_slug( string $slug ): void {
151        $this->slug = $slug;
152    }
153
154    /**
155     * Get the title.
156     *
157     * @since 6.2.0
158     *
159     * @return string
160     */
161    public function get_title(): string {
162        return $this->title;
163    }
164
165    /**
166     * Set the title.
167     *
168     * @since 6.2.0
169     *
170     * @param string $title The title (label) for this attribute.
171     */
172    public function set_title( string $title ): void {
173        $this->title = $title;
174    }
175
176    /**
177     * Get the description.
178     *
179     * @since 6.2.0
180     *
181     * @return string
182     */
183    public function get_description(): string {
184        return $this->description;
185    }
186
187    /**
188     * Set the description.
189     *
190     * @since 6.2.0
191     *
192     * @param string $description The description for this attribute.
193     */
194    public function set_description( string $description ): void {
195        $this->description = $description;
196    }
197
198    /**
199     * Get the type.
200     *
201     * @since 6.2.0
202     *
203     * @return string
204     */
205    public function get_type(): string {
206        return $this->type;
207    }
208
209    /**
210     * Set the type.
211     *
212     * @since 6.2.0
213     *
214     * @param string $type The attribute type.
215     */
216    public function set_type( string $type ): void {
217        $this->type = $type;
218    }
219
220    /**
221     * Get the data.
222     *
223     * @since 6.2.0
224     *
225     * @return array|null
226     */
227    public function get_data(): ?array {
228        return $this->data;
229    }
230
231    /**
232     * Set the data.
233     *
234     * @since 6.2.0
235     *
236     * @param array|null $data The data needed by this attribute.
237     */
238    public function set_data( ?array $data ): void {
239        $this->data = $data;
240    }
241
242    /**
243     * Get the attribute definition as an array.
244     *
245     * The main use-case to get the attribute as an array is,
246     * so we can easily share it via API.
247     *
248     * @since 6.2.0
249     *
250     * @return array
251     */
252    public function to_array(): array {
253        return array(
254            'slug'        => $this->get_slug(),
255            'title'       => $this->get_title(),
256            'description' => $this->get_description(),
257            'type'        => $this->get_type(),
258            'data'        => $this->get_data(),
259        );
260    }
261}