| 3 Oct 2022 |
ramsey | Well... sort of. It was about using that class within another class that's immutable | 17:46:03 |
Pol | Okay | 17:46:23 |
ramsey | It 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#L52 | 17:47:48 |
Pol | Oh... what's the best pattern there? | 17:49:23 |
ramsey | I don't know. It technically mutates the state of the randomizer on the machine, so the class can't be considered immutable | 17:49:53 |
ramsey | So, I removed the @psalm-immutable annotation 🙂 | 17:50:05 |
Pol | Having a look. | 17:50:40 |
Pol | It's weird because no property is being modified. | 17:51:10 |
ramsey | Right, but random_bytes() and random_int() mutate the state of the machine | 17:51:32 |
ramsey | so, the class performs mutating operations | 17:51:48 |
Pol | Yeah but you do not modify the class itself, so psalm shouldn't complain IMHO | 17:52:06 |
Pol | Going to make some experimentations :) | 17:52:17 |
ramsey | Psalm complains because an immutable class shouldn't mutate state anywhere (internally or externally) | 17:52:36 |
Pol | Maybe you should not create the $bytes variable there, just pass the random service to Binary::applyVersionAndVariant | 17:53:58 |
Pol | Something like that? | 17:54:35 |
Pol |  Download image.png | 17:54:37 |
ramsey | it would still be mutating the state of the machine when it creates the bytes in applyVersionandVariant() | 17:54:44 |
Pol | mmh | 17:54:50 |
ramsey | You'd have to create the bytes outside the class and then pass them into the class in order to keep the class immutable | 17:55:25 |
Pol | True. | 17:55:36 |
Pol | You have to leave it to the user | 17:55:44 |
ramsey | but that's a cumbersome API, so I'll just not put @psalm-immutable on the class 🙂 | 17:55:52 |
Pol | True. | 17:55:58 |
Pol | And doing this? | 17:57:02 |
Pol |  Download image.png | 17:57:03 |
Pol | But that is not what you want right? | 17:57:42 |
Pol | (you told me on Twitter) | 17:57:48 |
ramsey | it's the same problem... because the class calls random_bytes() either directly or indirectly, it is mutating the machine's state | 17:58:30 |
Pol | Doah. Right. | 17:58:38 |
| 4 Oct 2022 |
Jan Tojnar | I wonder if we could make the flake update action trigger on the channel advancement | 20:28:54 |