Comments (7)
Interesting you mention the Collection class. I'm actually working on a separate library that does what you describe. :-)
https://github.com/ramsey/collection
The problem is that it is a PHP 5.6+ library only. So, if we wanted to use it and make this change, we'd be looking at doing it in a version 4.0 of ramsey/uuid, where we set the lowest PHP version to 5.6.
from uuid.
I think since it would be a breaking change anyway, that would make sense, right?
What prevents that library from working in <5.6?
from uuid.
Nothing right now, I think. It was more a decision to move forward and not support older versions of PHP.
from uuid.
Calling dibs on this one
from uuid.
A quick analysis results in the following data:
- There appear to be 8 occurrences of
array
being used as a type hint within the src directory. - 5 of those occurrences expect the
$fields
variable, an associative array whose structure is documented in the docblock forRamsey\Uuid\UuidInterface::getFieldsHex()
- 1 is the
$components
argument inRamsey\Uuid\Codec\StringCodec::getFields()
which does not seem to be documented - 1 is the
$providers
argument for theFallbackNodeProvider
which is discussed in the begin of this thread. It expects an array ofNodeProviderInterface
instances. - the last occurrence is the
$timestamp
argument for theFixedTimeProvider
constructor. The docblock states that it is an array containing two elements: thesec
andusec
components of a timestamp.
In the cases where an associative array is expected, I would recommend the use of value objects. For instance, the $fields
value should be a value object that can ensure that it always contains the required fields. The value object itself is responsible for validation of data, and every method that type hints on that value object can be sure that it is valid.
The FallbackNodeProvider
appears to be the only actual collection (of homogeneous elements). We can go two ways: either create a collection class (NodeProviderCollection
) that ensures that it only contains elements of type NodeProviderInterface
. Or, in the FallbackNodeProvider
's constructor, we ensure that the array contains only elements of said type. I recommend the last option. While a collection class is more explicit, it also introduces more boilerplate (and the docblock type hint is probably explicit enough). In either case, we could use Benjamin Eberlei's Assert library to ensure that all elements of the array are of the same type in a clean way (this library adds much more input validation options, by the way). It will throw an InvalidArgumentException
if the assertion fails.
from uuid.
I agree with introducing a value object for the $fields
and your recommendation for checking the array values in the FallbackNodeProvider
.
from uuid.
In the cases where an associative array is expected, I would recommend the use of value objects. For instance, the $fields value should be a value object that can ensure that it always contains the required fields.
In the 4.x
branch, the fields are now represented by a value object. See here: https://github.com/ramsey/uuid/blob/4.x/src/Rfc4122/Fields.php
from uuid.
Related Issues (20)
- Misused Psalm Assertion for isValid() method? HOT 8
- Is there a way to force Uuid serialize to string instead of bytes ? HOT 7
- Could not find branch v5.x-dev anymore HOT 5
- Bad tag for 4.7.2 ? HOT 2
- ramsey/collection dependency requires PHP 8.1. HOT 2
- Ramsey\Uuid\Nonstandard namespace conflicts with itself in standalone builds HOT 2
- Unserialize error with OrderedTimeCodec HOT 2
- Remove the deleted tag in packagist.org HOT 3
- Deprecated: Return type of Ramsey\Uuid\Uuid::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): HOT 5
- Bump Bump brick/math from ^0.10 to ^0.11 HOT 2
- Mariadb 10.7+ uuid v7 sort HOT 1
- Interface 'Ramsey\Uuid\Provider\TimeProviderInterface' not found HOT 1
- Uuid v7 collisions HOT 9
- Deprecated Implements of Serializable in UuidInterface HOT 1
- Use a PSR clock for internal time management?
- Update brick/math to support v0.12.0
- Inconsistent results between fromString and isValid methods. HOT 2
- Uuid v7 generated in wrong order HOT 3
- Why doesn't this library use `hrtime()` for monotonicity? HOT 1
- Where is uuid7 method ?? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid.