php-code-builder icon indicating copy to clipboard operation
php-code-builder copied to clipboard

Extending php code builder features

Open GeorgII-web opened this issue 8 months ago • 0 comments

Hello, respectful maintainers!

Great tool. Is it possible to extend the PHP Builder to make classes with a more strict typing?

Trying to generate a class that will validate values not only at the end, but for every property. The problem is: only in a runtime it will fail on validation, but I would like to have a proper PSALM static analysis and type hinting on IDE, before running any code.

Method setId() should guarantee positive-int value even before code "compiled", and as a bonus, fail on setting an invalid value.

Like this:

    /**
     * @param positive-int $id
     */
    public function setId(int $id): self
    {
        \Webmozart\Assert\Assert::greaterThan($id, 0);
        $this->id = $id;
        return $this;
    }

I may try to add this functionality, but need some help, an entry point. Thank you anyway

GeorgII-web avatar May 16 '25 11:05 GeorgII-web