Skip to content

Commit

Permalink
bug #1293 [make:entity] don't set array field default value for nulla…
Browse files Browse the repository at this point in the history
…ble column (Rootie)

This PR was squashed before being merged into the 1.0-dev branch.

Discussion
----------

[make:entity] don't set array field default value for nullable column

Setting a default value will lead to a wrong (not nullable) return value of the getter method.

Also setting a default value on a nullable field somehow cancels out the intention of nullable (except for setting it explicitly).

I'm not sure if this should be treated as a bc break. but since no existing properties are overwritten i think it should be fine.

Commits
-------

9c12187 [make:entity] don't set array field default value for nullable column
  • Loading branch information
weaverryan committed Jul 10, 2023
2 parents c283524 + 9c12187 commit c01ac62
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function addEntityField(string $propertyName, array $columnOptions, array
$attributes[] = $this->buildAttributeNode(Column::class, $columnOptions, 'ORM');

$defaultValue = null;
if ('array' === $typeHint) {
if ('array' === $typeHint && !$nullable) {
$defaultValue = new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]);
} elseif ($typeHint && '\\' === $typeHint[0] && false !== strpos($typeHint, '\\', 1)) {
$typeHint = $this->addUseStatementIfNecessary(substr($typeHint, 1));
Expand Down

0 comments on commit c01ac62

Please sign in to comment.