nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

Option to set or overwrite a method. #152

Closed kosciuk closed 8 months ago

kosciuk commented 9 months ago

hello, if I try to edit a file, I have no way to keep a method and overwrite others, as there is "setMethods" which does a $methods = [].

I think there may be a setMethod() or overwriteMethod() that allows to add without deleting everything.

// copied from addMethod
public function setMethod(Method $method): static
{
    $lower = strtolower($method->getName());
    if (isset($this->methods[$lower])) {
        throw new Nette\InvalidStateException("Cannot add method '$name', because it already exists.");
    }
    if (!$this->isInterface()) {
        $method->setPublic();
    }

    return $this->methods[$lower] = $method;
}

This problem arose when doing a diff between the methods of a class.

I think it is important to have automatically generated files that can be edited by the programmer and the generator without losing data.

kosciuk commented 9 months ago

update.php.txt the problem is in line 47, when I delete a method to insert it again with the changes.

kosciuk commented 8 months ago

Thanks!