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

BUPH-145 | Shared Templates #80

Merged
merged 3 commits into from
Jun 21, 2022
Merged

BUPH-145 | Shared Templates #80

merged 3 commits into from
Jun 21, 2022

Conversation

jpmarcotte
Copy link
Contributor

The important stuff is probably in the 2nd commit.

Definitely looking for feedback on the template strings that get turned into tokens and their usability. I feel like they could be better, but I haven't thought of anything just yet.

@jpmarcotte jpmarcotte self-assigned this Apr 28, 2022
src/V2/Actor.php Show resolved Hide resolved
tests/v2/SharedTemplates/run_test Show resolved Hide resolved
Comment on lines +23 to +25
'NamespacedParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL,
'RelativeParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL,
'ParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I could easily be misunderstanding this

Since ParentActorName is a substring of NamespacedParentActorName (and RelativeParentActorName), NamespacedParentActorName could be naively tokenized into Namespaced**TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL**, right? Based on the logic in the compiler and the docs for str_replace, it looks like the only thing preventing that is that str_replace goes in order of this REPLACEMENTS array, which is manually ordered so that the superstrings come before the substring.

So functionally this looks fine, but I think it would be more of a pit of success to add logic to sort the replacements by length (or you could do the more complicated thing and find the problem pairs to order them)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe at least leave a comment in the code here as to the ordering being important and what the reasoning is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think any time there's a bunch of search/replace things happening, order should always be taken into account. There's just too many edge cases to deal with otherwise. I'll add comments so they aren't as likely to get moved, but that's also why we have tests.

An alternative (not sure how well it would work for the API) is to use something like ShortPrimaryActorName and ShortParentActorName to prevent substrings.

Copy link

@arielallon arielallon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat. this looks solid to me.

src/V2/Actor.php Show resolved Hide resolved
Comment on lines +23 to +25
'NamespacedParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_FULL_PASCAL,
'RelativeParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_RELATIVE_PASCAL,
'ParentActorName' => self::TOKEN_PARENT_ACTOR_NAME_SHORT_PASCAL,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe at least leave a comment in the code here as to the ordering being important and what the reasoning is

@arielallon
Copy link

Looking through the available tokens, I can currently think of other things that we might want.

Base automatically changed from BUPH-142-v2-tests to master June 6, 2022 19:38
@jpmarcotte
Copy link
Contributor Author

I can currently think of other things that we might want.

Such as?

Also, eventually we'll swap these out so they can be more customizable, but I felt like supporting shared templates as a feature was more important.

@arielallon
Copy link

I can currently think of other things that we might want.

Such as?

hahaha woops, that should have said "can't".

@jpmarcotte jpmarcotte merged commit 0437301 into master Jun 21, 2022
@jpmarcotte jpmarcotte deleted the BUPH-145-shared-templates branch June 21, 2022 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants