Commit Graph

78 Commits

Author SHA1 Message Date
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
Ben Ramsey 231027100a Increase microseconds in another test to ensure enough time passes 2019-12-06 14:54:08 -08:00
Ben Ramsey 9e48187656 Add slightly more sleep to ensure timestamps don't collide 2019-12-04 17:09:13 -08:00
Ben Ramsey 64ba9a2767 Clean up code according to PhpStorm inspections report 2019-11-30 13:14:52 -08:00
Lee Boynton 2804748423 Don't allow UUIDs to have trailing newline 2018-05-02 18:54:33 +01:00
Ben Peachey dbb9a8b6d1 Changes all usage in Tests of getMock with getMockBuilder. 2017-10-17 12:46:25 +02:00
Davis Peixoto 46071e69a1 173 - Expose UUID versions - Alternative 1
https://github.com/ramsey/uuid/issues/173

Creating constants on Uuid object, so they can be used as
- Uuid::UUID_TYPE_TIME
- Uuid::UUID_TYPE_RANDOM

# Alternative 1
Create constants on Uuid class

Signed-off-by: Davis Peixoto <davis.peixoto@gmail.com>
2017-08-03 21:12:10 -03:00
Davis Peixoto 0915c7bdc2 173 - Expose UUID versions - Alternative 1
https://github.com/ramsey/uuid/issues/173

Creating constants on Uuid object, so they can be used as
- UUID::UUID_TYPE_TIME
- UUID::UUID_TYPE_RANDOM

# Alternative 1
Create constants on Uuid class

Signed-off-by: Davis Peixoto <davis.peixoto@gmail.com>
2017-08-02 08:55:26 -03:00
Massimiliano Arione a2647abc14 add a specific exception for invalid UUID string 2017-03-11 10:52:53 +01:00