!jngDrdMgndWibPCYsR:nixos.org

Nix PHP

74 Members
A room for PHP developers running on Nix21 Servers

Load older messages


SenderMessageTime
3 Oct 2022
@drupol:matrix.org@drupol:matrix.org Was it related to the class RandomNodeService of ramsey/identifier ? 17:43:26
@drupol:matrix.org@drupol:matrix.orgI guess this is the reason why you didn't do:17:43:36
@drupol:matrix.org@drupol:matrix.orgimage.png
Download image.png
17:43:39
@ramsey:matrix.org@ramsey:matrix.orgYes17:45:43
@drupol:matrix.org@drupol:matrix.orgAh right, so, you can discard my screenshot then :)17:46:02
@ramsey:matrix.org@ramsey:matrix.orgWell... sort of. It was about using that class within another class that's immutable17:46:03
@drupol:matrix.org@drupol:matrix.orgOkay17:46:23
@ramsey:matrix.org@ramsey:matrix.orgIt was about trying to designate the UUID factories as immutable, but I can't do that because I'm using that random service here: https://github.com/ramsey/identifier/blob/cd0fb1c321bf3c3c1fd418a3318f5904b3a8e9c3/src/Uuid/Factory/UuidV4Factory.php#L5217:47:48
@drupol:matrix.org@drupol:matrix.orgOh... what's the best pattern there?17:49:23
@ramsey:matrix.org@ramsey:matrix.orgI don't know. It technically mutates the state of the randomizer on the machine, so the class can't be considered immutable17:49:53
@ramsey:matrix.org@ramsey:matrix.org So, I removed the @psalm-immutable annotation 🙂 17:50:05
@drupol:matrix.org@drupol:matrix.orgHaving a look.17:50:40
@drupol:matrix.org@drupol:matrix.orgIt's weird because no property is being modified.17:51:10
@ramsey:matrix.org@ramsey:matrix.org Right, but random_bytes() and random_int() mutate the state of the machine 17:51:32
@ramsey:matrix.org@ramsey:matrix.orgso, the class performs mutating operations17:51:48
@drupol:matrix.org@drupol:matrix.orgYeah but you do not modify the class itself, so psalm shouldn't complain IMHO17:52:06
@drupol:matrix.org@drupol:matrix.orgGoing to make some experimentations :)17:52:17
@ramsey:matrix.org@ramsey:matrix.orgPsalm complains because an immutable class shouldn't mutate state anywhere (internally or externally)17:52:36
@drupol:matrix.org@drupol:matrix.org Maybe you should not create the $bytes variable there, just pass the random service to Binary::applyVersionAndVariant 17:53:58
@drupol:matrix.org@drupol:matrix.orgSomething like that?17:54:35
@drupol:matrix.org@drupol:matrix.orgimage.png
Download image.png
17:54:37
@ramsey:matrix.org@ramsey:matrix.org it would still be mutating the state of the machine when it creates the bytes in applyVersionandVariant() 17:54:44
@drupol:matrix.org@drupol:matrix.orgmmh17:54:50
@ramsey:matrix.org@ramsey:matrix.orgYou'd have to create the bytes outside the class and then pass them into the class in order to keep the class immutable17:55:25
@drupol:matrix.org@drupol:matrix.orgTrue.17:55:36
@drupol:matrix.org@drupol:matrix.orgYou have to leave it to the user17:55:44
@ramsey:matrix.org@ramsey:matrix.org but that's a cumbersome API, so I'll just not put @psalm-immutable on the class 🙂 17:55:52
@drupol:matrix.org@drupol:matrix.orgTrue.17:55:58
@drupol:matrix.org@drupol:matrix.orgAnd doing this?17:57:02
@drupol:matrix.org@drupol:matrix.orgimage.png
Download image.png
17:57:03

Show newer messages


Back to Room ListRoom Version: 6