Skip to content

Commit 605d817

Browse files
committedJan 6, 2021
Update and apply CS rules
1 parent ce783e3 commit 605d817

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed
 

‎Uuid.php

+41-41
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@
1818
*/
1919
final class Uuid
2020
{
21-
const UUID_VARIANT_NCS = 0;
22-
const UUID_VARIANT_DCE = 1;
23-
const UUID_VARIANT_MICROSOFT = 2;
24-
const UUID_VARIANT_OTHER = 3;
25-
const UUID_TYPE_DEFAULT = 0;
26-
const UUID_TYPE_TIME = 1;
27-
const UUID_TYPE_MD5 = 3;
28-
const UUID_TYPE_DCE = 4; // Deprecated alias
29-
const UUID_TYPE_NAME = 1; // Deprecated alias
30-
const UUID_TYPE_RANDOM = 4;
31-
const UUID_TYPE_SHA1 = 5;
32-
const UUID_TYPE_NULL = -1;
33-
const UUID_TYPE_INVALID = -42;
21+
public const UUID_VARIANT_NCS = 0;
22+
public const UUID_VARIANT_DCE = 1;
23+
public const UUID_VARIANT_MICROSOFT = 2;
24+
public const UUID_VARIANT_OTHER = 3;
25+
public const UUID_TYPE_DEFAULT = 0;
26+
public const UUID_TYPE_TIME = 1;
27+
public const UUID_TYPE_MD5 = 3;
28+
public const UUID_TYPE_DCE = 4; // Deprecated alias
29+
public const UUID_TYPE_NAME = 1; // Deprecated alias
30+
public const UUID_TYPE_RANDOM = 4;
31+
public const UUID_TYPE_SHA1 = 5;
32+
public const UUID_TYPE_NULL = -1;
33+
public const UUID_TYPE_INVALID = -42;
3434

3535
// https://tools.ietf.org/html/rfc4122#section-4.1.4
3636
// 0x01b21dd213814000 is the number of 100-ns intervals between the
3737
// UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
38-
const TIME_OFFSET_INT = 0x01b21dd213814000;
39-
const TIME_OFFSET_BIN = "\x01\xb2\x1d\xd2\x13\x81\x40\x00";
40-
const TIME_OFFSET_COM = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00";
38+
public const TIME_OFFSET_INT = 0x01b21dd213814000;
39+
public const TIME_OFFSET_BIN = "\x01\xb2\x1d\xd2\x13\x81\x40\x00";
40+
public const TIME_OFFSET_COM = "\xfe\x4d\xe2\x2d\xec\x7e\xc0\x00";
4141

42-
public static function uuid_create($uuid_type = UUID_TYPE_DEFAULT)
42+
public static function uuid_create($uuid_type = \UUID_TYPE_DEFAULT)
4343
{
44-
if (!\is_numeric($uuid_type) && null !== $uuid_type) {
45-
trigger_error(sprintf('uuid_create() expects parameter 1 to be int, %s given', \gettype($uuid_type)), E_USER_WARNING);
44+
if (!is_numeric($uuid_type) && null !== $uuid_type) {
45+
trigger_error(sprintf('uuid_create() expects parameter 1 to be int, %s given', \gettype($uuid_type)), \E_USER_WARNING);
4646

4747
return null;
4848
}
@@ -56,7 +56,7 @@ public static function uuid_create($uuid_type = UUID_TYPE_DEFAULT)
5656
case self::UUID_TYPE_DEFAULT:
5757
return self::uuid_generate_random();
5858
default:
59-
trigger_error(sprintf("Unknown/invalid UUID type '%d' requested, using default type instead", $uuid_type), E_USER_WARNING);
59+
trigger_error(sprintf("Unknown/invalid UUID type '%d' requested, using default type instead", $uuid_type), \E_USER_WARNING);
6060

6161
return self::uuid_generate_random();
6262
}
@@ -65,13 +65,13 @@ public static function uuid_create($uuid_type = UUID_TYPE_DEFAULT)
6565
public static function uuid_generate_md5($uuid_ns, $name)
6666
{
6767
if (!\is_string($uuid_ns = self::toString($uuid_ns))) {
68-
trigger_error(sprintf('uuid_generate_md5() expects parameter 1 to be string, %s given', \gettype($uuid_ns)), E_USER_WARNING);
68+
trigger_error(sprintf('uuid_generate_md5() expects parameter 1 to be string, %s given', \gettype($uuid_ns)), \E_USER_WARNING);
6969

7070
return null;
7171
}
7272

7373
if (!\is_string($name = self::toString($name))) {
74-
trigger_error(sprintf('uuid_generate_md5() expects parameter 2 to be string, %s given', \gettype($name)), E_USER_WARNING);
74+
trigger_error(sprintf('uuid_generate_md5() expects parameter 2 to be string, %s given', \gettype($name)), \E_USER_WARNING);
7575

7676
return null;
7777
}
@@ -106,13 +106,13 @@ public static function uuid_generate_md5($uuid_ns, $name)
106106
public static function uuid_generate_sha1($uuid_ns, $name)
107107
{
108108
if (!\is_string($uuid_ns = self::toString($uuid_ns))) {
109-
trigger_error(sprintf('uuid_generate_sha1() expects parameter 1 to be string, %s given', \gettype($uuid_ns)), E_USER_WARNING);
109+
trigger_error(sprintf('uuid_generate_sha1() expects parameter 1 to be string, %s given', \gettype($uuid_ns)), \E_USER_WARNING);
110110

111111
return null;
112112
}
113113

114114
if (!\is_string($name = self::toString($name))) {
115-
trigger_error(sprintf('uuid_generate_sha1() expects parameter 2 to be string, %s given', \gettype($name)), E_USER_WARNING);
115+
trigger_error(sprintf('uuid_generate_sha1() expects parameter 2 to be string, %s given', \gettype($name)), \E_USER_WARNING);
116116

117117
return null;
118118
}
@@ -149,7 +149,7 @@ public static function uuid_generate_sha1($uuid_ns, $name)
149149
public static function uuid_is_valid($uuid)
150150
{
151151
if (!\is_string($uuid = self::toString($uuid))) {
152-
trigger_error(sprintf('uuid_is_valid() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
152+
trigger_error(sprintf('uuid_is_valid() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
153153

154154
return null;
155155
}
@@ -160,13 +160,13 @@ public static function uuid_is_valid($uuid)
160160
public static function uuid_compare($uuid1, $uuid2)
161161
{
162162
if (!\is_string($uuid1 = self::toString($uuid1))) {
163-
trigger_error(sprintf('uuid_compare() expects parameter 1 to be string, %s given', \gettype($uuid1)), E_USER_WARNING);
163+
trigger_error(sprintf('uuid_compare() expects parameter 1 to be string, %s given', \gettype($uuid1)), \E_USER_WARNING);
164164

165165
return null;
166166
}
167167

168168
if (!\is_string($uuid2 = self::toString($uuid2))) {
169-
trigger_error(sprintf('uuid_compare() expects parameter 2 to be string, %s given', \gettype($uuid2)), E_USER_WARNING);
169+
trigger_error(sprintf('uuid_compare() expects parameter 2 to be string, %s given', \gettype($uuid2)), \E_USER_WARNING);
170170

171171
return null;
172172
}
@@ -193,7 +193,7 @@ public static function uuid_compare($uuid1, $uuid2)
193193
public static function uuid_is_null($uuid)
194194
{
195195
if (!\is_string($uuid = self::toString($uuid))) {
196-
trigger_error(sprintf('uuid_is_null() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
196+
trigger_error(sprintf('uuid_is_null() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
197197

198198
return null;
199199
}
@@ -207,7 +207,7 @@ public static function uuid_is_null($uuid)
207207
public static function uuid_type($uuid)
208208
{
209209
if (!\is_string($uuid = self::toString($uuid))) {
210-
trigger_error(sprintf('uuid_type() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
210+
trigger_error(sprintf('uuid_type() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
211211

212212
return null;
213213
}
@@ -230,7 +230,7 @@ public static function uuid_type($uuid)
230230
public static function uuid_variant($uuid)
231231
{
232232
if (!\is_string($uuid = self::toString($uuid))) {
233-
trigger_error(sprintf('uuid_variant() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
233+
trigger_error(sprintf('uuid_variant() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
234234

235235
return null;
236236
}
@@ -263,7 +263,7 @@ public static function uuid_variant($uuid)
263263
public static function uuid_time($uuid)
264264
{
265265
if (!\is_string($uuid = self::toString($uuid))) {
266-
trigger_error(sprintf('uuid_time() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
266+
trigger_error(sprintf('uuid_time() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
267267

268268
return null;
269269
}
@@ -282,7 +282,7 @@ public static function uuid_time($uuid)
282282
return intdiv(hexdec($parsed['time']) - self::TIME_OFFSET_INT, 10000000);
283283
}
284284

285-
$time = str_pad(hex2bin($parsed['time']), 8, "\0", STR_PAD_LEFT);
285+
$time = str_pad(hex2bin($parsed['time']), 8, "\0", \STR_PAD_LEFT);
286286
$time = self::binaryAdd($time, self::TIME_OFFSET_COM);
287287
$time[0] = $time[0] & "\x7F";
288288

@@ -292,7 +292,7 @@ public static function uuid_time($uuid)
292292
public static function uuid_mac($uuid)
293293
{
294294
if (!\is_string($uuid = self::toString($uuid))) {
295-
trigger_error(sprintf('uuid_mac() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
295+
trigger_error(sprintf('uuid_mac() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
296296

297297
return null;
298298
}
@@ -313,7 +313,7 @@ public static function uuid_mac($uuid)
313313
public static function uuid_parse($uuid)
314314
{
315315
if (!\is_string($uuid = self::toString($uuid))) {
316-
trigger_error(sprintf('uuid_parse() expects parameter 1 to be string, %s given', \gettype($uuid)), E_USER_WARNING);
316+
trigger_error(sprintf('uuid_parse() expects parameter 1 to be string, %s given', \gettype($uuid)), \E_USER_WARNING);
317317

318318
return null;
319319
}
@@ -332,7 +332,7 @@ public static function uuid_parse($uuid)
332332
public static function uuid_unparse($bytes)
333333
{
334334
if (!\is_string($bytes = self::toString($bytes))) {
335-
trigger_error(sprintf('uuid_unparse() expects parameter 1 to be string, %s given', \gettype($bytes)), E_USER_WARNING);
335+
trigger_error(sprintf('uuid_unparse() expects parameter 1 to be string, %s given', \gettype($bytes)), \E_USER_WARNING);
336336

337337
return null;
338338
}
@@ -384,9 +384,9 @@ private static function uuid_generate_time()
384384
$time = substr($time, 11).substr($time, 2, 7);
385385

386386
if (\PHP_INT_SIZE >= 8) {
387-
$time = str_pad(dechex($time + self::TIME_OFFSET_INT), 16, '0', STR_PAD_LEFT);
387+
$time = str_pad(dechex($time + self::TIME_OFFSET_INT), 16, '0', \STR_PAD_LEFT);
388388
} else {
389-
$time = str_pad(self::toBinary($time), 8, "\0", STR_PAD_LEFT);
389+
$time = str_pad(self::toBinary($time), 8, "\0", \STR_PAD_LEFT);
390390
$time = self::binaryAdd($time, self::TIME_OFFSET_BIN);
391391
$time = bin2hex($time);
392392
}
@@ -448,12 +448,12 @@ private static function parse($uuid)
448448
return null;
449449
}
450450

451-
return array(
451+
return [
452452
'time' => '0'.$matches['time_hi'].$matches['time_mid'].$matches['time_low'],
453453
'version' => hexdec($matches['version']),
454454
'clock_seq' => hexdec($matches['clock_seq']),
455455
'node' => $matches['node'],
456-
);
456+
];
457457
}
458458

459459
private static function toString($v)
@@ -471,7 +471,7 @@ private static function toBinary($digits)
471471
$count = \strlen($digits);
472472

473473
while ($count) {
474-
$quotient = array();
474+
$quotient = [];
475475
$remainder = 0;
476476

477477
for ($i = 0; $i !== $count; ++$i) {
@@ -497,7 +497,7 @@ private static function toDecimal($bytes)
497497
$bytes = array_values(unpack('C*', $bytes));
498498

499499
while ($count = \count($bytes)) {
500-
$quotient = array();
500+
$quotient = [];
501501
$remainder = 0;
502502

503503
for ($i = 0; $i !== $count; ++$i) {

‎bootstrap.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return;
1616
}
1717

18-
if (PHP_VERSION_ID >= 80000) {
18+
if (\PHP_VERSION_ID >= 80000) {
1919
return require __DIR__.'/bootstrap80.php';
2020
}
2121

@@ -60,7 +60,7 @@
6060
}
6161

6262
if (!function_exists('uuid_create')) {
63-
function uuid_create($uuid_type = UUID_TYPE_DEFAULT) { return p\Uuid::uuid_create($uuid_type); }
63+
function uuid_create($uuid_type = \UUID_TYPE_DEFAULT) { return p\Uuid::uuid_create($uuid_type); }
6464
}
6565
if (!function_exists('uuid_generate_md5')) {
6666
function uuid_generate_md5($uuid_ns, $name) { return p\Uuid::uuid_generate_md5($uuid_ns, $name); }

‎bootstrap80.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
}
5353

5454
if (!function_exists('uuid_create')) {
55-
function uuid_create(int $uuid_type = UUID_TYPE_DEFAULT): string { return p\Uuid::uuid_create($uuid_type); }
55+
function uuid_create(int $uuid_type = \UUID_TYPE_DEFAULT): string { return p\Uuid::uuid_create($uuid_type); }
5656
}
5757
if (!function_exists('uuid_generate_md5')) {
5858
function uuid_generate_md5(string $uuid_ns, string $name): string { return p\Uuid::uuid_generate_md5($uuid_ns, $name); }

0 commit comments

Comments
 (0)
Please sign in to comment.