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

Applying psalm immutable + psalm.level=1 #5

Merged
merged 11 commits into from May 31, 2020
Merged

Conversation

Chemaclass
Copy link
Owner

@Chemaclass Chemaclass commented May 30, 2020

Here I'm trying to get rid of the classes' states in order to make them immutable.

For example, the class SegmentedValues had a property lists which it was mutable: the method fromRaw() was mutating that state(lists: array), instead of having that property, why not create a pure function without side effects? So that's what this PR is about. Getting rid of state mutation in favor of pure functions which doesn't have side effects but returning the value that we want.

In order to get rid of the array<array<string, array<string, SegmentInterface>>> return type, I encapsulate each "transaction message" into the class TransactionMessage, which contains exactly all their grouped segments.

TransactionMessage::groupSegmentsByMessage(SegmentInterface...):list<TransactionMessage>

Doing this approach we don't need to rely on arrays offsets to get their values but a method

TransactionMessage::segmentByName(string):array<string, SegmentInterface>

@Chemaclass Chemaclass added the enhancement New feature or request label May 30, 2020
@Chemaclass Chemaclass self-assigned this May 30, 2020
Copy link
Collaborator

@JesusValera JesusValera left a comment

Choose a reason for hiding this comment

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

Nice way you implement immutability in the classes!

@Chemaclass Chemaclass marked this pull request as ready for review May 31, 2020 09:37
@Chemaclass Chemaclass changed the title [WIP] Applying psalm immutable Applying psalm immutable + psalm.level=1! May 31, 2020
@Chemaclass Chemaclass changed the title Applying psalm immutable + psalm.level=1! Applying psalm immutable + psalm.level=1 May 31, 2020
@Chemaclass Chemaclass merged commit 6a73f4b into master May 31, 2020
@Chemaclass Chemaclass deleted the apply-psalm-immutable branch May 31, 2020 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants