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

Proof of concept: Use a trait for parsers #529

Closed
wants to merge 14 commits into from

Conversation

gmponos
Copy link
Contributor

@gmponos gmponos commented Dec 5, 2018

Made all the parsers use the same code by using a trait..

At my initial commits I made all the parsers use the same code. And then later I replaced the code with a trait.

@frederikbosch made a comment here

I had also thought about the same idea but later on my plan was to submit a PR just like this one.

Marking this trait as internal will also not be inside the BC promise.

@Big-Shark
Copy link

@gmponos Any updates?

@gmponos
Copy link
Contributor Author

gmponos commented May 13, 2019

This could be my fault.. but I need some feedback in order to proceed and finalize this or not.

Neither on the current PR or here I got any feedback.

@Big-Shark
Copy link

@gmponos This is look very nice for me, but I am not scure, why we can not use number_format ?
Yasterday I created this class https://gist.github.com/Big-Shark/84434409e4f4cb6754645ea283e48c74
And all my tests passed.
Can you explorer this?

src/Parser/DecimalParserTrait.php Outdated Show resolved Hide resolved

trait DecimalParserTrait
{
public static $decimalPattern = '/^(?P<sign>-)?(?P<digits>0|[1-9]\d*)?\.?(?P<fraction>\d+)?$/';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a const IMHO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Traits can not have constants :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case, I would make it protected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -16,7 +14,7 @@
*/
final class DecimalMoneyParser implements MoneyParser
{
const DECIMAL_PATTERN = '/^(?P<sign>-)?(?P<digits>0|[1-9]\d*)?\.?(?P<fraction>\d+)?$/';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that removing this constant is probably a BC break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

@sagikazarmark
Copy link
Collaborator

Like the idea! Can you please rebase the branch from master?

@gmponos gmponos mentioned this pull request Dec 28, 2019
@gmponos gmponos changed the title [WIP] Proof of concept: Use a trait for parsers Proof of concept: Use a trait for parsers Jun 22, 2020
@gmponos gmponos marked this pull request as draft June 22, 2020 11:39
@gmponos
Copy link
Contributor Author

gmponos commented Jun 22, 2020

Marked as WIP.. let's merge this first: #586

@frederikbosch
Copy link
Member

Sorry @gmponos, I think we are going to leave this as is. In my opinion traits are to be avoided.

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.

4 participants