Skip to content
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

Working with nullable properties. #196

Open
todo-username opened this issue Nov 29, 2023 · 4 comments
Open

Working with nullable properties. #196

todo-username opened this issue Nov 29, 2023 · 4 comments
Labels
Bug Something isn't working

Comments

@todo-username
Copy link

Bug Report

Q A
Version(s) 4.13.0

Summary

When creating methods with arguments that accept NULL, an additional '\' character is inserted.

image

Current behavior

When creating methods with arguments that accept NULL, an additional '\' character is inserted.

image

This behavior is most likely due to this method

src/Generator/TypeGenerator/AtomicType.php
image

If you remove the substitution of these characters, the method is generated correctly
image

Most likely, these characters are removed incorrectly if use ClassName is present in the class. If you create properties without the '?' The extra '\' is not added.

How to reproduce

Try creating methods for nullable properties (not primitives).
image

Expected behavior

The method is created without the additional '\' character.

image

@todo-username todo-username added the Bug Something isn't working label Nov 29, 2023
@Ocramius
Copy link
Member

Are you able to write a snippet that runs the generator and reproduces the problem here? I can't understand how laminas/laminas-code is used in your example.

Also, \ArrayCollection is correct if 'ArrayCollection' is given as string. All class names are assumed to be FQCNs, and I'd say that the property not having the \ is more problematic there.

@todo-username
Copy link
Author

Also, \ArrayCollection is correct if 'ArrayCollection' is given as string.

@Ocramius Yes, it is passed as a string, because if you pass the full class path, an additional prefix will be written, which is not needed due to the use of 'use'

image

@todo-username
Copy link
Author

todo-username commented Nov 29, 2023

Are you able to write a snippet that runs the generator and reproduces the problem here? I can't understand how laminas/laminas-code is used in your example.

@Ocramius Can you give an example of a format that will make it easier for you to understand the problem?

@Ocramius
Copy link
Member

Also, \ArrayCollection is correct if 'ArrayCollection' is given as string.

@Ocramius Yes, it is passed as a string, because if you pass the full class path, an additional prefix will be written, which is not needed due to the use of 'use'

laminas/laminas-code explicitly does NOT consider use statements: all symbols are FQN (fully qualified name) references.

More in #176

Can you give an example of a format that will make it easier for you to understand the problem?

The best you can do to reproduce the problem is:

  1. clone this repository
  2. make an example for ClassGenerator (see https://github.com/laminas/laminas-code/blob/fd87696ee3c03073058ee26176d0a7049930fefe/test/Generator/ClassGeneratorTest.php)
  3. make it fail with your scenario, to highlight the expectation differences

BTW, don't paste in screenshots: they are terrible to process :D You can use triple backticks for a code snippet.

That said, I endorse checking #176 first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants