Skip to content

[enhancement] generate entity constructors with all non-nullable properties #73

Open
@Evertt

Description

@Evertt

If my schema.yml says this:

Product:
  parent: false
  properties:
    name: { nullable: false }

Then I would love it if my generated Product.php then contains a constructor function which requires the $name property. Like this:

// src/AppBundle/Entity/Product.php

class Product
{
    // ...

    public function __construct(string $name)
    {
        $this->setName($name);
        // using the setter that already exists
        // so we can utilize any validation that that method might have
    }

    // ...
}

That way you can guarantee when I or another developer wants to initialize a new Product, that it will be a valid entity right after initialization.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions