phpowermove / php-code-generator

PHP code generator library
https://php-code-generator.readthedocs.org
Apache License 2.0
147 stars 43 forks source link

addSimpleParameter and addSimpleDescParameter functions #40

Closed cristianoc72 closed 7 years ago

cristianoc72 commented 7 years ago

In gossi\codegen\model\parts\ParameterParts trait, addSimpleParameterand addSimpleDescParameter functions don't accept anymore arrays as default value.

<?php

$function = new PhpFunction();
$function->addSimpleDescParameter('param1', 'array', 'desc', array());

This use case throws an Exception, because at https://github.com/gossi/php-code-generator/blob/master/src/model/parts/ParametersPart.php#L82 and at https://github.com/gossi/php-code-generator/blob/master/src/model/parts/ParametersPart.php#L105 the instructions accept only primitive values.

Is it a desired behavior? If yes, I'll refactor some Propel classes, otherwise I can submit a fix.

marcj commented 7 years ago

Yeah, unfortunately, they changed it.

This is why I added a MethodDefinition that extends Propel\Generator\Builder\PhpModel in Propel2: https://github.com/propelorm/Propel2/blob/data-mapper/src/Propel/Generator/Builder/PhpModel/MethodDefinition.php#L17

cristianoc72 commented 7 years ago

@marcj My fix is buggy: getExpression function must return a string, otherwise the writer can't correctly write down the class. I'm workingon it.

gossi commented 7 years ago

Yes, this is changed, because it was to unreliable to generate what kind of value you put in, see here: https://php-code-generator.readthedocs.io/en/latest/model.html#understanding-values

gossi commented 7 years ago

I'd say you should avoid using addSimpleParameter methods. Since the introduction of values and expressions, these methods are unreliable in what you want and they stand out of the rest of the API, they should go deprecated in the next versions. You should build your own wrapper or shortcut function for your own use-case, I think that's way better.