!jngDrdMgndWibPCYsR:nixos.org

Nix PHP

82 Members
A room for PHP developers running on Nix24 Servers

Load older messages


SenderMessageTime
3 Oct 2022
@drupol:matrix.orgPol Was it related to the class RandomNodeService of ramsey/identifier ? 17:43:26
@drupol:matrix.orgPolI guess this is the reason why you didn't do:17:43:36
@drupol:matrix.orgPolimage.png
Download image.png
17:43:39
@ramsey:matrix.orgramseyYes17:45:43
@drupol:matrix.orgPolAh right, so, you can discard my screenshot then :)17:46:02
@ramsey:matrix.orgramseyWell... sort of. It was about using that class within another class that's immutable17:46:03
@drupol:matrix.orgPolOkay17:46:23
@ramsey:matrix.orgramseyIt 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.orgPolOh... what's the best pattern there?17:49:23
@ramsey:matrix.orgramseyI 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.orgramsey So, I removed the @psalm-immutable annotation 🙂 17:50:05
@drupol:matrix.orgPolHaving a look.17:50:40
@drupol:matrix.orgPolIt's weird because no property is being modified.17:51:10
@ramsey:matrix.orgramsey Right, but random_bytes() and random_int() mutate the state of the machine 17:51:32
@ramsey:matrix.orgramseyso, the class performs mutating operations17:51:48
@drupol:matrix.orgPolYeah but you do not modify the class itself, so psalm shouldn't complain IMHO17:52:06
@drupol:matrix.orgPolGoing to make some experimentations :)17:52:17
@ramsey:matrix.orgramseyPsalm complains because an immutable class shouldn't mutate state anywhere (internally or externally)17:52:36
@drupol:matrix.orgPol Maybe you should not create the $bytes variable there, just pass the random service to Binary::applyVersionAndVariant 17:53:58
@drupol:matrix.orgPolSomething like that?17:54:35
@drupol:matrix.orgPolimage.png
Download image.png
17:54:37
@ramsey:matrix.orgramsey it would still be mutating the state of the machine when it creates the bytes in applyVersionandVariant() 17:54:44
@drupol:matrix.orgPolmmh17:54:50
@ramsey:matrix.orgramseyYou'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.orgPolTrue.17:55:36
@drupol:matrix.orgPolYou have to leave it to the user17:55:44
@ramsey:matrix.orgramsey but that's a cumbersome API, so I'll just not put @psalm-immutable on the class 🙂 17:55:52
@drupol:matrix.orgPolTrue.17:55:58
@drupol:matrix.orgPolAnd doing this?17:57:02
@drupol:matrix.orgPolimage.png
Download image.png
17:57:03

Show newer messages


Back to Room ListRoom Version: 6