Completed
Branch FET/reg-form-builder/main (69a760)
by
unknown
04:39 queued 02:08
created
core/services/graphql/types/TypeBase.php 1 patch
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -35,270 +35,270 @@
 block discarded – undo
35 35
 abstract class TypeBase implements TypeInterface
36 36
 {
37 37
 
38
-    /**
39
-     * @var string $namespace The graphql namespace/prefix.
40
-     */
41
-    protected $namespace = 'Espresso';
42
-
43
-    /**
44
-     * @var EEM_Base $model
45
-     */
46
-    protected $model;
47
-
48
-    /**
49
-     * @var string $name
50
-     */
51
-    protected $name = '';
52
-
53
-    /**
54
-     * @var string $description
55
-     */
56
-    protected $description = '';
57
-
58
-    /**
59
-     * @var GraphQLFieldInterface[] $fields
60
-     */
61
-    protected $fields = [];
62
-
63
-    /**
64
-     * @var array $graphql_to_model_map
65
-     */
66
-    protected $graphql_to_model_map = [];
67
-
68
-    /**
69
-     * @var FieldResolver $field_resolver
70
-     */
71
-    protected $field_resolver;
72
-
73
-    /**
74
-     * @var bool $is_custom_post_type
75
-     */
76
-    protected $is_custom_post_type = false;
77
-
78
-
79
-    /**
80
-     * TypeBase constructor.
81
-     *
82
-     * @param EEM_Base|null $model
83
-     */
84
-    public function __construct(EEM_Base $model = null)
85
-    {
86
-        $this->model = $model;
87
-        $this->setFields($this->getFields());
88
-        $this->field_resolver = new FieldResolver(
89
-            $this->model,
90
-            $this->getFieldsForResolver()
91
-        );
92
-    }
93
-
94
-
95
-    /**
96
-     * @return GraphQLFieldInterface[]
97
-     * @since $VID:$
98
-     */
99
-    abstract protected function getFields(): array;
100
-
101
-
102
-    /**
103
-     * @return string
104
-     */
105
-    public function name(): string
106
-    {
107
-        return $this->name;
108
-    }
109
-
110
-
111
-    /**
112
-     * @param string $name
113
-     */
114
-    protected function setName(string $name)
115
-    {
116
-        $this->name = $name;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function description(): string
124
-    {
125
-        return $this->description;
126
-    }
127
-
128
-
129
-    /**
130
-     * @param string $description
131
-     */
132
-    protected function setDescription(string $description)
133
-    {
134
-        $this->description = $description;
135
-    }
136
-
137
-
138
-    /**
139
-     * @return GraphQLFieldInterface[]
140
-     * @since $VID:$
141
-     */
142
-    public function fields(): array
143
-    {
144
-        return (array) $this->fields;
145
-    }
146
-
147
-
148
-    /**
149
-     * @param GraphQLFieldInterface[] $fields
150
-     */
151
-    protected function setFields(array $fields)
152
-    {
153
-        foreach ($fields as $field) {
154
-            if ($field instanceof GraphQLField) {
155
-                $this->fields[] = $field;
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Creates a key map for internal resolver.
163
-     *
164
-     * @return array
165
-     * @since $VID:$
166
-     */
167
-    public function getFieldsForResolver(): array
168
-    {
169
-        $fields = [];
170
-        foreach ($this->fields() as $field) {
171
-            if ($field->useForOutput()) {
172
-                $fields[ $field->name() ] = $field;
173
-            }
174
-        }
175
-        return $fields;
176
-    }
177
-
178
-
179
-    /**
180
-     * @return bool
181
-     */
182
-    public function isCustomPostType(): bool
183
-    {
184
-        return $this->is_custom_post_type;
185
-    }
186
-
187
-
188
-    /**
189
-     * @param bool $is_custom_post_type
190
-     */
191
-    protected function setIsCustomPostType(bool $is_custom_post_type)
192
-    {
193
-        $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
194
-    }
195
-
196
-
197
-    /**
198
-     * @param int|float $value
199
-     * @return int
200
-     * @since $VID:$
201
-     */
202
-    public function parseInfiniteValue($value): int
203
-    {
204
-        $value = trim($value);
205
-        return $value === null
206
-               || $value === ''
207
-               || $value === '∞'
208
-               || $value === 'INF'
209
-               || $value === INF
210
-               || $value === EE_INF
211
-               || is_infinite((float) $value)
212
-            ? -1
213
-            : $value;
214
-    }
215
-
216
-
217
-    /**
218
-     * @param mixed $source
219
-     * @return EE_Base_Class|null
220
-     * @throws EE_Error
221
-     */
222
-    private function getModel($source): ?EE_Base_Class
223
-    {
224
-        // If it comes from a custom connection
225
-        // where the $source is already instantiated.
226
-        if ($source instanceof EE_Base_Class) {
227
-            return $source;
228
-        }
229
-        return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
230
-    }
231
-
232
-
233
-    /**
234
-     * @param mixed       $source  The source that's passed down the GraphQL queries
235
-     * @param array       $args    The inputArgs on the field
236
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
237
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
238
-     * @return EE_Base_Class|Deferred|string|null
239
-     * @throws EE_Error
240
-     * @throws InvalidDataTypeException
241
-     * @throws InvalidInterfaceException
242
-     * @throws UnexpectedEntityException
243
-     * @throws UserError
244
-     * @throws InvalidArgumentException
245
-     * @throws ReflectionException
246
-     * @since $VID:$
247
-     */
248
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
249
-    {
250
-        $source = $source instanceof RootQuery ? $source : $this->getModel($source);
251
-
252
-        return $this->field_resolver->resolve($source, $args, $context, $info);
253
-    }
254
-
255
-
256
-    /**
257
-     * @param mixed      $payload The payload returned after mutation
258
-     * @param array      $args    The inputArgs on the field
259
-     * @param AppContext $context The AppContext passed down the GraphQL tree
260
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
261
-     * @throws EE_Error
262
-     */
263
-    public function resolveFromPayload($payload, array $args, AppContext $context)
264
-    {
265
-        if (empty($payload['id'])) {
266
-            return null;
267
-        }
268
-        return $this->model->get_one_by_ID($payload['id']);
269
-    }
270
-
271
-
272
-    /**
273
-     * Prepares a datetime value in ISO8601/RFC3339 format.
274
-     * It is assumed that the value of $datetime is in the format
275
-     * returned by EE_Base_Class::get_format().
276
-     *
277
-     * @param string        $datetime The datetime value.
278
-     * @param EE_Base_Class $source   The source object.
279
-     * @return string ISO8601/RFC3339 formatted datetime.
280
-     */
281
-    public function formatDatetime(string $datetime, EE_Base_Class $source): string
282
-    {
283
-        $format   = $source->get_format();
284
-        // create date object based on local timezone
285
-        $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
286
-        // change the timezone to UTC
287
-        $datetime->setTimezone(new DateTimeZone('UTC'));
288
-
289
-        return $datetime->format(DateTime::RFC3339);
290
-    }
291
-
292
-
293
-    /**
294
-     * Converts an object to JSON. The object must have a "toJson" method.
295
-     *
296
-     * @param string        $object   The object/value.
297
-     * @param EE_Base_Class $source   The source object.
298
-     * @return string JSON representation of the object.
299
-     */
300
-    public function toJson(JsonableInterface $object, EE_Base_Class $source): string
301
-    {
302
-        return $object->toJson();
303
-    }
38
+	/**
39
+	 * @var string $namespace The graphql namespace/prefix.
40
+	 */
41
+	protected $namespace = 'Espresso';
42
+
43
+	/**
44
+	 * @var EEM_Base $model
45
+	 */
46
+	protected $model;
47
+
48
+	/**
49
+	 * @var string $name
50
+	 */
51
+	protected $name = '';
52
+
53
+	/**
54
+	 * @var string $description
55
+	 */
56
+	protected $description = '';
57
+
58
+	/**
59
+	 * @var GraphQLFieldInterface[] $fields
60
+	 */
61
+	protected $fields = [];
62
+
63
+	/**
64
+	 * @var array $graphql_to_model_map
65
+	 */
66
+	protected $graphql_to_model_map = [];
67
+
68
+	/**
69
+	 * @var FieldResolver $field_resolver
70
+	 */
71
+	protected $field_resolver;
72
+
73
+	/**
74
+	 * @var bool $is_custom_post_type
75
+	 */
76
+	protected $is_custom_post_type = false;
77
+
78
+
79
+	/**
80
+	 * TypeBase constructor.
81
+	 *
82
+	 * @param EEM_Base|null $model
83
+	 */
84
+	public function __construct(EEM_Base $model = null)
85
+	{
86
+		$this->model = $model;
87
+		$this->setFields($this->getFields());
88
+		$this->field_resolver = new FieldResolver(
89
+			$this->model,
90
+			$this->getFieldsForResolver()
91
+		);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return GraphQLFieldInterface[]
97
+	 * @since $VID:$
98
+	 */
99
+	abstract protected function getFields(): array;
100
+
101
+
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function name(): string
106
+	{
107
+		return $this->name;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param string $name
113
+	 */
114
+	protected function setName(string $name)
115
+	{
116
+		$this->name = $name;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function description(): string
124
+	{
125
+		return $this->description;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param string $description
131
+	 */
132
+	protected function setDescription(string $description)
133
+	{
134
+		$this->description = $description;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return GraphQLFieldInterface[]
140
+	 * @since $VID:$
141
+	 */
142
+	public function fields(): array
143
+	{
144
+		return (array) $this->fields;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param GraphQLFieldInterface[] $fields
150
+	 */
151
+	protected function setFields(array $fields)
152
+	{
153
+		foreach ($fields as $field) {
154
+			if ($field instanceof GraphQLField) {
155
+				$this->fields[] = $field;
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Creates a key map for internal resolver.
163
+	 *
164
+	 * @return array
165
+	 * @since $VID:$
166
+	 */
167
+	public function getFieldsForResolver(): array
168
+	{
169
+		$fields = [];
170
+		foreach ($this->fields() as $field) {
171
+			if ($field->useForOutput()) {
172
+				$fields[ $field->name() ] = $field;
173
+			}
174
+		}
175
+		return $fields;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return bool
181
+	 */
182
+	public function isCustomPostType(): bool
183
+	{
184
+		return $this->is_custom_post_type;
185
+	}
186
+
187
+
188
+	/**
189
+	 * @param bool $is_custom_post_type
190
+	 */
191
+	protected function setIsCustomPostType(bool $is_custom_post_type)
192
+	{
193
+		$this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param int|float $value
199
+	 * @return int
200
+	 * @since $VID:$
201
+	 */
202
+	public function parseInfiniteValue($value): int
203
+	{
204
+		$value = trim($value);
205
+		return $value === null
206
+			   || $value === ''
207
+			   || $value === '∞'
208
+			   || $value === 'INF'
209
+			   || $value === INF
210
+			   || $value === EE_INF
211
+			   || is_infinite((float) $value)
212
+			? -1
213
+			: $value;
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param mixed $source
219
+	 * @return EE_Base_Class|null
220
+	 * @throws EE_Error
221
+	 */
222
+	private function getModel($source): ?EE_Base_Class
223
+	{
224
+		// If it comes from a custom connection
225
+		// where the $source is already instantiated.
226
+		if ($source instanceof EE_Base_Class) {
227
+			return $source;
228
+		}
229
+		return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
235
+	 * @param array       $args    The inputArgs on the field
236
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
237
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
238
+	 * @return EE_Base_Class|Deferred|string|null
239
+	 * @throws EE_Error
240
+	 * @throws InvalidDataTypeException
241
+	 * @throws InvalidInterfaceException
242
+	 * @throws UnexpectedEntityException
243
+	 * @throws UserError
244
+	 * @throws InvalidArgumentException
245
+	 * @throws ReflectionException
246
+	 * @since $VID:$
247
+	 */
248
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
249
+	{
250
+		$source = $source instanceof RootQuery ? $source : $this->getModel($source);
251
+
252
+		return $this->field_resolver->resolve($source, $args, $context, $info);
253
+	}
254
+
255
+
256
+	/**
257
+	 * @param mixed      $payload The payload returned after mutation
258
+	 * @param array      $args    The inputArgs on the field
259
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
260
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
261
+	 * @throws EE_Error
262
+	 */
263
+	public function resolveFromPayload($payload, array $args, AppContext $context)
264
+	{
265
+		if (empty($payload['id'])) {
266
+			return null;
267
+		}
268
+		return $this->model->get_one_by_ID($payload['id']);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Prepares a datetime value in ISO8601/RFC3339 format.
274
+	 * It is assumed that the value of $datetime is in the format
275
+	 * returned by EE_Base_Class::get_format().
276
+	 *
277
+	 * @param string        $datetime The datetime value.
278
+	 * @param EE_Base_Class $source   The source object.
279
+	 * @return string ISO8601/RFC3339 formatted datetime.
280
+	 */
281
+	public function formatDatetime(string $datetime, EE_Base_Class $source): string
282
+	{
283
+		$format   = $source->get_format();
284
+		// create date object based on local timezone
285
+		$datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
286
+		// change the timezone to UTC
287
+		$datetime->setTimezone(new DateTimeZone('UTC'));
288
+
289
+		return $datetime->format(DateTime::RFC3339);
290
+	}
291
+
292
+
293
+	/**
294
+	 * Converts an object to JSON. The object must have a "toJson" method.
295
+	 *
296
+	 * @param string        $object   The object/value.
297
+	 * @param EE_Base_Class $source   The source object.
298
+	 * @return string JSON representation of the object.
299
+	 */
300
+	public function toJson(JsonableInterface $object, EE_Base_Class $source): string
301
+	{
302
+		return $object->toJson();
303
+	}
304 304
 }
Please login to merge, or discard this patch.
core/services/container/Mirror.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -21,298 +21,298 @@
 block discarded – undo
21 21
 class Mirror
22 22
 {
23 23
 
24
-    /**
25
-     * @var ReflectionClass[]
26
-     */
27
-    private $classes = [];
28
-
29
-    /**
30
-     * @var ReflectionMethod[]
31
-     */
32
-    private $constructors = [];
33
-
34
-    /**
35
-     * @var ReflectionParameter[][]
36
-     */
37
-    private $parameters = [];
38
-
39
-    /**
40
-     * @var ReflectionParameter[][]
41
-     */
42
-    private $parameter_classes = [];
43
-
44
-    /**
45
-     * @var ReflectionProperty[][]
46
-     */
47
-    private $properties = [];
48
-
49
-    /**
50
-     * @var ReflectionMethod[][]
51
-     */
52
-    private $methods = [];
53
-
54
-    /**
55
-     * @var array
56
-     */
57
-    private $default_properties = [];
58
-
59
-    /**
60
-     * @var array
61
-     */
62
-    private $static_properties = [];
63
-
64
-
65
-    /**
66
-     * @param string $class_name
67
-     * @return ReflectionClass
68
-     * @throws ReflectionException
69
-     * @throws InvalidDataTypeException
70
-     */
71
-    public function getReflectionClass(string $class_name): ReflectionClass
72
-    {
73
-        if (! is_string($class_name)) {
74
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
75
-        }
76
-        if (! isset($this->classes[ $class_name ])) {
77
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
78
-        }
79
-        return $this->classes[ $class_name ];
80
-    }
81
-
82
-
83
-    /**
84
-     * @param string $class_name
85
-     * @return ReflectionMethod|null
86
-     * @throws InvalidDataTypeException
87
-     * @throws ReflectionException
88
-     */
89
-    public function getConstructor(string $class_name): ?ReflectionMethod
90
-    {
91
-        if (! is_string($class_name)) {
92
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
93
-        }
94
-        if (! isset($this->constructors[ $class_name ])) {
95
-            $reflection_class                  = $this->getReflectionClass($class_name);
96
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
97
-        }
98
-        return $this->constructors[ $class_name ];
99
-    }
100
-
101
-
102
-    /**
103
-     * @param ReflectionClass $reflection_class
104
-     * @return ReflectionMethod|null
105
-     * @throws InvalidDataTypeException
106
-     * @throws ReflectionException
107
-     */
108
-    public function getConstructorFromReflection(ReflectionClass $reflection_class): ?ReflectionMethod
109
-    {
110
-        return $this->getConstructor($reflection_class->getName());
111
-    }
112
-
113
-
114
-    /**
115
-     * @param string $class_name
116
-     * @return ReflectionParameter[]
117
-     * @throws InvalidDataTypeException
118
-     * @throws ReflectionException
119
-     */
120
-    public function getParameters(string $class_name): array
121
-    {
122
-        if (! isset($this->parameters[ $class_name ])) {
123
-            $constructor                     = $this->getConstructor($class_name);
124
-            $this->parameters[ $class_name ] = $constructor->getParameters();
125
-        }
126
-        return $this->parameters[ $class_name ];
127
-    }
128
-
129
-
130
-    /**
131
-     * @param ReflectionClass $reflection_class
132
-     * @return ReflectionParameter[]
133
-     * @throws InvalidDataTypeException
134
-     * @throws ReflectionException
135
-     */
136
-    public function getParametersFromReflection(ReflectionClass $reflection_class): array
137
-    {
138
-        return $this->getParameters($reflection_class->getName());
139
-    }
140
-
141
-
142
-    /**
143
-     * @param ReflectionMethod $constructor
144
-     * @return ReflectionParameter[]
145
-     * @throws InvalidDataTypeException
146
-     * @throws ReflectionException
147
-     */
148
-    public function getParametersFromReflectionConstructor(ReflectionMethod $constructor): array
149
-    {
150
-        return $this->getParameters($constructor->getDeclaringClass());
151
-    }
152
-
153
-
154
-    /**
155
-     * returns array of ReflectionParameter objects for parameters that are NOT optional
156
-     *
157
-     * @param string $class_name
158
-     * @return ReflectionParameter[]
159
-     * @throws InvalidDataTypeException
160
-     * @throws ReflectionException
161
-     */
162
-    public function getRequiredParameters(string $class_name): array
163
-    {
164
-        $required_parameters = [];
165
-        $parameters          = $this->getParameters($class_name);
166
-        foreach ($parameters as $parameter) {
167
-            if ($parameter instanceof ReflectionParameter && ! $parameter->isOptional()) {
168
-                $required_parameters[] = $parameter;
169
-            }
170
-        }
171
-        return $required_parameters;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param ReflectionParameter $param
177
-     * @param string              $class_name
178
-     * @param string              $index
179
-     * @return string|null
180
-     */
181
-    public function getParameterClassName(ReflectionParameter $param, string $class_name, string $index): ?string
182
-    {
183
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
184
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
185
-        }
186
-        if (! isset($this->parameter_classes[ $class_name ])) {
187
-            $this->parameter_classes[ $class_name ] = [];
188
-        }
189
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
190
-            $this->parameter_classes[ $class_name ][ $index ] = [];
191
-        }
192
-        // ReflectionParameter::getClass() is deprecated in PHP 8+
193
-        if (PHP_VERSION_ID >= 80000) {
194
-            $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] =
195
-                $param->getType() instanceof ReflectionNamedType
196
-                    ? $param->getType()->getName()
197
-                    : null;
198
-        } else {
199
-            $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
200
-                    ? $param->getClass()->getName()
201
-                    : null;
202
-        }
203
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
204
-    }
205
-
206
-
207
-    /**
208
-     * @param ReflectionParameter $param
209
-     * @param string              $class_name
210
-     * @param string              $index
211
-     * @return array|string|null
212
-     * @throws ReflectionException
213
-     */
214
-    public function getParameterDefaultValue(ReflectionParameter $param, string $class_name, string $index)
215
-    {
216
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
217
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
218
-        }
219
-        if (! isset($this->parameter_classes[ $class_name ])) {
220
-            $this->parameter_classes[ $class_name ] = [];
221
-        }
222
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
223
-            $this->parameter_classes[ $class_name ][ $index ] = [];
224
-        }
225
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
226
-            ? $param->getDefaultValue()
227
-            : null;
228
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
229
-    }
230
-
231
-
232
-    /**
233
-     * @param string $class_name
234
-     * @return ReflectionProperty[]
235
-     * @throws InvalidDataTypeException
236
-     * @throws ReflectionException
237
-     */
238
-    public function getProperties(string $class_name): array
239
-    {
240
-        if (! isset($this->properties[ $class_name ])) {
241
-            $reflection_class                = $this->getReflectionClass($class_name);
242
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
243
-        }
244
-        return $this->properties[ $class_name ];
245
-    }
246
-
247
-
248
-    /**
249
-     * @param ReflectionClass $reflection_class
250
-     * @return ReflectionProperty[]
251
-     * @throws InvalidDataTypeException
252
-     * @throws ReflectionException
253
-     */
254
-    public function getPropertiesFromReflection(ReflectionClass $reflection_class): array
255
-    {
256
-        return $this->getProperties($reflection_class->getName());
257
-    }
258
-
259
-
260
-    /**
261
-     * @param string $class_name
262
-     * @return ReflectionMethod[]
263
-     * @throws InvalidDataTypeException
264
-     * @throws ReflectionException
265
-     */
266
-    public function getMethods(string $class_name): array
267
-    {
268
-        if (! isset($this->methods[ $class_name ])) {
269
-            $reflection_class             = $this->getReflectionClass($class_name);
270
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
271
-        }
272
-        return $this->methods[ $class_name ];
273
-    }
274
-
275
-
276
-    /**
277
-     * @param ReflectionClass $reflection_class )
278
-     * @return ReflectionMethod[]
279
-     * @throws InvalidDataTypeException
280
-     * @throws ReflectionException
281
-     */
282
-    public function getMethodsFromReflection(ReflectionClass $reflection_class): array
283
-    {
284
-        return $this->getMethods($reflection_class->getName());
285
-    }
286
-
287
-
288
-    /**
289
-     * @param string $class_name
290
-     * @return array
291
-     * @throws InvalidDataTypeException
292
-     * @throws ReflectionException
293
-     */
294
-    public function getDefaultProperties(string $class_name): array
295
-    {
296
-        if (! isset($this->default_properties[ $class_name ])) {
297
-            $reflection_class                        = $this->getReflectionClass($class_name);
298
-            $this->default_properties[ $class_name ] = $reflection_class->getDefaultProperties();
299
-        }
300
-        return $this->default_properties[ $class_name ];
301
-    }
302
-
303
-
304
-    /**
305
-     * @param string $class_name
306
-     * @return array
307
-     * @throws InvalidDataTypeException
308
-     * @throws ReflectionException
309
-     */
310
-    public function getStaticProperties(string $class_name): array
311
-    {
312
-        if (! isset($this->static_properties[ $class_name ])) {
313
-            $reflection_class                       = $this->getReflectionClass($class_name);
314
-            $this->static_properties[ $class_name ] = $reflection_class->getStaticProperties();
315
-        }
316
-        return $this->static_properties[ $class_name ];
317
-    }
24
+	/**
25
+	 * @var ReflectionClass[]
26
+	 */
27
+	private $classes = [];
28
+
29
+	/**
30
+	 * @var ReflectionMethod[]
31
+	 */
32
+	private $constructors = [];
33
+
34
+	/**
35
+	 * @var ReflectionParameter[][]
36
+	 */
37
+	private $parameters = [];
38
+
39
+	/**
40
+	 * @var ReflectionParameter[][]
41
+	 */
42
+	private $parameter_classes = [];
43
+
44
+	/**
45
+	 * @var ReflectionProperty[][]
46
+	 */
47
+	private $properties = [];
48
+
49
+	/**
50
+	 * @var ReflectionMethod[][]
51
+	 */
52
+	private $methods = [];
53
+
54
+	/**
55
+	 * @var array
56
+	 */
57
+	private $default_properties = [];
58
+
59
+	/**
60
+	 * @var array
61
+	 */
62
+	private $static_properties = [];
63
+
64
+
65
+	/**
66
+	 * @param string $class_name
67
+	 * @return ReflectionClass
68
+	 * @throws ReflectionException
69
+	 * @throws InvalidDataTypeException
70
+	 */
71
+	public function getReflectionClass(string $class_name): ReflectionClass
72
+	{
73
+		if (! is_string($class_name)) {
74
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
75
+		}
76
+		if (! isset($this->classes[ $class_name ])) {
77
+			$this->classes[ $class_name ] = new ReflectionClass($class_name);
78
+		}
79
+		return $this->classes[ $class_name ];
80
+	}
81
+
82
+
83
+	/**
84
+	 * @param string $class_name
85
+	 * @return ReflectionMethod|null
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws ReflectionException
88
+	 */
89
+	public function getConstructor(string $class_name): ?ReflectionMethod
90
+	{
91
+		if (! is_string($class_name)) {
92
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
93
+		}
94
+		if (! isset($this->constructors[ $class_name ])) {
95
+			$reflection_class                  = $this->getReflectionClass($class_name);
96
+			$this->constructors[ $class_name ] = $reflection_class->getConstructor();
97
+		}
98
+		return $this->constructors[ $class_name ];
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param ReflectionClass $reflection_class
104
+	 * @return ReflectionMethod|null
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws ReflectionException
107
+	 */
108
+	public function getConstructorFromReflection(ReflectionClass $reflection_class): ?ReflectionMethod
109
+	{
110
+		return $this->getConstructor($reflection_class->getName());
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param string $class_name
116
+	 * @return ReflectionParameter[]
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws ReflectionException
119
+	 */
120
+	public function getParameters(string $class_name): array
121
+	{
122
+		if (! isset($this->parameters[ $class_name ])) {
123
+			$constructor                     = $this->getConstructor($class_name);
124
+			$this->parameters[ $class_name ] = $constructor->getParameters();
125
+		}
126
+		return $this->parameters[ $class_name ];
127
+	}
128
+
129
+
130
+	/**
131
+	 * @param ReflectionClass $reflection_class
132
+	 * @return ReflectionParameter[]
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws ReflectionException
135
+	 */
136
+	public function getParametersFromReflection(ReflectionClass $reflection_class): array
137
+	{
138
+		return $this->getParameters($reflection_class->getName());
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param ReflectionMethod $constructor
144
+	 * @return ReflectionParameter[]
145
+	 * @throws InvalidDataTypeException
146
+	 * @throws ReflectionException
147
+	 */
148
+	public function getParametersFromReflectionConstructor(ReflectionMethod $constructor): array
149
+	{
150
+		return $this->getParameters($constructor->getDeclaringClass());
151
+	}
152
+
153
+
154
+	/**
155
+	 * returns array of ReflectionParameter objects for parameters that are NOT optional
156
+	 *
157
+	 * @param string $class_name
158
+	 * @return ReflectionParameter[]
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws ReflectionException
161
+	 */
162
+	public function getRequiredParameters(string $class_name): array
163
+	{
164
+		$required_parameters = [];
165
+		$parameters          = $this->getParameters($class_name);
166
+		foreach ($parameters as $parameter) {
167
+			if ($parameter instanceof ReflectionParameter && ! $parameter->isOptional()) {
168
+				$required_parameters[] = $parameter;
169
+			}
170
+		}
171
+		return $required_parameters;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param ReflectionParameter $param
177
+	 * @param string              $class_name
178
+	 * @param string              $index
179
+	 * @return string|null
180
+	 */
181
+	public function getParameterClassName(ReflectionParameter $param, string $class_name, string $index): ?string
182
+	{
183
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
184
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
185
+		}
186
+		if (! isset($this->parameter_classes[ $class_name ])) {
187
+			$this->parameter_classes[ $class_name ] = [];
188
+		}
189
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
190
+			$this->parameter_classes[ $class_name ][ $index ] = [];
191
+		}
192
+		// ReflectionParameter::getClass() is deprecated in PHP 8+
193
+		if (PHP_VERSION_ID >= 80000) {
194
+			$this->parameter_classes[ $class_name ][ $index ]['param_class_name'] =
195
+				$param->getType() instanceof ReflectionNamedType
196
+					? $param->getType()->getName()
197
+					: null;
198
+		} else {
199
+			$this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
200
+					? $param->getClass()->getName()
201
+					: null;
202
+		}
203
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
204
+	}
205
+
206
+
207
+	/**
208
+	 * @param ReflectionParameter $param
209
+	 * @param string              $class_name
210
+	 * @param string              $index
211
+	 * @return array|string|null
212
+	 * @throws ReflectionException
213
+	 */
214
+	public function getParameterDefaultValue(ReflectionParameter $param, string $class_name, string $index)
215
+	{
216
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
217
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
218
+		}
219
+		if (! isset($this->parameter_classes[ $class_name ])) {
220
+			$this->parameter_classes[ $class_name ] = [];
221
+		}
222
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
223
+			$this->parameter_classes[ $class_name ][ $index ] = [];
224
+		}
225
+		$this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
226
+			? $param->getDefaultValue()
227
+			: null;
228
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param string $class_name
234
+	 * @return ReflectionProperty[]
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws ReflectionException
237
+	 */
238
+	public function getProperties(string $class_name): array
239
+	{
240
+		if (! isset($this->properties[ $class_name ])) {
241
+			$reflection_class                = $this->getReflectionClass($class_name);
242
+			$this->properties[ $class_name ] = $reflection_class->getProperties();
243
+		}
244
+		return $this->properties[ $class_name ];
245
+	}
246
+
247
+
248
+	/**
249
+	 * @param ReflectionClass $reflection_class
250
+	 * @return ReflectionProperty[]
251
+	 * @throws InvalidDataTypeException
252
+	 * @throws ReflectionException
253
+	 */
254
+	public function getPropertiesFromReflection(ReflectionClass $reflection_class): array
255
+	{
256
+		return $this->getProperties($reflection_class->getName());
257
+	}
258
+
259
+
260
+	/**
261
+	 * @param string $class_name
262
+	 * @return ReflectionMethod[]
263
+	 * @throws InvalidDataTypeException
264
+	 * @throws ReflectionException
265
+	 */
266
+	public function getMethods(string $class_name): array
267
+	{
268
+		if (! isset($this->methods[ $class_name ])) {
269
+			$reflection_class             = $this->getReflectionClass($class_name);
270
+			$this->methods[ $class_name ] = $reflection_class->getMethods();
271
+		}
272
+		return $this->methods[ $class_name ];
273
+	}
274
+
275
+
276
+	/**
277
+	 * @param ReflectionClass $reflection_class )
278
+	 * @return ReflectionMethod[]
279
+	 * @throws InvalidDataTypeException
280
+	 * @throws ReflectionException
281
+	 */
282
+	public function getMethodsFromReflection(ReflectionClass $reflection_class): array
283
+	{
284
+		return $this->getMethods($reflection_class->getName());
285
+	}
286
+
287
+
288
+	/**
289
+	 * @param string $class_name
290
+	 * @return array
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws ReflectionException
293
+	 */
294
+	public function getDefaultProperties(string $class_name): array
295
+	{
296
+		if (! isset($this->default_properties[ $class_name ])) {
297
+			$reflection_class                        = $this->getReflectionClass($class_name);
298
+			$this->default_properties[ $class_name ] = $reflection_class->getDefaultProperties();
299
+		}
300
+		return $this->default_properties[ $class_name ];
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param string $class_name
306
+	 * @return array
307
+	 * @throws InvalidDataTypeException
308
+	 * @throws ReflectionException
309
+	 */
310
+	public function getStaticProperties(string $class_name): array
311
+	{
312
+		if (! isset($this->static_properties[ $class_name ])) {
313
+			$reflection_class                       = $this->getReflectionClass($class_name);
314
+			$this->static_properties[ $class_name ] = $reflection_class->getStaticProperties();
315
+		}
316
+		return $this->static_properties[ $class_name ];
317
+	}
318 318
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function getReflectionClass(string $class_name): ReflectionClass
72 72
     {
73
-        if (! is_string($class_name)) {
73
+        if ( ! is_string($class_name)) {
74 74
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
75 75
         }
76
-        if (! isset($this->classes[ $class_name ])) {
77
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
76
+        if ( ! isset($this->classes[$class_name])) {
77
+            $this->classes[$class_name] = new ReflectionClass($class_name);
78 78
         }
79
-        return $this->classes[ $class_name ];
79
+        return $this->classes[$class_name];
80 80
     }
81 81
 
82 82
 
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function getConstructor(string $class_name): ?ReflectionMethod
90 90
     {
91
-        if (! is_string($class_name)) {
91
+        if ( ! is_string($class_name)) {
92 92
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
93 93
         }
94
-        if (! isset($this->constructors[ $class_name ])) {
94
+        if ( ! isset($this->constructors[$class_name])) {
95 95
             $reflection_class                  = $this->getReflectionClass($class_name);
96
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
96
+            $this->constructors[$class_name] = $reflection_class->getConstructor();
97 97
         }
98
-        return $this->constructors[ $class_name ];
98
+        return $this->constructors[$class_name];
99 99
     }
100 100
 
101 101
 
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function getParameters(string $class_name): array
121 121
     {
122
-        if (! isset($this->parameters[ $class_name ])) {
122
+        if ( ! isset($this->parameters[$class_name])) {
123 123
             $constructor                     = $this->getConstructor($class_name);
124
-            $this->parameters[ $class_name ] = $constructor->getParameters();
124
+            $this->parameters[$class_name] = $constructor->getParameters();
125 125
         }
126
-        return $this->parameters[ $class_name ];
126
+        return $this->parameters[$class_name];
127 127
     }
128 128
 
129 129
 
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function getParameterClassName(ReflectionParameter $param, string $class_name, string $index): ?string
182 182
     {
183
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
184
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
183
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) {
184
+            return $this->parameter_classes[$class_name][$index]['param_class_name'];
185 185
         }
186
-        if (! isset($this->parameter_classes[ $class_name ])) {
187
-            $this->parameter_classes[ $class_name ] = [];
186
+        if ( ! isset($this->parameter_classes[$class_name])) {
187
+            $this->parameter_classes[$class_name] = [];
188 188
         }
189
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
190
-            $this->parameter_classes[ $class_name ][ $index ] = [];
189
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
190
+            $this->parameter_classes[$class_name][$index] = [];
191 191
         }
192 192
         // ReflectionParameter::getClass() is deprecated in PHP 8+
193 193
         if (PHP_VERSION_ID >= 80000) {
194
-            $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] =
194
+            $this->parameter_classes[$class_name][$index]['param_class_name'] =
195 195
                 $param->getType() instanceof ReflectionNamedType
196 196
                     ? $param->getType()->getName()
197 197
                     : null;
198 198
         } else {
199
-            $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
199
+            $this->parameter_classes[$class_name][$index]['param_class_name'] = $param->getClass()
200 200
                     ? $param->getClass()->getName()
201 201
                     : null;
202 202
         }
203
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
203
+        return $this->parameter_classes[$class_name][$index]['param_class_name'];
204 204
     }
205 205
 
206 206
 
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
      */
214 214
     public function getParameterDefaultValue(ReflectionParameter $param, string $class_name, string $index)
215 215
     {
216
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
217
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
216
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) {
217
+            return $this->parameter_classes[$class_name][$index]['param_class_default'];
218 218
         }
219
-        if (! isset($this->parameter_classes[ $class_name ])) {
220
-            $this->parameter_classes[ $class_name ] = [];
219
+        if ( ! isset($this->parameter_classes[$class_name])) {
220
+            $this->parameter_classes[$class_name] = [];
221 221
         }
222
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
223
-            $this->parameter_classes[ $class_name ][ $index ] = [];
222
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
223
+            $this->parameter_classes[$class_name][$index] = [];
224 224
         }
225
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
225
+        $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable()
226 226
             ? $param->getDefaultValue()
227 227
             : null;
228
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
228
+        return $this->parameter_classes[$class_name][$index]['param_class_default'];
229 229
     }
230 230
 
231 231
 
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
      */
238 238
     public function getProperties(string $class_name): array
239 239
     {
240
-        if (! isset($this->properties[ $class_name ])) {
240
+        if ( ! isset($this->properties[$class_name])) {
241 241
             $reflection_class                = $this->getReflectionClass($class_name);
242
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
242
+            $this->properties[$class_name] = $reflection_class->getProperties();
243 243
         }
244
-        return $this->properties[ $class_name ];
244
+        return $this->properties[$class_name];
245 245
     }
246 246
 
247 247
 
@@ -265,11 +265,11 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public function getMethods(string $class_name): array
267 267
     {
268
-        if (! isset($this->methods[ $class_name ])) {
268
+        if ( ! isset($this->methods[$class_name])) {
269 269
             $reflection_class             = $this->getReflectionClass($class_name);
270
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
270
+            $this->methods[$class_name] = $reflection_class->getMethods();
271 271
         }
272
-        return $this->methods[ $class_name ];
272
+        return $this->methods[$class_name];
273 273
     }
274 274
 
275 275
 
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
      */
294 294
     public function getDefaultProperties(string $class_name): array
295 295
     {
296
-        if (! isset($this->default_properties[ $class_name ])) {
296
+        if ( ! isset($this->default_properties[$class_name])) {
297 297
             $reflection_class                        = $this->getReflectionClass($class_name);
298
-            $this->default_properties[ $class_name ] = $reflection_class->getDefaultProperties();
298
+            $this->default_properties[$class_name] = $reflection_class->getDefaultProperties();
299 299
         }
300
-        return $this->default_properties[ $class_name ];
300
+        return $this->default_properties[$class_name];
301 301
     }
302 302
 
303 303
 
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public function getStaticProperties(string $class_name): array
311 311
     {
312
-        if (! isset($this->static_properties[ $class_name ])) {
312
+        if ( ! isset($this->static_properties[$class_name])) {
313 313
             $reflection_class                       = $this->getReflectionClass($class_name);
314
-            $this->static_properties[ $class_name ] = $reflection_class->getStaticProperties();
314
+            $this->static_properties[$class_name] = $reflection_class->getStaticProperties();
315 315
         }
316
-        return $this->static_properties[ $class_name ];
316
+        return $this->static_properties[$class_name];
317 317
     }
318 318
 }
Please login to merge, or discard this patch.
core/services/form/meta/JsonableInterface.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
  */
12 12
 interface JsonableInterface
13 13
 {
14
-    /**
15
-     * @param string $json
16
-     * @return mixed
17
-     */
18
-    public static function fromJson(string $json);
14
+	/**
15
+	 * @param string $json
16
+	 * @return mixed
17
+	 */
18
+	public static function fromJson(string $json);
19 19
 
20 20
 
21
-    /**
22
-     * @return string
23
-     */
24
-    public function toJson(): string;
21
+	/**
22
+	 * @return string
23
+	 */
24
+	public function toJson(): string;
25 25
 }
Please login to merge, or discard this patch.
core/services/form/meta/Attributes.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -17,184 +17,184 @@
 block discarded – undo
17 17
 class Attributes implements JsonableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var JsonDataHandler
22
-     */
23
-    private $json_data_handler;
24
-
25
-    /**
26
-     * @var InputTypes
27
-     */
28
-    private $input_types;
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private $attributes = [];
34
-
35
-    /**
36
-     * @var array
37
-     */
38
-    private $attribute_types = [
39
-        'accept'          => 'string',
40
-        'accesskey'       => 'string',
41
-        'alt'             => 'string',
42
-        'autocomplete'    => 'bool',
43
-        'autofocus'       => 'bool',
44
-        'checked'         => 'bool',
45
-        // Custom HTML classes to be applied to the form input's container
46
-        'class'           => 'string',
47
-        'contenteditable' => 'bool',
48
-        'dir'             => 'string',
49
-        'disabled'        => 'bool',
50
-        'height'          => 'string',
51
-        'hidden'          => 'bool',
52
-        'id'              => 'string',
53
-        'list'            => 'string',
54
-        // Maximum numeric value allowed for form input answer.
55
-        'max'             => 'int',
56
-        // Maximum characters allowed for form input answer.
57
-        'maxlength'       => 'int',
58
-        // Minimum numeric value allowed for form input answer.
59
-        'min'             => 'int',
60
-        'multiple'        => 'bool',
61
-        'name'            => 'string',
62
-        'pattern'         => 'string',
63
-        // Example text displayed within an input to assist users with completing the form.
64
-        'placeholder'     => 'string',
65
-        'readonly'        => 'bool',
66
-        'size'            => 'int',
67
-        'spellcheck'      => 'bool',
68
-        'step'            => 'float',
69
-        'style'           => 'string',
70
-        'tabindex'        => 'int',
71
-        'title'           => 'string',
72
-        'translate'       => 'bool',
73
-        // Form input type. Values correspond to the Input::TYPE_* constants.
74
-        'type'            => 'string',
75
-        'value'           => 'string',
76
-        'width'           => 'string',
77
-    ];
78
-
79
-
80
-    /**
81
-     * Attributes constructor.
82
-     *
83
-     * @param JsonDataHandler $json_data_handler
84
-     * @param InputTypes      $element_types
85
-     * @param array           $attributes
86
-     */
87
-    public function __construct(JsonDataHandler $json_data_handler, array $attributes, InputTypes $element_types)
88
-    {
89
-        $this->json_data_handler = $json_data_handler;
90
-        $this->input_types       = $element_types;
91
-        $this->setAttributes($attributes);
92
-    }
93
-
94
-
95
-    /**
96
-     * @param string $json
97
-     * @return Attributes
98
-     */
99
-    public static function fromJson(string $json): Attributes
100
-    {
101
-        $json_data_handler = new JsonDataHandler();
102
-        $json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY);
103
-        $attributes = $json_data_handler->decodeJson($json);
104
-        /** @var InputTypes */
105
-        $element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes');
106
-        return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]);
107
-    }
108
-
109
-
110
-    /**
111
-     * @return array
112
-     */
113
-    public function toArray(): array
114
-    {
115
-        return $this->attributes();
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function toJson(): string
123
-    {
124
-        return $this->json_data_handler->encodeData($this->attributes());
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string                $attribute
130
-     * @param bool|float|int|string $value
131
-     * @return bool|float|int|string
132
-     */
133
-    private function sanitize(string $attribute, $value)
134
-    {
135
-        if ($attribute === 'type') {
136
-            $valid_types = $this->input_types->validTypeOptions();
137
-            return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT;
138
-        }
139
-        $type = $this->attribute_types[ $attribute ] ?? 'string';
140
-        switch ($type) {
141
-            case 'bool':
142
-                return filter_var($value, FILTER_VALIDATE_BOOLEAN);
143
-            case 'int':
144
-                return filter_var($value, FILTER_SANITIZE_NUMBER_INT);
145
-            case 'float':
146
-                return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
147
-            case 'string':
148
-            default:
149
-                return filter_var(
150
-                    $value,
151
-                    FILTER_SANITIZE_STRING,
152
-                    FILTER_FLAG_ENCODE_LOW | FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_ENCODE_AMP
153
-                );
154
-        }
155
-    }
156
-
157
-
158
-    /**
159
-     * Custom HTML classes to be applied to this form input's help text.
160
-     * returns a concatenated string unless $as_array is set to true
161
-     *
162
-     * @return array
163
-     */
164
-    public function attributes(): array
165
-    {
166
-        return $this->attributes;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string                $attribute
172
-     * @param bool|float|int|string $value
173
-     */
174
-    public function addAttribute(string $attribute, $value): void
175
-    {
176
-        if (array_key_exists($attribute, $this->attribute_types)) {
177
-            $this->attributes[ $attribute ] = $this->sanitize($attribute, $value);
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * @param string $attribute
184
-     */
185
-    public function removeAttribute(string $attribute): void
186
-    {
187
-        unset($this->attributes[ $attribute ]);
188
-    }
189
-
190
-
191
-    /**
192
-     * @param array $attributes array where keys are the attribute name and values are the attribute's value
193
-     */
194
-    public function setAttributes(array $attributes): void
195
-    {
196
-        foreach ($attributes as $attribute => $value) {
197
-            $this->addAttribute($attribute, $value);
198
-        }
199
-    }
20
+	/**
21
+	 * @var JsonDataHandler
22
+	 */
23
+	private $json_data_handler;
24
+
25
+	/**
26
+	 * @var InputTypes
27
+	 */
28
+	private $input_types;
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private $attributes = [];
34
+
35
+	/**
36
+	 * @var array
37
+	 */
38
+	private $attribute_types = [
39
+		'accept'          => 'string',
40
+		'accesskey'       => 'string',
41
+		'alt'             => 'string',
42
+		'autocomplete'    => 'bool',
43
+		'autofocus'       => 'bool',
44
+		'checked'         => 'bool',
45
+		// Custom HTML classes to be applied to the form input's container
46
+		'class'           => 'string',
47
+		'contenteditable' => 'bool',
48
+		'dir'             => 'string',
49
+		'disabled'        => 'bool',
50
+		'height'          => 'string',
51
+		'hidden'          => 'bool',
52
+		'id'              => 'string',
53
+		'list'            => 'string',
54
+		// Maximum numeric value allowed for form input answer.
55
+		'max'             => 'int',
56
+		// Maximum characters allowed for form input answer.
57
+		'maxlength'       => 'int',
58
+		// Minimum numeric value allowed for form input answer.
59
+		'min'             => 'int',
60
+		'multiple'        => 'bool',
61
+		'name'            => 'string',
62
+		'pattern'         => 'string',
63
+		// Example text displayed within an input to assist users with completing the form.
64
+		'placeholder'     => 'string',
65
+		'readonly'        => 'bool',
66
+		'size'            => 'int',
67
+		'spellcheck'      => 'bool',
68
+		'step'            => 'float',
69
+		'style'           => 'string',
70
+		'tabindex'        => 'int',
71
+		'title'           => 'string',
72
+		'translate'       => 'bool',
73
+		// Form input type. Values correspond to the Input::TYPE_* constants.
74
+		'type'            => 'string',
75
+		'value'           => 'string',
76
+		'width'           => 'string',
77
+	];
78
+
79
+
80
+	/**
81
+	 * Attributes constructor.
82
+	 *
83
+	 * @param JsonDataHandler $json_data_handler
84
+	 * @param InputTypes      $element_types
85
+	 * @param array           $attributes
86
+	 */
87
+	public function __construct(JsonDataHandler $json_data_handler, array $attributes, InputTypes $element_types)
88
+	{
89
+		$this->json_data_handler = $json_data_handler;
90
+		$this->input_types       = $element_types;
91
+		$this->setAttributes($attributes);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param string $json
97
+	 * @return Attributes
98
+	 */
99
+	public static function fromJson(string $json): Attributes
100
+	{
101
+		$json_data_handler = new JsonDataHandler();
102
+		$json_data_handler->configure(JsonDataHandler::DATA_TYPE_ARRAY);
103
+		$attributes = $json_data_handler->decodeJson($json);
104
+		/** @var InputTypes */
105
+		$element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes');
106
+		return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]);
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function toArray(): array
114
+	{
115
+		return $this->attributes();
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function toJson(): string
123
+	{
124
+		return $this->json_data_handler->encodeData($this->attributes());
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string                $attribute
130
+	 * @param bool|float|int|string $value
131
+	 * @return bool|float|int|string
132
+	 */
133
+	private function sanitize(string $attribute, $value)
134
+	{
135
+		if ($attribute === 'type') {
136
+			$valid_types = $this->input_types->validTypeOptions();
137
+			return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT;
138
+		}
139
+		$type = $this->attribute_types[ $attribute ] ?? 'string';
140
+		switch ($type) {
141
+			case 'bool':
142
+				return filter_var($value, FILTER_VALIDATE_BOOLEAN);
143
+			case 'int':
144
+				return filter_var($value, FILTER_SANITIZE_NUMBER_INT);
145
+			case 'float':
146
+				return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
147
+			case 'string':
148
+			default:
149
+				return filter_var(
150
+					$value,
151
+					FILTER_SANITIZE_STRING,
152
+					FILTER_FLAG_ENCODE_LOW | FILTER_FLAG_ENCODE_HIGH | FILTER_FLAG_ENCODE_AMP
153
+				);
154
+		}
155
+	}
156
+
157
+
158
+	/**
159
+	 * Custom HTML classes to be applied to this form input's help text.
160
+	 * returns a concatenated string unless $as_array is set to true
161
+	 *
162
+	 * @return array
163
+	 */
164
+	public function attributes(): array
165
+	{
166
+		return $this->attributes;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string                $attribute
172
+	 * @param bool|float|int|string $value
173
+	 */
174
+	public function addAttribute(string $attribute, $value): void
175
+	{
176
+		if (array_key_exists($attribute, $this->attribute_types)) {
177
+			$this->attributes[ $attribute ] = $this->sanitize($attribute, $value);
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * @param string $attribute
184
+	 */
185
+	public function removeAttribute(string $attribute): void
186
+	{
187
+		unset($this->attributes[ $attribute ]);
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param array $attributes array where keys are the attribute name and values are the attribute's value
193
+	 */
194
+	public function setAttributes(array $attributes): void
195
+	{
196
+		foreach ($attributes as $attribute => $value) {
197
+			$this->addAttribute($attribute, $value);
198
+		}
199
+	}
200 200
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         $attributes = $json_data_handler->decodeJson($json);
104 104
         /** @var InputTypes */
105 105
         $element_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes');
106
-        return LoaderFactory::getNew(Attributes::class, [ $json_data_handler, $attributes, $element_types ]);
106
+        return LoaderFactory::getNew(Attributes::class, [$json_data_handler, $attributes, $element_types]);
107 107
     }
108 108
 
109 109
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             $valid_types = $this->input_types->validTypeOptions();
137 137
             return in_array($value, $valid_types, true) ?: Text::TYPE_TEXT;
138 138
         }
139
-        $type = $this->attribute_types[ $attribute ] ?? 'string';
139
+        $type = $this->attribute_types[$attribute] ?? 'string';
140 140
         switch ($type) {
141 141
             case 'bool':
142 142
                 return filter_var($value, FILTER_VALIDATE_BOOLEAN);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     public function addAttribute(string $attribute, $value): void
175 175
     {
176 176
         if (array_key_exists($attribute, $this->attribute_types)) {
177
-            $this->attributes[ $attribute ] = $this->sanitize($attribute, $value);
177
+            $this->attributes[$attribute] = $this->sanitize($attribute, $value);
178 178
         }
179 179
     }
180 180
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function removeAttribute(string $attribute): void
186 186
     {
187
-        unset($this->attributes[ $attribute ]);
187
+        unset($this->attributes[$attribute]);
188 188
     }
189 189
 
190 190
 
Please login to merge, or discard this patch.
core/services/form/meta/FormStatus.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 class FormStatus
16 16
 {
17 17
 
18
-    /**
19
-     * indicates that element is not archived or trashed
20
-     */
21
-    public const ACTIVE = 'active';
18
+	/**
19
+	 * indicates that element is not archived or trashed
20
+	 */
21
+	public const ACTIVE = 'active';
22 22
 
23
-    /**
24
-     * indicates that element is archived and should no longer be displayed on public forms
25
-     * but may still be required due to existing answers when form was completed prior to input being archived
26
-     */
27
-    public const ARCHIVED = 'archived';
23
+	/**
24
+	 * indicates that element is archived and should no longer be displayed on public forms
25
+	 * but may still be required due to existing answers when form was completed prior to input being archived
26
+	 */
27
+	public const ARCHIVED = 'archived';
28 28
 
29
-    /**
30
-     * indicates that element should be automatically added to newly created forms
31
-     */
32
-    public const DEFAULT = 'default';
29
+	/**
30
+	 * indicates that element should be automatically added to newly created forms
31
+	 */
32
+	public const DEFAULT = 'default';
33 33
 
34
-    /**
35
-     * indicates that a copy of the form section will be saved for use in other events but not loaded by default
36
-     */
37
-    public const SHARED = 'shared';
34
+	/**
35
+	 * indicates that a copy of the form section will be saved for use in other events but not loaded by default
36
+	 */
37
+	public const SHARED = 'shared';
38 38
 
39
-    /**
40
-     * indicates that element is no longer needed, has no existing answers, and can be moved to the trash
41
-     */
42
-    public const TRASHED = 'trashed';
39
+	/**
40
+	 * indicates that element is no longer needed, has no existing answers, and can be moved to the trash
41
+	 */
42
+	public const TRASHED = 'trashed';
43 43
 
44
-    /**
45
-     * @var array
46
-     */
47
-    private $valid_status_options;
44
+	/**
45
+	 * @var array
46
+	 */
47
+	private $valid_status_options;
48 48
 
49 49
 
50
-    public function __construct()
51
-    {
52
-        $this->valid_status_options = apply_filters(
53
-            'FHEE__EventEspresso_core_services_form_meta_FormStatus__valid_status_options',
54
-            [
55
-                FormStatus::ACTIVE   => esc_html__('Active', 'event_espresso'),
56
-                FormStatus::ARCHIVED => esc_html__('Archived', 'event_espresso'),
57
-                FormStatus::DEFAULT  => esc_html__('Default', 'event_espresso'),
58
-                FormStatus::SHARED   => esc_html__('Shared', 'event_espresso'),
59
-                FormStatus::TRASHED  => esc_html__('Trashed', 'event_espresso'),
60
-            ]
61
-        );
62
-    }
50
+	public function __construct()
51
+	{
52
+		$this->valid_status_options = apply_filters(
53
+			'FHEE__EventEspresso_core_services_form_meta_FormStatus__valid_status_options',
54
+			[
55
+				FormStatus::ACTIVE   => esc_html__('Active', 'event_espresso'),
56
+				FormStatus::ARCHIVED => esc_html__('Archived', 'event_espresso'),
57
+				FormStatus::DEFAULT  => esc_html__('Default', 'event_espresso'),
58
+				FormStatus::SHARED   => esc_html__('Shared', 'event_espresso'),
59
+				FormStatus::TRASHED  => esc_html__('Trashed', 'event_espresso'),
60
+			]
61
+		);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * @return array
67
-     */
68
-    public function getFormStatusValues(): array
69
-    {
70
-        $values = [];
71
-        foreach ($this->valid_status_options as $value => $description) {
72
-            $values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
73
-        }
74
-        return $values;
75
-    }
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function getFormStatusValues(): array
69
+	{
70
+		$values = [];
71
+		foreach ($this->valid_status_options as $value => $description) {
72
+			$values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
73
+		}
74
+		return $values;
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @param bool $constants_only
80
-     * @return array
81
-     */
82
-    public function validStatusOptions(bool $constants_only = false): array
83
-    {
84
-        return $constants_only
85
-            ? array_keys($this->valid_status_options)
86
-            : $this->valid_status_options;
87
-    }
78
+	/**
79
+	 * @param bool $constants_only
80
+	 * @return array
81
+	 */
82
+	public function validStatusOptions(bool $constants_only = false): array
83
+	{
84
+		return $constants_only
85
+			? array_keys($this->valid_status_options)
86
+			: $this->valid_status_options;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@
 block discarded – undo
69 69
     {
70 70
         $values = [];
71 71
         foreach ($this->valid_status_options as $value => $description) {
72
-            $values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
72
+            $values[GQLUtils::formatEnumKey($value)] = compact('value', 'description');
73 73
         }
74 74
         return $values;
75 75
     }
Please login to merge, or discard this patch.
core/services/form/meta/InputTypes.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
     {
117 117
         $values = [];
118 118
         foreach ($this->valid_type_options as $value => $description) {
119
-            $values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
119
+            $values[GQLUtils::formatEnumKey($value)] = compact('value', 'description');
120 120
         }
121 121
         return $values;
122 122
     }
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -22,124 +22,124 @@
 block discarded – undo
22 22
  */
23 23
 class InputTypes
24 24
 {
25
-    /**
26
-     * @var Block
27
-     */
28
-    private $block;
29
-
30
-    /**
31
-     * @var Button
32
-     */
33
-    private $button;
34
-
35
-    /**
36
-     * @var DateTime
37
-     */
38
-    private $datetime;
39
-
40
-    /**
41
-     * @var Input
42
-     */
43
-    private $input;
44
-
45
-    /**
46
-     * @var Number
47
-     */
48
-    private $number;
49
-
50
-    /**
51
-     * @var Phone
52
-     */
53
-    private $phone;
54
-
55
-    /**
56
-     * @var Select
57
-     */
58
-    private $select;
59
-
60
-    /**
61
-     * @var Text
62
-     */
63
-    private $text;
64
-
65
-    /**
66
-     * @var array
67
-     */
68
-    private $valid_type_options;
69
-
70
-
71
-    /**
72
-     * InputTypes constructor.
73
-     *
74
-     * @param Block   $block
75
-     * @param Button   $button
76
-     * @param DateTime $datetime
77
-     * @param Input    $input
78
-     * @param Number   $number
79
-     * @param Phone    $phone
80
-     * @param Select   $select
81
-     * @param Text     $text
82
-     */
83
-    public function __construct(
84
-        Block $block,
85
-        Button $button,
86
-        DateTime $datetime,
87
-        Input $input,
88
-        Number $number,
89
-        Phone $phone,
90
-        Select $select,
91
-        Text $text
92
-    ) {
93
-        $this->block    = $block;
94
-        $this->button   = $button;
95
-        $this->datetime = $datetime;
96
-        $this->input    = $input;
97
-        $this->number   = $number;
98
-        $this->phone    = $phone;
99
-        $this->select   = $select;
100
-        $this->text     = $text;
101
-        $this->assembleValidTypeOptions();
102
-    }
103
-
104
-
105
-    private function assembleValidTypeOptions()
106
-    {
107
-        $block    = $this->block->validTypeOptions();
108
-        $button   = $this->button->validTypeOptions();
109
-        $datetime = $this->datetime->validTypeOptions();
110
-        $input    = $this->input->validTypeOptions();
111
-        $number   = $this->number->validTypeOptions();
112
-        $phone    = $this->phone->validTypeOptions();
113
-        $select   = $this->select->validTypeOptions();
114
-        $text     = $this->text->validTypeOptions();
115
-        $this->valid_type_options = apply_filters(
116
-            'FHEE__EventEspresso_core_services_form_meta_InputTypes__valid_type_options',
117
-            array_merge($block, $button, $datetime, $input, $number, $phone, $select, $text)
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * @return array
124
-     */
125
-    public function getInputTypesValues(): array
126
-    {
127
-        $values = [];
128
-        foreach ($this->valid_type_options as $value => $description) {
129
-            $values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
130
-        }
131
-        return $values;
132
-    }
133
-
134
-
135
-    /**
136
-     * @param bool $constants_only
137
-     * @return array
138
-     */
139
-    public function validTypeOptions(bool $constants_only = false): array
140
-    {
141
-        return $constants_only
142
-            ? array_keys($this->valid_type_options)
143
-            : $this->valid_type_options;
144
-    }
25
+	/**
26
+	 * @var Block
27
+	 */
28
+	private $block;
29
+
30
+	/**
31
+	 * @var Button
32
+	 */
33
+	private $button;
34
+
35
+	/**
36
+	 * @var DateTime
37
+	 */
38
+	private $datetime;
39
+
40
+	/**
41
+	 * @var Input
42
+	 */
43
+	private $input;
44
+
45
+	/**
46
+	 * @var Number
47
+	 */
48
+	private $number;
49
+
50
+	/**
51
+	 * @var Phone
52
+	 */
53
+	private $phone;
54
+
55
+	/**
56
+	 * @var Select
57
+	 */
58
+	private $select;
59
+
60
+	/**
61
+	 * @var Text
62
+	 */
63
+	private $text;
64
+
65
+	/**
66
+	 * @var array
67
+	 */
68
+	private $valid_type_options;
69
+
70
+
71
+	/**
72
+	 * InputTypes constructor.
73
+	 *
74
+	 * @param Block   $block
75
+	 * @param Button   $button
76
+	 * @param DateTime $datetime
77
+	 * @param Input    $input
78
+	 * @param Number   $number
79
+	 * @param Phone    $phone
80
+	 * @param Select   $select
81
+	 * @param Text     $text
82
+	 */
83
+	public function __construct(
84
+		Block $block,
85
+		Button $button,
86
+		DateTime $datetime,
87
+		Input $input,
88
+		Number $number,
89
+		Phone $phone,
90
+		Select $select,
91
+		Text $text
92
+	) {
93
+		$this->block    = $block;
94
+		$this->button   = $button;
95
+		$this->datetime = $datetime;
96
+		$this->input    = $input;
97
+		$this->number   = $number;
98
+		$this->phone    = $phone;
99
+		$this->select   = $select;
100
+		$this->text     = $text;
101
+		$this->assembleValidTypeOptions();
102
+	}
103
+
104
+
105
+	private function assembleValidTypeOptions()
106
+	{
107
+		$block    = $this->block->validTypeOptions();
108
+		$button   = $this->button->validTypeOptions();
109
+		$datetime = $this->datetime->validTypeOptions();
110
+		$input    = $this->input->validTypeOptions();
111
+		$number   = $this->number->validTypeOptions();
112
+		$phone    = $this->phone->validTypeOptions();
113
+		$select   = $this->select->validTypeOptions();
114
+		$text     = $this->text->validTypeOptions();
115
+		$this->valid_type_options = apply_filters(
116
+			'FHEE__EventEspresso_core_services_form_meta_InputTypes__valid_type_options',
117
+			array_merge($block, $button, $datetime, $input, $number, $phone, $select, $text)
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public function getInputTypesValues(): array
126
+	{
127
+		$values = [];
128
+		foreach ($this->valid_type_options as $value => $description) {
129
+			$values[ GQLUtils::formatEnumKey($value) ] = compact('value', 'description');
130
+		}
131
+		return $values;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @param bool $constants_only
137
+	 * @return array
138
+	 */
139
+	public function validTypeOptions(bool $constants_only = false): array
140
+	{
141
+		return $constants_only
142
+			? array_keys($this->valid_type_options)
143
+			: $this->valid_type_options;
144
+	}
145 145
 }
Please login to merge, or discard this patch.
core/services/form/meta/Required.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -15,110 +15,110 @@
 block discarded – undo
15 15
 class Required implements JsonableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var JsonDataHandler
20
-     */
21
-    private $json_data_handler;
22
-
23
-    /** Whether or not the input must be supplied with a value in order to complete the form.
24
-     *
25
-     * @var bool
26
-     */
27
-    private $required;
28
-
29
-    /**
30
-     * Custom validation text displayed alongside a required form input to assist users with completing the form.
31
-     *
32
-     * @var string
33
-     */
34
-    private $validationText;
35
-
36
-
37
-    /**
38
-     * Required constructor.
39
-     *
40
-     * @param JsonDataHandler $json_data_handler
41
-     * @param bool            $required
42
-     * @param string          $validationText
43
-     */
44
-    public function __construct(JsonDataHandler $json_data_handler, bool $required, string $validationText)
45
-    {
46
-        $this->json_data_handler = $json_data_handler;
47
-        $this->setRequired($required);
48
-        $this->setValidationText($validationText);
49
-    }
50
-
51
-
52
-    /**
53
-     * @param string $json
54
-     * @return Required
55
-     */
56
-    public static function fromJson(string $json): Required
57
-    {
58
-        $json_data_handler = new JsonDataHandler();
59
-        $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
60
-        $data           = $json_data_handler->decodeJson($json);
61
-        $required       = $data->required ?? false;
62
-        $validationText = $data->validationText ?? '';
63
-        return new Required($json_data_handler, $required, $validationText);
64
-    }
65
-
66
-
67
-    /**
68
-     * @return array
69
-     */
70
-    public function toArray(): array
71
-    {
72
-        return [
73
-            'required'       => $this->required,
74
-            'validationText' => $this->validationText,
75
-        ];
76
-    }
77
-
78
-
79
-    /**
80
-     * @return string
81
-     */
82
-    public function toJson(): string
83
-    {
84
-        return $this->json_data_handler->encodeData($this->toArray());
85
-    }
86
-
87
-
88
-    /**
89
-     *
90
-     *
91
-     * @return bool
92
-     */
93
-    public function isRequired(): ?bool
94
-    {
95
-        return $this->required;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param bool|int|string $required
101
-     */
102
-    public function setRequired($required = true)
103
-    {
104
-        $this->required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
105
-    }
106
-
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function validationText(): ?string
112
-    {
113
-        return $this->validationText;
114
-    }
115
-
116
-
117
-    /**
118
-     * @param string $validationText
119
-     */
120
-    public function setValidationText(string $validationText)
121
-    {
122
-        $this->validationText = sanitize_text_field($validationText);
123
-    }
18
+	/**
19
+	 * @var JsonDataHandler
20
+	 */
21
+	private $json_data_handler;
22
+
23
+	/** Whether or not the input must be supplied with a value in order to complete the form.
24
+	 *
25
+	 * @var bool
26
+	 */
27
+	private $required;
28
+
29
+	/**
30
+	 * Custom validation text displayed alongside a required form input to assist users with completing the form.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $validationText;
35
+
36
+
37
+	/**
38
+	 * Required constructor.
39
+	 *
40
+	 * @param JsonDataHandler $json_data_handler
41
+	 * @param bool            $required
42
+	 * @param string          $validationText
43
+	 */
44
+	public function __construct(JsonDataHandler $json_data_handler, bool $required, string $validationText)
45
+	{
46
+		$this->json_data_handler = $json_data_handler;
47
+		$this->setRequired($required);
48
+		$this->setValidationText($validationText);
49
+	}
50
+
51
+
52
+	/**
53
+	 * @param string $json
54
+	 * @return Required
55
+	 */
56
+	public static function fromJson(string $json): Required
57
+	{
58
+		$json_data_handler = new JsonDataHandler();
59
+		$json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
60
+		$data           = $json_data_handler->decodeJson($json);
61
+		$required       = $data->required ?? false;
62
+		$validationText = $data->validationText ?? '';
63
+		return new Required($json_data_handler, $required, $validationText);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return array
69
+	 */
70
+	public function toArray(): array
71
+	{
72
+		return [
73
+			'required'       => $this->required,
74
+			'validationText' => $this->validationText,
75
+		];
76
+	}
77
+
78
+
79
+	/**
80
+	 * @return string
81
+	 */
82
+	public function toJson(): string
83
+	{
84
+		return $this->json_data_handler->encodeData($this->toArray());
85
+	}
86
+
87
+
88
+	/**
89
+	 *
90
+	 *
91
+	 * @return bool
92
+	 */
93
+	public function isRequired(): ?bool
94
+	{
95
+		return $this->required;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param bool|int|string $required
101
+	 */
102
+	public function setRequired($required = true)
103
+	{
104
+		$this->required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return string
110
+	 */
111
+	public function validationText(): ?string
112
+	{
113
+		return $this->validationText;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param string $validationText
119
+	 */
120
+	public function setValidationText(string $validationText)
121
+	{
122
+		$this->validationText = sanitize_text_field($validationText);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/enums/ElementTypeEnum.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@
 block discarded – undo
17 17
 class ElementTypeEnum extends EnumBase
18 18
 {
19 19
 
20
-    /**
21
-     * ElementTypeEnum constructor.
22
-     */
23
-    public function __construct()
24
-    {
25
-        $this->setName($this->namespace . 'ElementTypeEnum');
26
-        $this->setDescription(esc_html__('Form element type.', 'event_espresso'));
27
-        parent::__construct();
28
-    }
20
+	/**
21
+	 * ElementTypeEnum constructor.
22
+	 */
23
+	public function __construct()
24
+	{
25
+		$this->setName($this->namespace . 'ElementTypeEnum');
26
+		$this->setDescription(esc_html__('Form element type.', 'event_espresso'));
27
+		parent::__construct();
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * @return array
33
-     */
34
-    protected function getValues(): array
35
-    {
36
-        /** @var InputTypes $input_types */
37
-        $input_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes');
38
-        return $input_types->getInputTypesValues();
39
-    }
31
+	/**
32
+	 * @return array
33
+	 */
34
+	protected function getValues(): array
35
+	{
36
+		/** @var InputTypes $input_types */
37
+		$input_types = LoaderFactory::getShared('EventEspresso\core\services\form\meta\InputTypes');
38
+		return $input_types->getInputTypesValues();
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
      */
23 23
     public function __construct()
24 24
     {
25
-        $this->setName($this->namespace . 'ElementTypeEnum');
25
+        $this->setName($this->namespace.'ElementTypeEnum');
26 26
         $this->setDescription(esc_html__('Form element type.', 'event_espresso'));
27 27
         parent::__construct();
28 28
     }
Please login to merge, or discard this patch.
core/domain/services/graphql/enums/FormStatusEnum.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@
 block discarded – undo
17 17
 class FormStatusEnum extends EnumBase
18 18
 {
19 19
 
20
-    /**
21
-     * FormStatusEnum constructor.
22
-     */
23
-    public function __construct()
24
-    {
25
-        $this->setName($this->namespace . 'FormStatusEnum');
26
-        $this->setDescription(esc_html__(
27
-            'Whether form section or element is active, archived, shared, trashed, or used as a default on new forms.',
28
-            'event_espresso'
29
-        ));
30
-        parent::__construct();
31
-    }
20
+	/**
21
+	 * FormStatusEnum constructor.
22
+	 */
23
+	public function __construct()
24
+	{
25
+		$this->setName($this->namespace . 'FormStatusEnum');
26
+		$this->setDescription(esc_html__(
27
+			'Whether form section or element is active, archived, shared, trashed, or used as a default on new forms.',
28
+			'event_espresso'
29
+		));
30
+		parent::__construct();
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * @return array
36
-     */
37
-    protected function getValues(): array
38
-    {
39
-        /** @var FormStatus $form_status */
40
-        $form_status = LoaderFactory::getShared('EventEspresso\core\services\form\meta\FormStatus');
34
+	/**
35
+	 * @return array
36
+	 */
37
+	protected function getValues(): array
38
+	{
39
+		/** @var FormStatus $form_status */
40
+		$form_status = LoaderFactory::getShared('EventEspresso\core\services\form\meta\FormStatus');
41 41
 
42
-        return $form_status->getFormStatusValues();
43
-    }
42
+		return $form_status->getFormStatusValues();
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
      */
23 23
     public function __construct()
24 24
     {
25
-        $this->setName($this->namespace . 'FormStatusEnum');
25
+        $this->setName($this->namespace.'FormStatusEnum');
26 26
         $this->setDescription(esc_html__(
27 27
             'Whether form section or element is active, archived, shared, trashed, or used as a default on new forms.',
28 28
             'event_espresso'
Please login to merge, or discard this patch.