Commit Graph

247 Commits

Author SHA1 Message Date
Ben Ramsey ffc400e009 Change UuidInterface::getInteger() to always return a string value 2020-01-18 12:13:56 -06:00
Ben Ramsey b7f9dc5010 Check for RFC 4122, version 1 UUIDs with OrderedTimeCodec 2020-01-18 12:13:56 -06:00
Barney Laurance bdc9170edc Run Psalm on src as well as Static Analysis Fixture (#282)
* Run Psalm on src as well as Static Analysis Fixture

Psalm baselining feature is used to prevent immediate build failures -
psalm will just cause failures for errors caused by future changes to
the code.

See https://psalm.dev/docs/running_psalm/dealing_with_code_issues/#using-a-baseline-file

* Fix MixedArgument issues in OrderedTimeCodec

Potentially unpack should be documented as returning string[] instead of
array to make this unecassary.

* Fix Psalm PossiblyNullPropertyAssignmentValue issues

* Add psalm-immutable annotation to Uuid class

* Fix Psalm MixedArgument issues

* Fix MissingImmutableAnnotation psalm issue

* Fix Psalm MixedAssignment issue

* Fix Psalm InvalidReturnStatement / InvalidReturnType issue

* Add ImpureMethodCall issues to baseline.

Fixing these in one place just moves them somewhere else.

* Exclude psalm-baseline.xml from exported git archives
2020-01-18 12:13:56 -06:00
Marco Pivetta d01922dd14 Marked minimal parts of UuidInterface and Uuid named constructors as pure/immutable
This change is the minimum requirement to make the static analysis suite pass checks
on immutability/purity invariants of a `Uuid` and `UuidInterface`: it doesn't ensure
that internals of `Uuid` are pure. That will need deprecation of `Uuid::setFactory()`,
as well as marking any types referenced in private state as `@psalm-immutable` too.

That's out of scope for the current patch, which provides a good 80/20 split on purity
invariants for most (even advanced) UUID downstream users.
2020-01-18 12:13:55 -06:00
Marco Pivetta 667d42b5ce UuidInterface#getInteger() should return a string as per pre-existing declaration 2020-01-18 12:13:55 -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
Massimiliano Arione 5459113b81 add typehints and return types 2020-01-18 12:13:10 -06:00
Ben Ramsey 0721630ba4 Refactor converters to uniformly accept and return string values 2020-01-18 12:13:09 -06:00
Carlos Barrero 650cb9f545 Change getDateTime to DateTimeInterface 2020-01-18 12:13:09 -06:00
Ben Ramsey 5f2eaa6d2d Add __toString() to UuidInterface
Resolves #111
2020-01-18 12:13:09 -06:00
Ben Ramsey 8544df0f40 Remove the MtRandGenerator 2020-01-18 12:13:09 -06:00
Ben Ramsey 05f3f16158 Remove the OpenSslGenerator 2020-01-18 12:13:09 -06:00
André Filipe bdfbf64a10 Removed some else/elseif and added some early returns to make the code a little easier to read, nothing changes on the big picture 2020-01-18 12:13:09 -06:00
Alessandro Minoccheri b234bec5b9 change array declarations 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
Ben Ramsey 506135cc6e Remove SodiumRandomGenerator generator class; it is no longer necessary 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
Mathieu TUDISCO e535e89708 Fix typo 2020-01-17 10:16:13 -06:00
Ben Ramsey da6fcde177 Add tests to ensure consistent behavior from 3.x to 4.x 2020-01-08 16:47:00 -06:00
Ben Ramsey b39ec78f6e Check whether sysfs is readable before attempting to read it
Fixes #260
2019-12-17 02:01:14 -06:00
Ben Ramsey 692175901d Fix RandomNodeProvider behavior on 32-bit systems
The 6 bytes obtained from `random_bytes()` is a 48-bit integer, which
cannot be converted to decimal on a 32-bit system, without being
implicitly cast to a float by PHP. This was causing problems with
setting the multicast bit, and it led to non-random node values.

This new approach splits the 6 bytes up into two 3-byte values, each a
24-bit integer, and applies the multicast bit to the most significant
bits before re-combining the bytes as a string.
2019-11-30 20:26:42 -08:00
André Filipe 84fe6cf755 Removed some else/elseif and added some early returns to make the code a little easier to read, nothing changes on the big picture 2019-11-30 15:10:48 -08:00
Ben Ramsey f1e27fc9e8 Apply coding standards to functions.php 2019-11-30 14:56:46 -08:00
Ben Ramsey 1273cfaf39 Update param typehint to accept UuidInterface as v3/v5 namespace 2019-11-30 14:15:06 -08:00
Ben Ramsey be88f95a50 Backport 2ec28dd to the 3.x series 2019-11-30 14:14:41 -08:00
Matias Navarro Carter 2ec28dd736 Function api created
Function api is a set of simple autoloaded functions to create uuids proxying the Uuid class static methods.

They provide easy and clean ways of just creating string represented uuids instead of the class.
2019-11-30 13:53:03 -08:00
Nikita Konstantinov 580027e79b Remove redundant bitwise operations 2019-11-30 13:39:14 -08:00
Ben Ramsey 64ba9a2767 Clean up code according to PhpStorm inspections report 2019-11-30 13:14:52 -08:00
Ben Ramsey feb3eb50d1 Revert "Mark toString() method as deprecated, scheduled for removal in 4.0.0"
This reverts commit 4c467ce4d5.

For more information, please see the discussion at:
https://github.com/ramsey/uuid/commit/4c467ce4d5a72c3cf0832c813d4d84d222c3d4bb#commitcomment-31174263

Also refer to the discussion at:
https://github.com/ShittySoft/symfony-live-berlin-2018-doctrine-tutorial/pull/3#issuecomment-460441229

TL;DR: I am retaining `toString()` for improved static analysis and
long-term stability.
2019-11-30 12:33:16 -08:00
Ben Ramsey 555e5c1102 Test usage of PHP_OS constant 2019-11-30 12:18:43 -08:00
Ben Ramsey 92d12eb5c6 Merge branch '3.x' of https://github.com/bkayranci/uuid into bkayranci-3.x 2019-11-30 11:51:54 -08:00
Alessandro Minoccheri c4cc058f3d change array declarations 2019-11-30 09:10:09 -08:00
Ben Ramsey 466629a399 Use a high-strength generator by default, when using RandomLibAdapter 2019-11-30 09:10:09 -08:00
karsasmus 2824db17c8 Change library ircmaxell/random-lib to paragonie/random-lib 2019-11-30 09:10:09 -08:00
Türkalp Burak KAYRANCIOĞLU c0183c581e PHP_OS predefined constant was used instead of php_uname() function. 2019-10-26 13:34:38 +03:00
Ben Ramsey 4c467ce4d5 Mark toString() method as deprecated, scheduled for removal in 4.0.0 2018-08-12 10:49:01 -05:00
Ben Ramsey 59c8bb0840 Update the deprecation messages 2018-08-12 09:43:21 -05:00
Ben Ramsey cd92bfa43c Mark SodiumRandomGenerator as deprecated 2018-08-11 21:30:34 -05:00
Ben Ramsey 7397e2f431 Mark MtRandGenerator and OpenSslGenerator as deprecated 2018-08-11 21:23:49 -05:00
Ben Ramsey 5d5eab97ee Add ext-json as a dependency 2018-08-05 16:59:04 -05:00
Ben Ramsey 8d621488c4 Check whether passthru() is disabled
If passthru() is disabled in php.ini, this will force the
SystemNodeProvider to return `false` for the node. Using the default
FallbackNodeProvider, ramsey/uuid will default to the
RandomNodeProvider, in these cases.

Closes #114
2018-07-19 16:53:00 -05:00
Ben Ramsey 6616ec086c Merge pull request #232 from marcosh/master
add annotations for thrown exceptions
2018-07-19 15:24:41 -05:00
Ben Ramsey b8cac9278c Merge branch 'SystemNodeProvider-FreeBSD-support' of https://github.com/kalifg/uuid into kalifg-SystemNodeProvider-FreeBSD-support 2018-07-19 15:08:45 -05:00
Marco Perone 4b7374129c add annotations for thrown exceptions 2018-07-09 09:04:12 +02:00
Lee Boynton 2804748423 Don't allow UUIDs to have trailing newline 2018-05-02 18:54:33 +01:00
Ben Peachey 62628862df Improvements to the SystemNodeProviderTest class (#211)
* Changes location of providers in the SystemNodeProviderTest

  They are now grouped at the bottom of the class.

* Adds logic to SystemNodeProviderTest.

* Changes call to `file_get_contents` SystemNodeProvider so it can be
  mocked.

* Changes SystemNodeProviderTest so native PHP functions are mocked
  instead of the class under test.

* Changes SystemNodeProviderTest so "\n" is used instead of PHP_EOL

  As the (input or output) of the tests is not system dependant it does
  not make sense to use PHP_EOL. All of these instance have been
  replaced for the sake of readability and stating intent more clearly.

* Adds dataprovider to SystemNodeProvider main test for input
  variations.

* Adds OS to SystemNodeProviderTest dataprovider for Linux fail
  scenario.

* Adds test for SystemNodeProvider to ensure invalid values are not
  accepted.

* Changes names of dataproviders in SystemNodeProviderTest for
  consistency.

* Changes SystemNodeProviderTest by grouping dataproviders together.

* Changes method in SystemNodeProviderTest to use the provided mock
  functions.

* Fixes PSR-2 coding conventions in SystemNodeProviderTest.

* Minor change to SystemNodeProviderTest based on review.
2018-02-07 17:28:02 -06:00
kalifg a7492800e2 Add support for determining MAC address on FreeBSD systems 2018-02-07 15:15:49 -06:00