Skip to content

Commit de6a88a

Browse files
committed
Improve method param typing
1 parent 350375c commit de6a88a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

templates/php/src/Services/Service.php.twig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,29 @@ class {{ service.name | caseUcfirst }} extends Service
3939
*
4040
{% endif %}
4141
{% for parameter in method.parameters.all %}
42-
* @param {{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}
42+
* @param {% if not parameter.required or parameter.nullable %}?{% endif %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}
4343
{% endfor %}
4444
* @throws {{spec.title | caseUcfirst}}Exception
4545
* @return {{ method | getReturn }}
46-
4746
*/
48-
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
47+
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if not parameter.required or parameter.nullable %}?{% endif %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
4948
{
50-
$apiPath = str_replace([{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}], [{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}], '{{ method.path }}');
49+
$apiPath = str_replace(
50+
[{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}],
51+
[{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}],
52+
'{{ method.path }}'
53+
);
5154
5255
{{~ include('php/base/params.twig') -}}
5356
{%~ if 'multipart/form-data' in method.consumes %}
5457
{{~ include('php/base/requests/file.twig') }}
5558
{%~ else %}
59+
5660
{{~ include('php/base/requests/api.twig') }}
5761
{%~ endif %}
5862
}
5963
{%~ if not loop.last %}
6064
6165
{%~ endif %}
6266
{%~ endfor %}
63-
}
67+
}

0 commit comments

Comments
 (0)