Commit Graph

86 Commits

Author SHA1 Message Date
Ben Ramsey d7379b67af test: update exception message for PHP 8.1 2021-08-06 14:35:42 -05:00
Ben Ramsey c005f69d6e chore: update package files 2021-08-06 14:05:57 -05:00
Bilge 7947413a76 Use assertSame instead of assertEquals. 2020-08-23 13:53:19 +01:00
Marco Pivetta b805572537 Ensure that Uuid::uuidX() generators produce instances equivalent to Uuid::fromString() and Uuid::fromBytes()
With this change, `Uuid::uuid1()`, `Uuid::uuid2()` and so forth now produce a `LazyUuidFromString` instance, which
is both more memory efficient and comparable to `Uuid::fromString()` instances in other tools, such as within
PHPUnit's `Assertion::assertEqual()`, which would reject any two objects not matching each other's types.

Before this patch, `Assertion::assertEquals(Uuid::uuid5(...), Uuid::fromString(...))` would always fail due to
different subtypes produced by the two factory methods.
2020-07-09 13:57:30 +02:00
Marco Pivetta 1f0cd71d93 Applied fixes and suppressions (sadly) to match psalm/phpstan code quality guidelines
We have a lot of deprecated API in here which shouldn't exist in first place, but that
will luckily disappear with v5.0.0 :-)
2020-07-09 13:57:30 +02:00
Marco Pivetta 1ce3f55673 Applied automated CS fixes according to project CS settings 2020-07-09 13:57:30 +02:00
Marco Pivetta 569e93ac4e Re-implemented Uuid::fromString() so it produces a LazyUuidFromString when possible
This should speed up `Uuid::fromString()` massively, leading to much shallower execution
paths when `toString()` and similar simplistic API is required.
2020-07-09 13:57:30 +02:00
Ben Ramsey 22ee596348 Make serialize(UuidInterface) more compact
Resolves #318
2020-07-08 15:27:19 -05:00
Ben Ramsey ba7c1c17ce Add more tests for UuidV6 2020-02-24 15:14:57 -06:00
Ben Ramsey fec93008bc Accept Type\Hexadecimal for the first parameter to uuid1() 2020-02-24 14:34:40 -06:00
Ben Ramsey ab3c89fb8e Change the $node parameter from mixed to ?Hexadecimal 2020-02-24 13:44:03 -06:00
Ben Ramsey cc2bf6f8ef Support version 6 UUIDs
See the following:

* https://github.com/uuid6/uuid6-ietf-draft
* http://gh.peabody.io/uuidv6/
2020-02-22 22:41:15 -06:00
Ben Ramsey 65b0c091c0 Deprecate VALID_PATTERN, UUID_TYPE_IDENTIFIER; suggest replacements 2020-02-21 13:37:06 -06:00
Ben Ramsey a7cf07a2d8 Fix microsecond rounding error on 32-bit systems 2020-02-21 02:51:31 -06:00
Ben Ramsey e0ff858ff6 Return Hexadecimal from getHex() and IntegerValue from getInteger() 2020-02-21 01:40:14 -06:00
Ben Ramsey 7af4814017 Round microseconds to six digits when getting DateTime from v1 UUIDs 2020-02-21 01:17:05 -06:00
Ben Ramsey 4a44aeab2e Add a test for the Unix epoch with v1 UUIDs 2020-02-20 17:23:32 -06:00
Ben Ramsey 5f0850c7b5 Add an additional test for last possible date for a v1 UUID 2020-02-20 17:03:08 -06:00
Ben Ramsey fb4f54fb84 Address static analysis issues 2020-02-08 13:14:17 -06:00
Ben Ramsey 0bff9e8660 Add NameGeneratorInterface and generators for v3 and v5 UUIDs 2020-02-08 13:12:20 -06:00
Marco Pivetta a252f29847 Import used functions and constants via use statement to disallow ambiguity for compiler/static-analysis
As documented in https://wiki.php.net/rfc/use_global_elements, the engine (by default) does a local namespace
lookup, then falls back to global namespace when first calling a global function referenced in namespaced code,
unless that function is referenced via fully qualified name (FQN).

By using the FQN, the actual symbol can be looked up at compile-time, both by the PHP engine and by static analysis
tooling, allowing for compiler (in particular) optimizations to replace known hot-path functions with specialized opcodes.

Sadly, no actual benchmark at hand: the improvements can be minimal or massive, depending on where this library is
used (tight loops being most relevant).
2020-02-03 13:15:35 -06:00
Ben Ramsey 5fa4eb4f17 Add fromDateTime() to create version 1 UUIDs from DateTime instances
Fixes #28
2020-02-03 00:48:41 -06:00
Ben Ramsey a5c7314f8d Fix string passed to DateTimeImmutable 2020-01-20 21:04:26 -06:00
Ben Ramsey a8d52100de Support microtime in returned DateTimeInterface instances
Fixes #90 and supersedes #93.
2020-01-19 23:21:48 -06:00
Ben Ramsey 268e66aad8 Add static Uuid::uuid2() method 2020-01-18 14:14:47 -06:00
Ben Ramsey 8202946225 Add NilUuid concrete class to represent nil UUIDs 2020-01-18 12:14:01 -06:00
Ben Ramsey d21a3e3875 Add tests to ensure static methods return specific UUID types 2020-01-18 12:14:01 -06:00
Ben Ramsey 5d1f106882 Rename Validator\Validator to Validator\GenericValidator 2020-01-18 12:14:00 -06:00
Ben Ramsey 2ad77d9ca7 Remove CalculatorInterface as a Uuid constructor parameter 2020-01-18 12:14:00 -06:00
Ben Ramsey 360261d617 Deprecate all the fields methods on UuidInterface and Uuid 2020-01-18 12:14:00 -06:00
Ben Ramsey 10624f64a1 Change return type of Uuid::getFields() to FieldsInterface 2020-01-18 12:14:00 -06:00
Ben Ramsey c11c023796 Address static analysis issues and add additional tests 2020-01-18 12:13:59 -06:00
Ben Ramsey f5cfb5f57d Split known v3 and v5 UUID tests into providers 2020-01-18 12:13:59 -06:00
Ben Ramsey d543895369 Return string integers instead of int integers 2020-01-18 12:13:58 -06:00
Ben Ramsey 63942c393d Remove Gmp converters; the generic converters are preferred 2020-01-18 12:13:58 -06:00
Ben Ramsey ebaa04a6b2 Improve coverage and unit tests for fields, GUIDs, and nonstandard UUIDs 2020-01-18 12:13:57 -06:00
Ben Ramsey 70eace9086 Introduce separate classes to handle nonstandard UUIDs 2020-01-18 12:13:57 -06:00
Ben Ramsey d6ed9b3832 Introduce separate class support for GUIDs 2020-01-18 12:13:57 -06:00
Ben Ramsey d4dd45e908 Apply fields functionality to Uuid class 2020-01-18 12:13:57 -06:00
Ben Ramsey 12896f06db Use internal exceptions
Fixes #254
2020-01-18 12:13:55 -06:00
Ben Ramsey 0d7b8c2b7a Update coding style to include PSR-12, among other options
This also includes heavy use of slevomat/coding-standard to apply
various checks to the code, based on maintainer (me) preference.
2020-01-18 12:13:55 -06:00
Ben Ramsey 0721630ba4 Refactor converters to uniformly accept and return string values 2020-01-18 12:13:09 -06:00
Ben Ramsey 81f0f9a9b4 Clean-up tests and use PHPStan max level for tests 2020-01-18 12:13:09 -06:00
Carlos Barrero 650cb9f545 Change getDateTime to DateTimeInterface 2020-01-18 12:13:09 -06:00
Julian Ecknig 4de1348099 Add GmpConverter and GmpTimeConverter 2020-01-18 12:13:09 -06:00
Bradyn Poulsen 3cf759ad05 Migrate isValid() to Validator and ValidatorInterface
* Maintain backwards compatibility with the former Uuid::isValid() and
  Uuid::VALID_PATTERN
* Remove the assert statements in favor of str_replace and preg_match
* Make the validator a featureset of the factory
* Remove old suggestion about locations of constants
* Remove argument count assertions
* Remove VALID_PATTERN from Uuid
2020-01-18 12:13:08 -06:00
SignpostMarv 0030399564 Increase PHPStan levels and update code to resolve issues found 2020-01-18 12:13:08 -06:00
Martin Hujer ca2629767d Require phpstan and correct issues found up to level 2
* issues found by phpstan L0
* issues found by phpstan L1
* issues found by phpstan L2 in src/
* issues found by phpstan L2 in tests/
2020-01-18 12:13:08 -06:00
Ben Ramsey 5d7ee63f1c Update dev requirements and test suite for PHP 7+ only 2020-01-18 12:13:07 -06:00
Martin Hujer 049d5acf7a Use ::class constants where possible
It helps with refactorings and static analysis, because you can easily
tell if the class is missing or not.
2020-01-18 12:13:07 -06:00