New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umple's PHP method generation fails to create valid method parameters #964

Closed
jblang94 opened this Issue Jan 21, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@jblang94
Contributor

jblang94 commented Jan 21, 2017

Brief Description

When Umple generates PHP code, it fails to adjust method parameters so that they are valid PHP method parameters. To be more exact, the generated PHP code fails to prepend the parameter name with the "$" symbol. As a result, parsing errors occur when PHP attempts to process the generated code.

This was discovered when attempting to fix the "GeometricSystem.ump" UmpleOnline example for PHP compilation in issue #758.

Minimum Steps to Reproduce

Consider the following Umple code

generate Php;

class GeometricObject {

}

class Canvas {
        void paint(GeometricObject g){/*implementation*/}
        void update(GeometricObject g){/*implementation*/}
        void example(boolean b) {}
}

Expected Result

In the generated Canvas.php, for the paint, update, and example, we would expect the following:

public function paint(GeometricObject $g)
{
       /*implementation*/
}

public function update(GeometricObject $g)
{
       /*implementation*/
}

public function example($b)
{
       
}

Actual Result

public function paint(GeometricObject g)
{
       /*implementation*/
}

public function update(GeometricObject g)
{
       /*implementation*/
}

public function example(boolean b)
{
       
}

If a method's parameter is a primitive type in the Umple code (ex. void example(boolean b)), the corresponding generated method in the PHP code should not include the type (ex. public function example($b)) . Otherwise, we keep the method parameter's type in the generated PHP method.

For both cases, the parameter name must be prepended with the "$" symbol.

Primitive types include strings, booleans, integers, floats, doubles, and booleans.

@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Jan 21, 2017

The file needs to be modified is this UmpleToPhp-> UmpleTLTemplates-> class_MethodDeclaration.ump

@nwam nwam self-assigned this Jan 21, 2017

@nwam

This comment has been minimized.

Contributor

nwam commented Jan 22, 2017

Based on PHP's documentation it appears that no special syntax is required for passing an array as an argument:

<?php
function takes_array($input)
{
    echo "$input[0] + $input[1] = ", $input[0]+$input[1];
}
?>

However, it is possible to explicitly declare an argument as an array with the array keyword, but not required.

I am wondering if there are preferences on how this should be performed.

For now, I am commenting out the line

isList = aMethodParam.getIsList() ? " [] " : " ";

from UmpleToPhp/UmpleTLTemplates/class_MethodDeclaration.ump because it will do nothing but cause errors.

I am also wondering what happens when there is a non-primitive array. I didn't find anything too clear in the PHP documentation, but based on comments in my stack overflow post, we must declare the function as function f($c){ ... }. I will implement class_MethodDeclaration.ump to do so for now.

@jblang94 jblang94 referenced this issue Jan 27, 2017

Merged

Fix issue 923 #978

@nwam

This comment has been minimized.

Contributor

nwam commented Jan 27, 2017

Some of the tests which fail when I fixed this issue have method parameters of type int and Integer and the primitive type for PHP is integer. I'll keep the tests like this for now, but the greater concern is that we may want to warn the user if they are using int instead of Umple's generic Integer type.

On top of this, I am wondering why the generated PHP code contains Integer, since Umple's Integer should be generated into PHP's integer. An example of this was found when generating PHP code for cruise.umple/test/cruise/umple/implementation/BasicPrecondition1.ump.

@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Jan 28, 2017

If there are int variables in test cases, your can change it to Integer. However, that test cases might be used in different languages so you need to check those test cases.
what you pointed out is exactly the issue we try to resolve. If a parameter is an Integer, it shouldn't be in generated code for that method. The reason is that in PHP, there is no need to specify the type of primitive types for parameters.

@nwam nwam referenced this issue Jan 28, 2017

Merged

Fix #964 #980

vahdat-ab added a commit that referenced this issue Feb 3, 2017

@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Feb 3, 2017

@jblang94 This issue is closed. If you have issues related to this, you can go head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment