Skip to content

Conversation

@sad-spirit
Copy link
Contributor

@sad-spirit sad-spirit commented Sep 28, 2025

This implements the new class-level #[NamePrefix] and #[Camelize] attributes as described in request #17

Additionally, having more than one #[Identifier] attribute on DTO class level will cause an exception, as was probably intended.

Fixes #17

@Pixelshaped
Copy link
Owner

Pixelshaped commented Oct 1, 2025

@sad-spirit Yo! I've reviewed your code which is fine, but I'd like to discuss things a bit if that's ok with you.
Instead of having two attributes NamePrefix and Camelize, what about only one, but which would convey modifiers (could maybe be named Modifier or PropertyModifier or PropertyNameModifier?)?

Also, not a fan of the method name manglePropertyName as mangle conveys an idea of chaos (def: "destroy or severely damage by tearing or crushing"). What about just "modifyPropertyName"? Which could coincidentally work well with a Modifier attribute?

Otherwise nice job and thanks for contributing. Sorry again for the delay in my answers. I reactivated email notifications, I should be more responsive starting now.

@sad-spirit
Copy link
Contributor Author

Instead of having two attributes NamePrefix and Camelize, what about only one, but which would convey modifiers (could maybe be named Modifier or PropertyModifier or PropertyNameModifier?)?

Maybe NameTransformation? We are not actually modifying the property or its name, we are transforming column names to property names.

So it will look like #[NameTransformation(camelize: true)] / #[NameTransformation(removePrefix: 'foo_')] / #[NameTransformation(removePrefix: 'foo_', camelize: true)], with other options possible later.

Also, not a fan of the method name manglePropertyName as mangle conveys an idea of chaos (def: "destroy or severely damage by tearing or crushing"). What about just "modifyPropertyName"? Which could coincidentally work well with a Modifier attribute?

You are right, I could choose a better name. Same as above, I'd suggest transformPropertyName().

I reactivated email notifications, I should be more responsive starting now.

👍

@Pixelshaped
Copy link
Owner

Maybe NameTransformer? '-tion' indicates a result, whether '-er' indicates an action. Otherwise we're aligned. Thanks again!

@sad-spirit
Copy link
Contributor Author

Maybe NameTransformer? '-tion' indicates a result, whether '-er' indicates an action.

The attribute does not perform any actions, it just specifies which actions to perform. NameTransformer is a good name for a class that will contain the transformPropertyName() method if that is ever extracted from FlatMapper.

I'll update the pull request (and fix the CI failures).

@sad-spirit sad-spirit changed the title NamePrefix and Camelize class-level attributes NameTransformation class-level attribute Oct 1, 2025
@Pixelshaped
Copy link
Owner

I think it's 99% mergeable, nicely done. Do you think you could test removePrefix and camelize in isolation (at least one of them) to illustrate independence of behavior?

@sad-spirit
Copy link
Contributor Author

Do you think you could test removePrefix and camelize in isolation (at least one of them) to illustrate independence of behavior?

That's mostly done already: note that AuthorDTO class used in the test has only removePrefix enabled: #[NameTransformation(removePrefix: 'author_')], while BookDTO has both options: #[NameTransformation(removePrefix: 'book_', camelize: true)].

@Pixelshaped
Copy link
Owner

It sort of is... Let's merge this and I'll add more tests whenever (to cover also the error that happens when two Identifier attributes are used). Thanks again!

@Pixelshaped Pixelshaped merged commit 7c8f66c into Pixelshaped:main Oct 1, 2025
1 check passed
@sad-spirit
Copy link
Contributor Author

Thanks! What I actually forgot is a test for #[Scalar] attribute overriding whatever was created by #[NameTransformation] 😞

@Pixelshaped
Copy link
Owner

Ha yes the overriding was mentioned in the docs and I forgot to tell you about it. Maybe make a small pr when you have the time, no worries.

Coverage also took a small hit https://app.codecov.io/gh/Pixelshaped/flat-mapper-bundle/commit/7c8f66c683a6979b36a0c2e5d373c7e363092ff5 but it shouldn't be too hard to cover that back.

@sad-spirit sad-spirit deleted the class-level-attributes branch October 3, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class-level attributes for DTOs?

2 participants