[TOOLS] Add warning to update code in bin/generate_entity_fields

This commit is contained in:
Hugo Sales 2021-12-26 22:16:19 +00:00 committed by Diogo Peralta Cordeiro
parent 93276ce8d0
commit a1a6f5f4fd
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0

View File

@ -27,6 +27,7 @@ $files = array_merge(glob(ROOT . '/src/Entity/*.php'),
glob(ROOT . '/plugins/*/Entity/*.php')));
$classes = [];
$nullable_no_defaults_warning = [];
foreach ($files as $file) {
@ -64,6 +65,9 @@ foreach ($files as $file) {
}
if (($nullable === '?' || \array_key_exists('default', $field_schema)) && $type != '\DateTimeInterface') {
if (!\array_key_exists('default', $field_schema)) {
$nullable_no_defaults_warning[] = "{$class}::{$field}";
}
$default = $field_schema['default'] ?? null;
if (\is_string($default)) {
$default = "'{$default}'";
@ -107,3 +111,10 @@ foreach ($files as $file) {
$out_file = preg_replace("%\\s*{$begin}.*{$end}%smu", $code, $in_file);
file_put_contents($file, $out_file);
}
if (!empty($nullable_no_defaults_warning)) {
echo "Warning: The following don't have a default value, but we're assigning it `null`. Doctrine might not like this, so update it\n";
foreach ($nullable_no_defaults_warning as $n) {
echo " {$n}\n";
}
}