Skip to content

Commit b66e921

Browse files
authored
chore: rename all enum cases to PascalCase instead of SHOUT_CASE (#450)
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 24a777d commit b66e921

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+453
-417
lines changed

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
# Components
88

9-
* [Psl\Async](../src/Psl/Async/README.md)
10-
* [Psl\Default](../src/Psl/Default/README.md)
11-
* [Psl\Range](../src/Psl/Range/README.md)
9+
* [Psl\Async](../src/Psl/Async/README.md)
10+
* [Psl\Default](../src/Psl/Default/README.md)
11+
* [Psl\Range](../src/Psl/Range/README.md)
1212

1313
---
1414

docs/component/html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020

2121
#### `Enums`
2222

23-
- [Encoding](./../../src/Psl/Html/Encoding.php#L20)
23+
- [Encoding](./../../src/Psl/Html/Encoding.php#L17)
2424

2525

docs/documenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function regenerate_documentation(): void
6666

6767
$readme_template = File\read(__DIR__ . '/templates/README.template.md');
6868
$readme = Str\replace($readme_template, '{{ list }}', $components_documentation);
69-
$mode = Filesystem\is_file($readme) ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE;
69+
$mode = Filesystem\is_file($readme) ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate;
7070
File\write(__DIR__ . '/README.md', $readme, $mode);
7171

7272
foreach ($components as $component) {
@@ -143,7 +143,7 @@ function document_component(string $component, string $index_link): void
143143
), "\n"),
144144
]);
145145

146-
$mode = Filesystem\is_file($current_filename) ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE;
146+
$mode = Filesystem\is_file($current_filename) ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate;
147147
File\write($current_filename, $documentation, $mode);
148148
}
149149

docs/templates/README.template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Components
88

99
* [Psl\Async](../src/Psl/Async/README.md)
10+
* [Psl\Default](../src/Psl/Default/README.md)
1011
* [Psl\Range](../src/Psl/Range/README.md)
1112

1213
---

src/Psl/Encoding/Base64/Internal/Base64.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ abstract class Base64
3636
public static function encode(string $binary, bool $padding = true): string
3737
{
3838
$dest = '';
39-
$binary_length = Str\length($binary, encoding: Str\Encoding::ASCII_8BIT);
39+
$binary_length = Str\length($binary, encoding: Str\Encoding::Ascii8bit);
4040

4141
for ($i = 0; $i + 3 <= $binary_length; $i += 3) {
4242
/** @var array<int, int> $chunk */
43-
$chunk = unpack('C*', Str\slice($binary, $i, 3, encoding: Str\Encoding::ASCII_8BIT));
43+
$chunk = unpack('C*', Str\slice($binary, $i, 3, encoding: Str\Encoding::Ascii8bit));
4444
$byte0 = $chunk[1];
4545
$byte1 = $chunk[2];
4646
$byte2 = $chunk[3];
@@ -55,7 +55,7 @@ public static function encode(string $binary, bool $padding = true): string
5555
*
5656
* @var array<int, int> $chunk
5757
*/
58-
$chunk = unpack('C*', Str\slice($binary, $i, $binary_length - $i, encoding: Str\Encoding::ASCII_8BIT));
58+
$chunk = unpack('C*', Str\slice($binary, $i, $binary_length - $i, encoding: Str\Encoding::Ascii8bit));
5959
$byte0 = $chunk[1];
6060
if ($i + 1 < $binary_length) {
6161
$byte1 = $chunk[2];
@@ -92,7 +92,7 @@ public static function encode(string $binary, bool $padding = true): string
9292
*/
9393
public static function decode(string $base64, bool $explicit_padding = true): string
9494
{
95-
$base64_length = Str\length($base64, encoding: Str\Encoding::ASCII_8BIT);
95+
$base64_length = Str\length($base64, encoding: Str\Encoding::Ascii8bit);
9696
if ($base64_length === 0) {
9797
return '';
9898
}
@@ -105,13 +105,13 @@ public static function decode(string $base64, bool $explicit_padding = true): st
105105

106106
/** @psalm-suppress MissingThrowsDocblock */
107107
$base64 = Str\trim_right($base64, '=');
108-
$base64_length = Str\length($base64, encoding: Str\Encoding::ASCII_8BIT);
108+
$base64_length = Str\length($base64, encoding: Str\Encoding::Ascii8bit);
109109

110110
$err = 0;
111111
$dest = '';
112112
for ($i = 0; $i + 4 <= $base64_length; $i += 4) {
113113
/** @var array<int, int> $chunk */
114-
$chunk = unpack('C*', Str\slice($base64, $i, 4, encoding: Str\Encoding::ASCII_8BIT));
114+
$chunk = unpack('C*', Str\slice($base64, $i, 4, encoding: Str\Encoding::Ascii8bit));
115115
$char0 = static::decode6Bits($chunk[1]);
116116
$char1 = static::decode6Bits($chunk[2]);
117117
$char2 = static::decode6Bits($chunk[3]);
@@ -130,7 +130,7 @@ public static function decode(string $base64, bool $explicit_padding = true): st
130130
*
131131
* @var array<int, int> $chunk
132132
*/
133-
$chunk = unpack('C*', Str\slice($base64, $i, $base64_length - $i, encoding: Str\Encoding::ASCII_8BIT));
133+
$chunk = unpack('C*', Str\slice($base64, $i, $base64_length - $i, encoding: Str\Encoding::Ascii8bit));
134134
$char0 = static::decode6Bits($chunk[1]);
135135
if ($i + 2 < $base64_length) {
136136
$char1 = static::decode6Bits($chunk[2]);

src/Psl/Encoding/Base64/Variant.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum Variant implements DefaultInterface
2121
*
2222
* This variant is typically used in MIME messages and XML data.
2323
*/
24-
case Default;
24+
case Standard;
2525

2626
/**
2727
* A URL and filename safe Base64 encoding variant.
@@ -64,8 +64,17 @@ enum Variant implements DefaultInterface
6464
*/
6565
case DotSlashOrdered;
6666

67+
/**
68+
* Provides the default variant for Base64 encoding.
69+
*
70+
* By default, this method returns the `Standard` variant, which is widely used across
71+
* various applications, including MIME messages and XML data. It represents a safe
72+
* and common choice for general-purpose encoding needs.
73+
*
74+
* @return static The `Standard` variant of Base64 encoding.
75+
*/
6776
public static function default(): static
6877
{
69-
return self::Default;
78+
return self::Standard;
7079
}
7180
}

src/Psl/Encoding/Base64/decode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* the base64 characters range.
1616
* @throws Exception\IncorrectPaddingException If the encoded string has an incorrect padding.
1717
*/
18-
function decode(string $base64, Variant $variant = Variant::Default, bool $explicit_padding = true): string
18+
function decode(string $base64, Variant $variant = Variant::Standard, bool $explicit_padding = true): string
1919
{
2020
return match ($variant) {
21-
Variant::Default => Internal\Base64::decode($base64, $explicit_padding),
21+
Variant::Standard => Internal\Base64::decode($base64, $explicit_padding),
2222
Variant::UrlSafe => Internal\Base64UrlSafe::decode($base64, $explicit_padding),
2323
Variant::DotSlash => Internal\Base64DotSlash::decode($base64, $explicit_padding),
2424
Variant::DotSlashOrdered => Internal\Base64DotSlashOrdered::decode($base64, $explicit_padding),

src/Psl/Encoding/Base64/encode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*
1010
* @pure
1111
*/
12-
function encode(string $binary, Variant $variant = Variant::Default, bool $padding = true): string
12+
function encode(string $binary, Variant $variant = Variant::Standard, bool $padding = true): string
1313
{
1414
return match ($variant) {
15-
Variant::Default => Internal\Base64::encode($binary, $padding),
15+
Variant::Standard => Internal\Base64::encode($binary, $padding),
1616
Variant::UrlSafe => Internal\Base64UrlSafe::encode($binary, $padding),
1717
Variant::DotSlash => Internal\Base64DotSlash::encode($binary, $padding),
1818
Variant::DotSlashOrdered => Internal\Base64DotSlashOrdered::encode($binary, $padding),

src/Psl/Encoding/Hex/decode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function decode(string $hexadecimal): string
2727
);
2828
}
2929

30-
$hex_len = Str\length($hexadecimal, Str\Encoding::ASCII_8BIT);
30+
$hex_len = Str\length($hexadecimal, Str\Encoding::Ascii8bit);
3131
if (($hex_len & 1) !== 0) {
3232
throw new Exception\RangeException(
3333
'Expected an even number of hexadecimal characters.',

src/Psl/File/HandleInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getSize(): int;
3535
* Example:
3636
*
3737
* ```php
38-
* $lock = $file->lock(LockType::SHARED);
38+
* $lock = $file->lock(LockType::Shared);
3939
* // lock has been acquired.
4040
* $lock->release();
4141
* ```
@@ -53,7 +53,7 @@ public function lock(LockType $type): Lock;
5353
*
5454
* ```php
5555
* try {
56-
* $lock = $file->tryLock(LockType::SHARED);
56+
* $lock = $file->tryLock(LockType::Shared);
5757
* // lock has been acquired.
5858
* $lock->release();
5959
* } catch(AlreadyLockedException) {

src/Psl/File/Internal/ResourceHandle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function tryLock(LockType $type): Lock
108108
throw new Exception\AlreadyClosedException('Handle has already been closed.');
109109
}
110110

111-
$operations = LOCK_NB | ($type === LockType::EXCLUSIVE ? LOCK_EX : LOCK_SH);
111+
$operations = LOCK_NB | ($type === LockType::Exclusive ? LOCK_EX : LOCK_SH);
112112
$success = @flock($this->stream, $operations, $would_block);
113113
// @codeCoverageIgnoreStart
114114
if ($would_block) {
@@ -118,7 +118,7 @@ public function tryLock(LockType $type): Lock
118118
if (!$success) {
119119
throw new File\Exception\RuntimeException(Str\format(
120120
'Could not acquire %s lock for "%s".',
121-
$type === LockType::EXCLUSIVE ? 'exclusive' : 'shared',
121+
$type === LockType::Exclusive ? 'exclusive' : 'shared',
122122
$this->getPath(),
123123
));
124124
}

src/Psl/File/Lock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ final class Lock
1111
private bool $released = false;
1212

1313
/**
14-
* @param (Closure(): void) $release
14+
* @param (Closure(): void) $releaseCallback
1515
*
16-
* @internal use HandleInterface::lock() to create a lock.
16+
* @internal use {@see HandleInterface::lock()} to create a lock.
1717
*/
1818
public function __construct(
1919
public readonly LockType $type,

src/Psl/File/LockType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ enum LockType
1111
* commonly called a reader lock. The creation of a Lock will block until
1212
* the lock is acquired.
1313
*/
14-
case SHARED;
14+
case Shared;
1515

1616
/**
1717
* Only a single process may possess an exclusive lock to a given file at a
1818
* time. The creation of a Lock will block until the lock is acquired.
1919
*/
20-
case EXCLUSIVE;
20+
case Exclusive;
2121
}

src/Psl/File/ReadWriteHandle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ final class ReadWriteHandle extends Internal\AbstractHandleWrapper implements Re
2525
* @throws Exception\NotReadableException If $file exists, and is non-readable.
2626
* @throws Exception\RuntimeException If unable to create the $file if it does not exist.
2727
*/
28-
public function __construct(string $file, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE)
28+
public function __construct(string $file, WriteMode $write_mode = WriteMode::OpenOrCreate)
2929
{
3030
$is_file = Filesystem\is_file($file);
3131
if (!$is_file && Filesystem\exists($file)) {
3232
throw Exception\NotFileException::for($file);
3333
}
3434

35-
$must_create = $write_mode === WriteMode::MUST_CREATE;
35+
$must_create = $write_mode === WriteMode::MustCreate;
3636
if ($must_create && $is_file) {
3737
throw Exception\AlreadyCreatedException::for($file);
3838
}

src/Psl/File/WriteHandle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ final class WriteHandle extends Internal\AbstractHandleWrapper implements WriteH
2323
* @throws Exception\NotWritableException If $file is non-writable.
2424
* @throws Exception\RuntimeException If unable to create the $file if it does not exist.
2525
*/
26-
public function __construct(string $file, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE)
26+
public function __construct(string $file, WriteMode $write_mode = WriteMode::OpenOrCreate)
2727
{
2828
$is_file = Filesystem\is_file($file);
2929
if (!$is_file && Filesystem\exists($file)) {
3030
throw Exception\NotFileException::for($file);
3131
}
3232

33-
$must_create = $write_mode === WriteMode::MUST_CREATE;
33+
$must_create = $write_mode === WriteMode::MustCreate;
3434
if ($must_create && $is_file) {
3535
throw Exception\AlreadyCreatedException::for($file);
3636
}

src/Psl/File/WriteMode.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ enum WriteMode: string
1010
* Open the file for writing only; place the file pointer at the beginning of
1111
* the file.
1212
*
13-
* If the file exits, it is not truncated (as with `TRUNCATE`), and the call
14-
* succeeds (unlike `MUST_CREATE`).
13+
* If the file exits, it is not truncated (as with `Truncate`), and the call
14+
* succeeds (unlike `MustCreate`).
1515
*/
16-
case OPEN_OR_CREATE = 'cb';
16+
case OpenOrCreate = 'cb';
1717

1818
/**
1919
* Open for writing only; place the file pointer at the beginning of the
2020
* file and truncate the file to zero length. If the file does not exist,
2121
* attempt to create it.
2222
*/
23-
case TRUNCATE = 'wb';
23+
case Truncate = 'wb';
2424

2525
/**
2626
* Open for writing only; place the file pointer at the end of the file. If
2727
* the file does not exist, attempt to create it. In this mode, seeking has
2828
* no effect, writes are always appended.
2929
*/
30-
case APPEND = 'ab';
30+
case Append = 'ab';
3131

3232
/**
3333
* Create and open for writing only; place the file pointer at the beginning
3434
* of the file. If the file already exists, the filesystem call will throw an
3535
* exception. If the file does not exist, attempt to create it.
3636
*/
37-
case MUST_CREATE = 'xb';
37+
case MustCreate = 'xb';
3838
}

src/Psl/File/open_read_write.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @throws Exception\NotReadableException If $file exists, and is non-readable.
1717
* @throws Exception\RuntimeException If unable to create the $file if it does not exist.
1818
*/
19-
function open_read_write(string $path, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE): ReadWriteHandleInterface
19+
function open_read_write(string $path, WriteMode $write_mode = WriteMode::OpenOrCreate): ReadWriteHandleInterface
2020
{
2121
return new ReadWriteHandle($path, $write_mode);
2222
}

src/Psl/File/open_write_only.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @throws Exception\NotWritableException If $file exists, and is non-writable.
1616
* @throws Exception\RuntimeException If unable to create the $file if it does not exist.
1717
*/
18-
function open_write_only(string $file, WriteMode $mode = WriteMode::OPEN_OR_CREATE): WriteHandleInterface
18+
function open_write_only(string $file, WriteMode $mode = WriteMode::OpenOrCreate): WriteHandleInterface
1919
{
2020
return new WriteHandle($file, $mode);
2121
}

src/Psl/File/read.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function read(string $file, int $offset = 0, ?int $length = null): string
2424
{
2525
try {
2626
$handle = namespace\open_read_only($file);
27-
$lock = $handle->lock(namespace\LockType::SHARED);
27+
$lock = $handle->lock(namespace\LockType::Shared);
2828

2929
$handle->seek($offset);
3030
$content = $handle->readAll($length);

src/Psl/File/write.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
* @throws Exception\NotWritableException If $file exists, and is non-writable.
2222
* @throws Exception\RuntimeException In case of an error.
2323
*/
24-
function write(string $file, string $content, WriteMode $mode = WriteMode::OPEN_OR_CREATE): void
24+
function write(string $file, string $content, WriteMode $mode = WriteMode::OpenOrCreate): void
2525
{
2626
clearstatcache();
2727

2828
try {
2929
$handle = File\open_write_only($file, $mode);
30-
$lock = $handle->lock(File\LockType::EXCLUSIVE);
30+
$lock = $handle->lock(File\LockType::Exclusive);
3131

3232
$handle->writeAll($content);
3333

src/Psl/Filesystem/copy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ function copy(string $source, string $destination, bool $overwrite = false): voi
4040
$source_handle = File\open_read_only($source);
4141
$destination_handle = File\open_write_only(
4242
$destination,
43-
$destination_exists ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE,
43+
$destination_exists ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate,
4444
);
4545

46-
$source_lock = $source_handle->lock(File\LockType::SHARED);
47-
$destination_lock = $destination_handle->lock(File\LockType::EXCLUSIVE);
46+
$source_lock = $source_handle->lock(File\LockType::Shared);
47+
$destination_lock = $destination_handle->lock(File\LockType::Exclusive);
4848

4949
while ($chunk = $source_handle->read()) {
5050
$destination_handle->writeAll($chunk);

0 commit comments

Comments
 (0)