Skip to content
Snippets Groups Projects

Add test with broken property type.

Closed Nikita Malyshev requested to merge issue/drupal-3462156:3462156-unhelpful-php-error into 11.x
1 unresolved thread
Files
2
@@ -81,6 +81,28 @@ public function validateDefinition(array $definition, bool $enforce_schemas): bo
if (($schema['properties'] ?? NULL) === []) {
$schema['properties'] = new \stdClass();
}
// Ensure that all property types are strings. For example, a null value
// will not automatically convert to 'null', which will lead to a PHP error
// that is hard to trace back to the property.
$non_string_props = [];
\array_walk($prop_names, function (string $prop) use (&$non_string_props, $schema) {
$type = $schema['properties'][$prop]['type'];
$types = !\is_array($type) ? [$type] : $type;
$non_string_types = \array_filter($types, static fn (mixed $type) => !\is_string($type));
if ($non_string_types) {
$non_string_props[] = $prop;
}
});
if ($non_string_props) {
throw new InvalidComponentException(\sprintf(
'The component "%s" uses non-string types for properties: %s.',
$definition['id'],
\implode(', ', $non_string_props),
));
}
$classes_per_prop = $this->getClassProps($schema);
$missing_class_errors = [];
foreach ($classes_per_prop as $prop_name => $class_types) {
Loading