mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-16 16:17:43 +03:00
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.
This commit is contained in:
+20
-37
@@ -8,71 +8,54 @@
|
||||
*
|
||||
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
* phpcs:disable Squiz.Functions.GlobalFunction
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Uuid;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||
|
||||
/**
|
||||
* Generate a version 1 UUID from a host ID, sequence number, and the current time.
|
||||
* Returns a version 1 (time-based) UUID from a host ID, sequence number,
|
||||
* and the current time
|
||||
*
|
||||
* @param int|string|null $node A 48-bit number representing the hardware address
|
||||
* This number may be represented as an integer or a hexadecimal string.
|
||||
* @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
|
||||
* @param int|string $node A 48-bit number representing the hardware address;
|
||||
* this number may be represented as an integer or a hexadecimal string
|
||||
* @param int $clockSeq A 14-bit number used to help avoid duplicates that
|
||||
* could arise when the clock is set backwards in time or if the node ID
|
||||
* changes.
|
||||
* @return string
|
||||
* @throws UnsatisfiedDependencyException if called on a 32-bit system and
|
||||
* `Moontoast\Math\BigNumber` is not present
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception if it was not possible to gather sufficient entropy
|
||||
* changes
|
||||
*/
|
||||
function v1($node = null, $clockSeq = null)
|
||||
function v1($node = null, ?int $clockSeq = null): string
|
||||
{
|
||||
return Uuid::uuid1($node, $clockSeq)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a version 3 UUID based on the MD5 hash of a namespace identifier
|
||||
* (which is a UUID) and a name (which is a string).
|
||||
* Returns a version 3 (name-based) UUID based on the MD5 hash of a
|
||||
* namespace ID and a name
|
||||
*
|
||||
* @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
|
||||
* @param string $name The name to create a UUID for
|
||||
* @return string
|
||||
* @throws InvalidUuidStringException
|
||||
* @param string|UuidInterface $ns The namespace (must be a valid UUID)
|
||||
*/
|
||||
function v3($ns, $name)
|
||||
function v3($ns, string $name): string
|
||||
{
|
||||
return Uuid::uuid3($ns, $name)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a version 4 (random) UUID.
|
||||
*
|
||||
* @return string
|
||||
* @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception
|
||||
* Returns a version 4 (random) UUID
|
||||
*/
|
||||
function v4()
|
||||
function v4(): string
|
||||
{
|
||||
return Uuid::uuid4()->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a version 5 UUID based on the SHA-1 hash of a namespace
|
||||
* identifier (which is a UUID) and a name (which is a string).
|
||||
* Returns a version 5 (name-based) UUID based on the SHA-1 hash of a
|
||||
* namespace ID and a name
|
||||
*
|
||||
* @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
|
||||
* @param string $name The name to create a UUID for
|
||||
* @return string
|
||||
* @throws InvalidUuidStringException
|
||||
* @param string|UuidInterface $ns The namespace (must be a valid UUID)
|
||||
*/
|
||||
function v5($ns, $name)
|
||||
function v5($ns, string $name): string
|
||||
{
|
||||
return Uuid::uuid5($ns, $name)->toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user