From 4e5222f58916fbad3a9bbf84dd4c17056432dbcc Mon Sep 17 00:00:00 2001 From: azjezz Date: Mon, 25 Mar 2024 06:42:53 +0000 Subject: [PATCH] chore: rename all enum cases to PascalCase instead of SHOUT_CASE Signed-off-by: azjezz --- docs/README.md | 6 +- docs/component/html.md | 2 +- docs/documenter.php | 4 +- docs/templates/README.template.md | 1 + src/Psl/Encoding/Base64/Internal/Base64.php | 14 +- src/Psl/Encoding/Base64/Variant.php | 13 +- src/Psl/Encoding/Base64/decode.php | 4 +- src/Psl/Encoding/Base64/encode.php | 4 +- src/Psl/Encoding/Hex/decode.php | 2 +- src/Psl/File/HandleInterface.php | 4 +- src/Psl/File/Internal/ResourceHandle.php | 4 +- src/Psl/File/Lock.php | 4 +- src/Psl/File/LockType.php | 4 +- src/Psl/File/ReadWriteHandle.php | 4 +- src/Psl/File/WriteHandle.php | 4 +- src/Psl/File/WriteMode.php | 12 +- src/Psl/File/open_read_write.php | 2 +- src/Psl/File/open_write_only.php | 2 +- src/Psl/File/read.php | 2 +- src/Psl/File/write.php | 4 +- src/Psl/Filesystem/copy.php | 6 +- src/Psl/Hash/Algorithm.php | 120 +++++++------- src/Psl/Hash/Context.php | 19 ++- src/Psl/Hash/Hmac/Algorithm.php | 88 +++++----- src/Psl/Html/Encoding.php | 89 ++++++---- src/Psl/Html/decode.php | 2 +- src/Psl/Html/encode.php | 2 +- src/Psl/Html/encode_special_characters.php | 2 +- src/Psl/Network/Address.php | 4 +- src/Psl/Network/Internal/get_peer_name.php | 2 +- src/Psl/Network/SocketScheme.php | 4 +- src/Psl/Str/Encoding.php | 156 +++++++++--------- src/Psl/Str/after.php | 2 +- src/Psl/Str/after_ci.php | 2 +- src/Psl/Str/after_last.php | 2 +- src/Psl/Str/after_last_ci.php | 2 +- src/Psl/Str/before.php | 2 +- src/Psl/Str/before_ci.php | 2 +- src/Psl/Str/before_last.php | 2 +- src/Psl/Str/before_last_ci.php | 2 +- src/Psl/Str/capitalize.php | 2 +- src/Psl/Str/capitalize_words.php | 2 +- src/Psl/Str/chr.php | 2 +- src/Psl/Str/chunk.php | 2 +- src/Psl/Str/contains.php | 2 +- src/Psl/Str/contains_ci.php | 2 +- src/Psl/Str/ends_with.php | 2 +- src/Psl/Str/ends_with_ci.php | 2 +- src/Psl/Str/fold.php | 2 +- src/Psl/Str/is_utf8.php | 2 +- src/Psl/Str/length.php | 2 +- src/Psl/Str/lowercase.php | 2 +- src/Psl/Str/ord.php | 2 +- src/Psl/Str/pad_left.php | 2 +- src/Psl/Str/pad_right.php | 2 +- src/Psl/Str/range.php | 2 +- src/Psl/Str/replace.php | 2 +- src/Psl/Str/replace_ci.php | 2 +- src/Psl/Str/replace_every.php | 2 +- src/Psl/Str/replace_every_ci.php | 2 +- src/Psl/Str/reverse.php | 2 +- src/Psl/Str/search.php | 2 +- src/Psl/Str/search_ci.php | 2 +- src/Psl/Str/search_last.php | 2 +- src/Psl/Str/search_last_ci.php | 2 +- src/Psl/Str/slice.php | 2 +- src/Psl/Str/splice.php | 2 +- src/Psl/Str/split.php | 2 +- src/Psl/Str/starts_with.php | 2 +- src/Psl/Str/starts_with_ci.php | 2 +- src/Psl/Str/strip_prefix.php | 2 +- src/Psl/Str/strip_suffix.php | 2 +- src/Psl/Str/truncate.php | 2 +- src/Psl/Str/uppercase.php | 2 +- src/Psl/Str/width.php | 2 +- src/Psl/Str/wrap.php | 2 +- tests/unit/File/LockTest.php | 26 +-- tests/unit/File/ReadWriteHandleTest.php | 18 +- tests/unit/File/ReadWriteTest.php | 16 +- tests/unit/File/WriteHandleTest.php | 12 +- tests/unit/Fun/TapTest.php | 4 +- tests/unit/Hash/ContextTest.php | 8 +- tests/unit/Hash/HashTest.php | 4 +- tests/unit/Hash/Hmac/HashTest.php | 4 +- tests/unit/Html/DecodeTest.php | 20 +-- .../unit/Html/EncodeSpecialCharactersTest.php | 20 +-- tests/unit/Html/EncodeTest.php | 20 +-- tests/unit/Str/AfterCiTest.php | 32 ++-- tests/unit/Str/ConvertEncodingTest.php | 2 +- tests/unit/Str/DetectEncodingTest.php | 6 +- 90 files changed, 453 insertions(+), 417 deletions(-) diff --git a/docs/README.md b/docs/README.md index d44d18f1..2dc967f7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,9 +6,9 @@ # Components -* [Psl\Async](../src/Psl/Async/README.md) -* [Psl\Default](../src/Psl/Default/README.md) -* [Psl\Range](../src/Psl/Range/README.md) + * [Psl\Async](../src/Psl/Async/README.md) + * [Psl\Default](../src/Psl/Default/README.md) + * [Psl\Range](../src/Psl/Range/README.md) --- diff --git a/docs/component/html.md b/docs/component/html.md index e3c7785e..f0c64256 100644 --- a/docs/component/html.md +++ b/docs/component/html.md @@ -20,6 +20,6 @@ #### `Enums` -- [Encoding](./../../src/Psl/Html/Encoding.php#L20) +- [Encoding](./../../src/Psl/Html/Encoding.php#L17) diff --git a/docs/documenter.php b/docs/documenter.php index 40ec38c0..1fd92dd4 100644 --- a/docs/documenter.php +++ b/docs/documenter.php @@ -66,7 +66,7 @@ function regenerate_documentation(): void $readme_template = File\read(__DIR__ . '/templates/README.template.md'); $readme = Str\replace($readme_template, '{{ list }}', $components_documentation); - $mode = Filesystem\is_file($readme) ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE; + $mode = Filesystem\is_file($readme) ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate; File\write(__DIR__ . '/README.md', $readme, $mode); foreach ($components as $component) { @@ -143,7 +143,7 @@ function document_component(string $component, string $index_link): void ), "\n"), ]); - $mode = Filesystem\is_file($current_filename) ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE; + $mode = Filesystem\is_file($current_filename) ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate; File\write($current_filename, $documentation, $mode); } diff --git a/docs/templates/README.template.md b/docs/templates/README.template.md index a80545b3..278bb739 100644 --- a/docs/templates/README.template.md +++ b/docs/templates/README.template.md @@ -7,6 +7,7 @@ # Components * [Psl\Async](../src/Psl/Async/README.md) + * [Psl\Default](../src/Psl/Default/README.md) * [Psl\Range](../src/Psl/Range/README.md) --- diff --git a/src/Psl/Encoding/Base64/Internal/Base64.php b/src/Psl/Encoding/Base64/Internal/Base64.php index 10ec2005..04483a14 100644 --- a/src/Psl/Encoding/Base64/Internal/Base64.php +++ b/src/Psl/Encoding/Base64/Internal/Base64.php @@ -36,11 +36,11 @@ abstract class Base64 public static function encode(string $binary, bool $padding = true): string { $dest = ''; - $binary_length = Str\length($binary, encoding: Str\Encoding::ASCII_8BIT); + $binary_length = Str\length($binary, encoding: Str\Encoding::Ascii8bit); for ($i = 0; $i + 3 <= $binary_length; $i += 3) { /** @var array $chunk */ - $chunk = unpack('C*', Str\slice($binary, $i, 3, encoding: Str\Encoding::ASCII_8BIT)); + $chunk = unpack('C*', Str\slice($binary, $i, 3, encoding: Str\Encoding::Ascii8bit)); $byte0 = $chunk[1]; $byte1 = $chunk[2]; $byte2 = $chunk[3]; @@ -55,7 +55,7 @@ public static function encode(string $binary, bool $padding = true): string * * @var array $chunk */ - $chunk = unpack('C*', Str\slice($binary, $i, $binary_length - $i, encoding: Str\Encoding::ASCII_8BIT)); + $chunk = unpack('C*', Str\slice($binary, $i, $binary_length - $i, encoding: Str\Encoding::Ascii8bit)); $byte0 = $chunk[1]; if ($i + 1 < $binary_length) { $byte1 = $chunk[2]; @@ -92,7 +92,7 @@ public static function encode(string $binary, bool $padding = true): string */ public static function decode(string $base64, bool $explicit_padding = true): string { - $base64_length = Str\length($base64, encoding: Str\Encoding::ASCII_8BIT); + $base64_length = Str\length($base64, encoding: Str\Encoding::Ascii8bit); if ($base64_length === 0) { return ''; } @@ -105,13 +105,13 @@ public static function decode(string $base64, bool $explicit_padding = true): st /** @psalm-suppress MissingThrowsDocblock */ $base64 = Str\trim_right($base64, '='); - $base64_length = Str\length($base64, encoding: Str\Encoding::ASCII_8BIT); + $base64_length = Str\length($base64, encoding: Str\Encoding::Ascii8bit); $err = 0; $dest = ''; for ($i = 0; $i + 4 <= $base64_length; $i += 4) { /** @var array $chunk */ - $chunk = unpack('C*', Str\slice($base64, $i, 4, encoding: Str\Encoding::ASCII_8BIT)); + $chunk = unpack('C*', Str\slice($base64, $i, 4, encoding: Str\Encoding::Ascii8bit)); $char0 = static::decode6Bits($chunk[1]); $char1 = static::decode6Bits($chunk[2]); $char2 = static::decode6Bits($chunk[3]); @@ -130,7 +130,7 @@ public static function decode(string $base64, bool $explicit_padding = true): st * * @var array $chunk */ - $chunk = unpack('C*', Str\slice($base64, $i, $base64_length - $i, encoding: Str\Encoding::ASCII_8BIT)); + $chunk = unpack('C*', Str\slice($base64, $i, $base64_length - $i, encoding: Str\Encoding::Ascii8bit)); $char0 = static::decode6Bits($chunk[1]); if ($i + 2 < $base64_length) { $char1 = static::decode6Bits($chunk[2]); diff --git a/src/Psl/Encoding/Base64/Variant.php b/src/Psl/Encoding/Base64/Variant.php index 7a3d90a4..fc74e191 100644 --- a/src/Psl/Encoding/Base64/Variant.php +++ b/src/Psl/Encoding/Base64/Variant.php @@ -21,7 +21,7 @@ enum Variant implements DefaultInterface * * This variant is typically used in MIME messages and XML data. */ - case Default; + case Standard; /** * A URL and filename safe Base64 encoding variant. @@ -64,8 +64,17 @@ enum Variant implements DefaultInterface */ case DotSlashOrdered; + /** + * Provides the default variant for Base64 encoding. + * + * By default, this method returns the `Standard` variant, which is widely used across + * various applications, including MIME messages and XML data. It represents a safe + * and common choice for general-purpose encoding needs. + * + * @return static The `Standard` variant of Base64 encoding. + */ public static function default(): static { - return self::Default; + return self::Standard; } } diff --git a/src/Psl/Encoding/Base64/decode.php b/src/Psl/Encoding/Base64/decode.php index cfcf2f09..dccf1799 100644 --- a/src/Psl/Encoding/Base64/decode.php +++ b/src/Psl/Encoding/Base64/decode.php @@ -15,10 +15,10 @@ * the base64 characters range. * @throws Exception\IncorrectPaddingException If the encoded string has an incorrect padding. */ -function decode(string $base64, Variant $variant = Variant::Default, bool $explicit_padding = true): string +function decode(string $base64, Variant $variant = Variant::Standard, bool $explicit_padding = true): string { return match ($variant) { - Variant::Default => Internal\Base64::decode($base64, $explicit_padding), + Variant::Standard => Internal\Base64::decode($base64, $explicit_padding), Variant::UrlSafe => Internal\Base64UrlSafe::decode($base64, $explicit_padding), Variant::DotSlash => Internal\Base64DotSlash::decode($base64, $explicit_padding), Variant::DotSlashOrdered => Internal\Base64DotSlashOrdered::decode($base64, $explicit_padding), diff --git a/src/Psl/Encoding/Base64/encode.php b/src/Psl/Encoding/Base64/encode.php index 0949ed0f..21b49ded 100644 --- a/src/Psl/Encoding/Base64/encode.php +++ b/src/Psl/Encoding/Base64/encode.php @@ -9,10 +9,10 @@ * * @pure */ -function encode(string $binary, Variant $variant = Variant::Default, bool $padding = true): string +function encode(string $binary, Variant $variant = Variant::Standard, bool $padding = true): string { return match ($variant) { - Variant::Default => Internal\Base64::encode($binary, $padding), + Variant::Standard => Internal\Base64::encode($binary, $padding), Variant::UrlSafe => Internal\Base64UrlSafe::encode($binary, $padding), Variant::DotSlash => Internal\Base64DotSlash::encode($binary, $padding), Variant::DotSlashOrdered => Internal\Base64DotSlashOrdered::encode($binary, $padding), diff --git a/src/Psl/Encoding/Hex/decode.php b/src/Psl/Encoding/Hex/decode.php index fdd6fd27..f187b919 100644 --- a/src/Psl/Encoding/Hex/decode.php +++ b/src/Psl/Encoding/Hex/decode.php @@ -27,7 +27,7 @@ function decode(string $hexadecimal): string ); } - $hex_len = Str\length($hexadecimal, Str\Encoding::ASCII_8BIT); + $hex_len = Str\length($hexadecimal, Str\Encoding::Ascii8bit); if (($hex_len & 1) !== 0) { throw new Exception\RangeException( 'Expected an even number of hexadecimal characters.', diff --git a/src/Psl/File/HandleInterface.php b/src/Psl/File/HandleInterface.php index 30f82665..031e07d3 100644 --- a/src/Psl/File/HandleInterface.php +++ b/src/Psl/File/HandleInterface.php @@ -35,7 +35,7 @@ public function getSize(): int; * Example: * * ```php - * $lock = $file->lock(LockType::SHARED); + * $lock = $file->lock(LockType::Shared); * // lock has been acquired. * $lock->release(); * ``` @@ -53,7 +53,7 @@ public function lock(LockType $type): Lock; * * ```php * try { - * $lock = $file->tryLock(LockType::SHARED); + * $lock = $file->tryLock(LockType::Shared); * // lock has been acquired. * $lock->release(); * } catch(AlreadyLockedException) { diff --git a/src/Psl/File/Internal/ResourceHandle.php b/src/Psl/File/Internal/ResourceHandle.php index 836fd7f1..cb969f20 100644 --- a/src/Psl/File/Internal/ResourceHandle.php +++ b/src/Psl/File/Internal/ResourceHandle.php @@ -108,7 +108,7 @@ public function tryLock(LockType $type): Lock throw new Exception\AlreadyClosedException('Handle has already been closed.'); } - $operations = LOCK_NB | ($type === LockType::EXCLUSIVE ? LOCK_EX : LOCK_SH); + $operations = LOCK_NB | ($type === LockType::Exclusive ? LOCK_EX : LOCK_SH); $success = @flock($this->stream, $operations, $would_block); // @codeCoverageIgnoreStart if ($would_block) { @@ -118,7 +118,7 @@ public function tryLock(LockType $type): Lock if (!$success) { throw new File\Exception\RuntimeException(Str\format( 'Could not acquire %s lock for "%s".', - $type === LockType::EXCLUSIVE ? 'exclusive' : 'shared', + $type === LockType::Exclusive ? 'exclusive' : 'shared', $this->getPath(), )); } diff --git a/src/Psl/File/Lock.php b/src/Psl/File/Lock.php index 518831ba..af0c0b58 100644 --- a/src/Psl/File/Lock.php +++ b/src/Psl/File/Lock.php @@ -11,9 +11,9 @@ final class Lock private bool $released = false; /** - * @param (Closure(): void) $release + * @param (Closure(): void) $releaseCallback * - * @internal use HandleInterface::lock() to create a lock. + * @internal use {@see HandleInterface::lock()} to create a lock. */ public function __construct( public readonly LockType $type, diff --git a/src/Psl/File/LockType.php b/src/Psl/File/LockType.php index 27532366..ae0ecfb5 100644 --- a/src/Psl/File/LockType.php +++ b/src/Psl/File/LockType.php @@ -11,11 +11,11 @@ enum LockType * commonly called a reader lock. The creation of a Lock will block until * the lock is acquired. */ - case SHARED; + case Shared; /** * Only a single process may possess an exclusive lock to a given file at a * time. The creation of a Lock will block until the lock is acquired. */ - case EXCLUSIVE; + case Exclusive; } diff --git a/src/Psl/File/ReadWriteHandle.php b/src/Psl/File/ReadWriteHandle.php index 400e3f1d..a5aec5ba 100644 --- a/src/Psl/File/ReadWriteHandle.php +++ b/src/Psl/File/ReadWriteHandle.php @@ -25,14 +25,14 @@ final class ReadWriteHandle extends Internal\AbstractHandleWrapper implements Re * @throws Exception\NotReadableException If $file exists, and is non-readable. * @throws Exception\RuntimeException If unable to create the $file if it does not exist. */ - public function __construct(string $file, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE) + public function __construct(string $file, WriteMode $write_mode = WriteMode::OpenOrCreate) { $is_file = Filesystem\is_file($file); if (!$is_file && Filesystem\exists($file)) { throw Exception\NotFileException::for($file); } - $must_create = $write_mode === WriteMode::MUST_CREATE; + $must_create = $write_mode === WriteMode::MustCreate; if ($must_create && $is_file) { throw Exception\AlreadyCreatedException::for($file); } diff --git a/src/Psl/File/WriteHandle.php b/src/Psl/File/WriteHandle.php index 28664cfc..d1671fdb 100644 --- a/src/Psl/File/WriteHandle.php +++ b/src/Psl/File/WriteHandle.php @@ -23,14 +23,14 @@ final class WriteHandle extends Internal\AbstractHandleWrapper implements WriteH * @throws Exception\NotWritableException If $file is non-writable. * @throws Exception\RuntimeException If unable to create the $file if it does not exist. */ - public function __construct(string $file, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE) + public function __construct(string $file, WriteMode $write_mode = WriteMode::OpenOrCreate) { $is_file = Filesystem\is_file($file); if (!$is_file && Filesystem\exists($file)) { throw Exception\NotFileException::for($file); } - $must_create = $write_mode === WriteMode::MUST_CREATE; + $must_create = $write_mode === WriteMode::MustCreate; if ($must_create && $is_file) { throw Exception\AlreadyCreatedException::for($file); } diff --git a/src/Psl/File/WriteMode.php b/src/Psl/File/WriteMode.php index d3d955a3..7bac7a6e 100644 --- a/src/Psl/File/WriteMode.php +++ b/src/Psl/File/WriteMode.php @@ -10,29 +10,29 @@ enum WriteMode: string * Open the file for writing only; place the file pointer at the beginning of * the file. * - * If the file exits, it is not truncated (as with `TRUNCATE`), and the call - * succeeds (unlike `MUST_CREATE`). + * If the file exits, it is not truncated (as with `Truncate`), and the call + * succeeds (unlike `MustCreate`). */ - case OPEN_OR_CREATE = 'cb'; + case OpenOrCreate = 'cb'; /** * Open for writing only; place the file pointer at the beginning of the * file and truncate the file to zero length. If the file does not exist, * attempt to create it. */ - case TRUNCATE = 'wb'; + case Truncate = 'wb'; /** * Open for writing only; place the file pointer at the end of the file. If * the file does not exist, attempt to create it. In this mode, seeking has * no effect, writes are always appended. */ - case APPEND = 'ab'; + case Append = 'ab'; /** * Create and open for writing only; place the file pointer at the beginning * of the file. If the file already exists, the filesystem call will throw an * exception. If the file does not exist, attempt to create it. */ - case MUST_CREATE = 'xb'; + case MustCreate = 'xb'; } diff --git a/src/Psl/File/open_read_write.php b/src/Psl/File/open_read_write.php index af74c749..a8a041ac 100644 --- a/src/Psl/File/open_read_write.php +++ b/src/Psl/File/open_read_write.php @@ -16,7 +16,7 @@ * @throws Exception\NotReadableException If $file exists, and is non-readable. * @throws Exception\RuntimeException If unable to create the $file if it does not exist. */ -function open_read_write(string $path, WriteMode $write_mode = WriteMode::OPEN_OR_CREATE): ReadWriteHandleInterface +function open_read_write(string $path, WriteMode $write_mode = WriteMode::OpenOrCreate): ReadWriteHandleInterface { return new ReadWriteHandle($path, $write_mode); } diff --git a/src/Psl/File/open_write_only.php b/src/Psl/File/open_write_only.php index b6c2683d..ac83c215 100644 --- a/src/Psl/File/open_write_only.php +++ b/src/Psl/File/open_write_only.php @@ -15,7 +15,7 @@ * @throws Exception\NotWritableException If $file exists, and is non-writable. * @throws Exception\RuntimeException If unable to create the $file if it does not exist. */ -function open_write_only(string $file, WriteMode $mode = WriteMode::OPEN_OR_CREATE): WriteHandleInterface +function open_write_only(string $file, WriteMode $mode = WriteMode::OpenOrCreate): WriteHandleInterface { return new WriteHandle($file, $mode); } diff --git a/src/Psl/File/read.php b/src/Psl/File/read.php index da3ee836..2ac6e9c3 100644 --- a/src/Psl/File/read.php +++ b/src/Psl/File/read.php @@ -24,7 +24,7 @@ function read(string $file, int $offset = 0, ?int $length = null): string { try { $handle = namespace\open_read_only($file); - $lock = $handle->lock(namespace\LockType::SHARED); + $lock = $handle->lock(namespace\LockType::Shared); $handle->seek($offset); $content = $handle->readAll($length); diff --git a/src/Psl/File/write.php b/src/Psl/File/write.php index 912a763b..fab7728c 100644 --- a/src/Psl/File/write.php +++ b/src/Psl/File/write.php @@ -21,13 +21,13 @@ * @throws Exception\NotWritableException If $file exists, and is non-writable. * @throws Exception\RuntimeException In case of an error. */ -function write(string $file, string $content, WriteMode $mode = WriteMode::OPEN_OR_CREATE): void +function write(string $file, string $content, WriteMode $mode = WriteMode::OpenOrCreate): void { clearstatcache(); try { $handle = File\open_write_only($file, $mode); - $lock = $handle->lock(File\LockType::EXCLUSIVE); + $lock = $handle->lock(File\LockType::Exclusive); $handle->writeAll($content); diff --git a/src/Psl/Filesystem/copy.php b/src/Psl/Filesystem/copy.php index 194b7bde..f49b9ca6 100644 --- a/src/Psl/Filesystem/copy.php +++ b/src/Psl/Filesystem/copy.php @@ -40,11 +40,11 @@ function copy(string $source, string $destination, bool $overwrite = false): voi $source_handle = File\open_read_only($source); $destination_handle = File\open_write_only( $destination, - $destination_exists ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE, + $destination_exists ? File\WriteMode::Truncate : File\WriteMode::OpenOrCreate, ); - $source_lock = $source_handle->lock(File\LockType::SHARED); - $destination_lock = $destination_handle->lock(File\LockType::EXCLUSIVE); + $source_lock = $source_handle->lock(File\LockType::Shared); + $destination_lock = $destination_handle->lock(File\LockType::Exclusive); while ($chunk = $source_handle->read()) { $destination_handle->writeAll($chunk); diff --git a/src/Psl/Hash/Algorithm.php b/src/Psl/Hash/Algorithm.php index be227e12..0ee12cd6 100644 --- a/src/Psl/Hash/Algorithm.php +++ b/src/Psl/Hash/Algorithm.php @@ -6,64 +6,64 @@ enum Algorithm: string { - case MD2 = "md2"; - case MD4 = "md4"; - case MD5 = "md5"; - case SHA1 = "sha1"; - case SHA224 = "sha224"; - case SHA256 = "sha256"; - case SHA384 = "sha384"; - case SHA512_224 = "sha512/224"; - case SHA512_256 = "sha512/256"; - case SHA512 = "sha512"; - case SHA3_224 = "sha3-224"; - case SHA3_256 = "sha3-256"; - case SHA3_384 = "sha3-384"; - case SHA3_512 = "sha3-512"; - case RIPEMD_128 = "ripemd128"; - case RIPEMD_160 = "ripemd160"; - case RIPEMD_256 = "ripemd256"; - case RIPEMD_320 = "ripemd320"; - case WHIRLPOOL = "whirlpool"; - case TIGER128_3 = "tiger128,3"; - case TIGER160_3 = "tiger160,3"; - case TIGER192_3 = "tiger192,3"; - case TIGER128_4 = "tiger128,4"; - case TIGER160_4 = "tiger160,4"; - case TIGER192_4 = "tiger192,4"; - case SNEFRU = "snefru"; - case SNEFRU_256 = "snefru256"; - case GOST = "gost"; - case GOST_CRYPTO = "gost-crypto"; - case ADLER32 = "adler32"; - case CRC32 = "crc32"; - case CRC32B = "crc32b"; - case CRC32C = "crc32c"; - case FNV132 = "fnv132"; - case FNV1A32 = "fnv1a32"; - case FNV164 = "fnv164"; - case FNV1A64 = "fnv1a64"; - case JOAAT = "joaat"; - case MURMUR3A = "murmur3a"; - case MURMUR3C = "murmur3c"; - case MURMUR3F = "murmur3f"; - case XXH32 = "xxh32"; - case XXH64 = "xxh64"; - case XXH3 = "xxh3"; - case XXH128 = "xxh128"; - case HAVAL128_3 = "haval128,3"; - case HAVAL160_3 = "haval160,3"; - case HAVAL192_3 = "haval192,3"; - case HAVAL224_3 = "haval224,3"; - case HAVAL256_3 = "haval256,3"; - case HAVAL128_4 = "haval128,4"; - case HAVAL160_4 = "haval160,4"; - case HAVAL192_4 = "haval192,4"; - case HAVAL224_4 = "haval224,4"; - case HAVAL256_4 = "haval256,4"; - case HAVAL128_5 = "haval128,5"; - case HAVAL160_5 = "haval160,5"; - case HAVAL192_5 = "haval192,5"; - case HAVAL224_5 = "haval224,5"; - case HAVAL256_5 = "haval256,5"; + case Md2 = "md2"; + case Md4 = "md4"; + case Md5 = "md5"; + case Sha1 = "sha1"; + case Sha224 = "sha224"; + case Sha256 = "sha256"; + case Sha384 = "sha384"; + case Sha512224 = "sha512/224"; + case Sha512256 = "sha512/256"; + case Sha512 = "sha512"; + case Sha3224 = "sha3-224"; + case Sha3256 = "sha3-256"; + case Sha3384 = "sha3-384"; + case Sha3512 = "sha3-512"; + case Ripemd128 = "ripemd128"; + case Ripemd160 = "ripemd160"; + case Ripemd256 = "ripemd256"; + case Ripemd320 = "ripemd320"; + case Whirlpool = "whirlpool"; + case Tiger1283 = "tiger128,3"; + case Tiger1603 = "tiger160,3"; + case Tiger1923 = "tiger192,3"; + case Tiger1284 = "tiger128,4"; + case Tiger1604 = "tiger160,4"; + case Tiger1924 = "tiger192,4"; + case Snefru = "snefru"; + case Snefru256 = "snefru256"; + case Gost = "gost"; + case GostCrypto = "gost-crypto"; + case Adler32 = "adler32"; + case Crc32 = "crc32"; + case Crc32B = "crc32b"; + case Crc32C = "crc32c"; + case Fnv132 = "fnv132"; + case Fnv1A32 = "fnv1a32"; + case Fnv164 = "fnv164"; + case Fnv1A64 = "fnv1a64"; + case Joaat = "joaat"; + case Murmur3A = "murmur3a"; + case Murmur3C = "murmur3c"; + case Murmur3F = "murmur3f"; + case Xxh32 = "xxh32"; + case Xxh64 = "xxh64"; + case Xxh3 = "xxh3"; + case Xxh128 = "xxh128"; + case Haval1283 = "haval128,3"; + case Haval1603 = "haval160,3"; + case Haval1923 = "haval192,3"; + case Haval2243 = "haval224,3"; + case Haval2563 = "haval256,3"; + case Haval1284 = "haval128,4"; + case Haval1604 = "haval160,4"; + case Haval1924 = "haval192,4"; + case Haval2244 = "haval224,4"; + case Haval2564 = "haval256,4"; + case Haval1285 = "haval128,5"; + case Haval1605 = "haval160,5"; + case Haval1925 = "haval192,5"; + case Haval2245 = "haval224,5"; + case Haval2565 = "haval256,5"; } diff --git a/src/Psl/Hash/Context.php b/src/Psl/Hash/Context.php index 5d755eb7..b2982fee 100644 --- a/src/Psl/Hash/Context.php +++ b/src/Psl/Hash/Context.php @@ -17,21 +17,22 @@ * * Example: * - * Hash\Context::forAlgorithm('md5') + * Hash\Context::forAlgorithm(Hash\Algorithm::Md5) * ->update('The quick brown fox ') * ->update('jumped over the lazy dog.') * ->finalize() * => Str("5c6ffbdd40d9556b73a21e63c3e0e904") * - * @psalm-immutable + * @immutable */ final class Context { - private HashContext $internalContext; - - private function __construct(HashContext $internal_context) - { - $this->internalContext = $internal_context; + /** + * @pure + */ + private function __construct( + private readonly HashContext $internalContext + ) { } /** @@ -63,9 +64,9 @@ public static function hmac(Hmac\Algorithm $algorithm, string $key): Context /** * Pump data into an active hashing context. * - * @psalm-mutation-free - * * @throws Exception\RuntimeException If unable to pump data into the active hashing context. + * + * @psalm-mutation-free */ public function update(string $data): Context { diff --git a/src/Psl/Hash/Hmac/Algorithm.php b/src/Psl/Hash/Hmac/Algorithm.php index acc0fa47..e8c430a6 100644 --- a/src/Psl/Hash/Hmac/Algorithm.php +++ b/src/Psl/Hash/Hmac/Algorithm.php @@ -6,48 +6,48 @@ enum Algorithm: string { - case MD2 = "md2"; - case MD4 = "md4"; - case MD5 = "md5"; - case SHA1 = "sha1"; - case SHA224 = "sha224"; - case SHA256 = "sha256"; - case SHA384 = "sha384"; - case SHA512_224 = "sha512/224"; - case SHA512_256 = "sha512/256"; - case SHA512 = "sha512"; - case SHA3_224 = "sha3-224"; - case SHA3_256 = "sha3-256"; - case SHA3_384 = "sha3-384"; - case SHA3_512 = "sha3-512"; - case RIPEMD_128 = "ripemd128"; - case RIPEMD_160 = "ripemd160"; - case RIPEMD_256 = "ripemd256"; - case RIPEMD_320 = "ripemd320"; - case WHIRLPOOL = "whirlpool"; - case TIGER128_3 = "tiger128,3"; - case TIGER160_3 = "tiger160,3"; - case TIGER192_3 = "tiger192,3"; - case TIGER128_4 = "tiger128,4"; - case TIGER160_4 = "tiger160,4"; - case TIGER192_4 = "tiger192,4"; - case SNEFRU = "snefru"; - case SNEFRU_256 = "snefru256"; - case GOST = "gost"; - case GOST_CRYPTO = "gost-crypto"; - case HAVAL128_3 = "haval128,3"; - case HAVAL160_3 = "haval160,3"; - case HAVAL192_3 = "haval192,3"; - case HAVAL224_3 = "haval224,3"; - case HAVAL256_3 = "haval256,3"; - case HAVAL128_4 = "haval128,4"; - case HAVAL160_4 = "haval160,4"; - case HAVAL192_4 = "haval192,4"; - case HAVAL224_4 = "haval224,4"; - case HAVAL256_4 = "haval256,4"; - case HAVAL128_5 = "haval128,5"; - case HAVAL160_5 = "haval160,5"; - case HAVAL192_5 = "haval192,5"; - case HAVAL224_5 = "haval224,5"; - case HAVAL256_5 = "haval256,5"; + case Md2 = "md2"; + case Md4 = "md4"; + case Md5 = "md5"; + case Sha1 = "sha1"; + case Sha224 = "sha224"; + case Sha256 = "sha256"; + case Sha384 = "sha384"; + case Sha512224 = "sha512/224"; + case Sha512256 = "sha512/256"; + case Sha512 = "sha512"; + case Sha3224 = "sha3-224"; + case Sha3256 = "sha3-256"; + case Sha3384 = "sha3-384"; + case Sha3512 = "sha3-512"; + case Ripemd128 = "ripemd128"; + case Ripemd160 = "ripemd160"; + case Ripemd256 = "ripemd256"; + case Ripemd320 = "ripemd320"; + case Whirlpool = "whirlpool"; + case Tiger1283 = "tiger128,3"; + case Tiger1603 = "tiger160,3"; + case Tiger1923 = "tiger192,3"; + case Tiger1284 = "tiger128,4"; + case Tiger1604 = "tiger160,4"; + case Tiger1924 = "tiger192,4"; + case Snefru = "snefru"; + case Snefru256 = "snefru256"; + case Gost = "gost"; + case GostCrypto = "gost-crypto"; + case Haval1283 = "haval128,3"; + case Haval1603 = "haval160,3"; + case Haval1923 = "haval192,3"; + case Haval2243 = "haval224,3"; + case Haval2563 = "haval256,3"; + case Haval1284 = "haval128,4"; + case Haval1604 = "haval160,4"; + case Haval1924 = "haval192,4"; + case Haval2244 = "haval224,4"; + case Haval2564 = "haval256,4"; + case Haval1285 = "haval128,5"; + case Haval1605 = "haval160,5"; + case Haval1925 = "haval192,5"; + case Haval2245 = "haval224,5"; + case Haval2565 = "haval256,5"; } diff --git a/src/Psl/Html/Encoding.php b/src/Psl/Html/Encoding.php index 69ca0762..7a3d27ae 100644 --- a/src/Psl/Html/Encoding.php +++ b/src/Psl/Html/Encoding.php @@ -13,53 +13,78 @@ * HTML documents and web development. It includes various Unicode, Western European, * Cyrillic, Chinese, Japanese, and other character sets to support internationalization * and localization of web content. - * - * Implementing the DefaultInterface, it provides a method to obtain a default encoding, - * which is UTF-8 due to its wide compatibility and support for a vast range of characters. */ enum Encoding: string implements DefaultInterface { - // ASCII compatible multi-byte 8-bit Unicode. - case UTF_8 = 'UTF-8'; + /** + * ASCII compatible multi-byte 8-bit Unicode. + */ + case Utf8 = 'UTF-8'; - // Western European, Latin-1. - case ISO_8859_1 = 'ISO-8859-1'; + /** + * Western European, Latin-1. + */ + case Iso88591 = 'ISO-8859-1'; - // Western European, Latin-9. - case ISO_8859_15 = 'ISO-8859-15'; + /** + * Western European, Latin-9. + */ + case Iso885915 = 'ISO-8859-15'; - // Cyrillic charset (Latin/Cyrillic). - case ISO_8859_5 = 'ISO-8859-5'; + /** + * Cyrillic charset (Latin/Cyrillic). + */ + case Iso88595 = 'ISO-8859-5'; - // DOS-specific Cyrillic charset. - case CP_866 = 'cp866'; + /** + * DOS-specific Cyrillic charset. + */ + case Cp866 = 'cp866'; - // Windows-specific Cyrillic charset. - case CP_1251 = 'cp1251'; + /** + * Windows-specific Cyrillic charset. + */ + case Cp1251 = 'cp1251'; - // Windows specific charset for Western European. - case CP_1252 = 'cp1252'; + /** + * Windows specific charset for Western European. + */ + case Cp1252 = 'cp1252'; - // Russian. - case KOI8_R = 'KOI8-R'; + /** + * Russian. + */ + case Koi8R = 'KOI8-R'; - // Traditional Chinese, mainly used in Taiwan. - case BIG5 = 'BIG5'; + /** + * Traditional Chinese. + */ + case Big5 = 'BIG5'; - // Simplified Chinese, national standard character set. - case GB2312 = 'GB2312'; + /** + * Simplified Chinese, national standard character set. + */ + case Gb2312 = 'GB2312'; - // Big5 with Hong Kong extensions, Traditional Chinese. - case BIG5_HKSCS = 'BIG5-HKSCS'; + /** + * Traditional Chinese ( Big5 with Hong Kong extensions ). + */ + case Big5Hkscs = 'BIG5-HKSCS'; - // Japanese - case SHIFT_JIS = 'Shift_JIS'; + /** + * Japanese. + */ + case ShiftJis = 'Shift_JIS'; - // Japanese - case EUC_JP = 'EUC-JP'; + /** + * Japanese. + */ + case EucJp = 'EUC-JP'; - // Charset that was used by Mac OS. - case MAC_ROMAN = 'MacRoman'; + /** + * Charset that was used by macOS. + */ + case MacRoman = 'MacRoman'; /** * Provides the default character encoding. @@ -73,6 +98,6 @@ enum Encoding: string implements DefaultInterface */ public static function default(): static { - return self::UTF_8; + return self::Utf8; } } diff --git a/src/Psl/Html/decode.php b/src/Psl/Html/decode.php index 0d06dad2..f668ff26 100644 --- a/src/Psl/Html/decode.php +++ b/src/Psl/Html/decode.php @@ -15,7 +15,7 @@ * * @pure */ -function decode(string $html, Encoding $encoding = Encoding::UTF_8): string +function decode(string $html, Encoding $encoding = Encoding::Utf8): string { return html_entity_decode($html, ENT_QUOTES, $encoding->value); } diff --git a/src/Psl/Html/encode.php b/src/Psl/Html/encode.php index c26b8cf0..b69bbc18 100644 --- a/src/Psl/Html/encode.php +++ b/src/Psl/Html/encode.php @@ -19,7 +19,7 @@ * * @pure */ -function encode(string $html, bool $double_encoding = true, Encoding $encoding = Encoding::UTF_8): string +function encode(string $html, bool $double_encoding = true, Encoding $encoding = Encoding::Utf8): string { return htmlentities($html, ENT_QUOTES, $encoding->value, $double_encoding); } diff --git a/src/Psl/Html/encode_special_characters.php b/src/Psl/Html/encode_special_characters.php index 21698e47..b1c49ed0 100644 --- a/src/Psl/Html/encode_special_characters.php +++ b/src/Psl/Html/encode_special_characters.php @@ -21,7 +21,7 @@ * * @pure */ -function encode_special_characters(string $html, bool $double_encoding = true, Encoding $encoding = Encoding::UTF_8): string +function encode_special_characters(string $html, bool $double_encoding = true, Encoding $encoding = Encoding::Utf8): string { return htmlspecialchars($html, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, $encoding->value, $double_encoding); } diff --git a/src/Psl/Network/Address.php b/src/Psl/Network/Address.php index cc54eb82..d33dafff 100644 --- a/src/Psl/Network/Address.php +++ b/src/Psl/Network/Address.php @@ -23,12 +23,12 @@ public static function create(SocketScheme $scheme, string $host, ?int $port = n public static function unix(string $host): self { - return new self(SocketScheme::UNIX, $host, null); + return new self(SocketScheme::Unix, $host, null); } public static function tcp(string $host = self::DEFAULT_HOST, int $port = self::DEFAULT_PORT): self { - return new self(SocketScheme::TCP, $host, $port); + return new self(SocketScheme::Tcp, $host, $port); } /** diff --git a/src/Psl/Network/Internal/get_peer_name.php b/src/Psl/Network/Internal/get_peer_name.php index b027ecf1..f64472e7 100644 --- a/src/Psl/Network/Internal/get_peer_name.php +++ b/src/Psl/Network/Internal/get_peer_name.php @@ -30,7 +30,7 @@ function get_peer_name(mixed $socket): Network\Address return Network\Address::unix($result); } - $scheme = Network\SocketScheme::TCP; + $scheme = Network\SocketScheme::Tcp; $host = substr($result, 0, $separator_position); $port = (int) substr($result, $separator_position + 1); diff --git a/src/Psl/Network/SocketScheme.php b/src/Psl/Network/SocketScheme.php index e5c9c01a..1ac2f367 100644 --- a/src/Psl/Network/SocketScheme.php +++ b/src/Psl/Network/SocketScheme.php @@ -9,6 +9,6 @@ */ enum SocketScheme: string { - case TCP = 'tcp'; - case UNIX = 'unix'; + case Tcp = 'tcp'; + case Unix = 'unix'; } diff --git a/src/Psl/Str/Encoding.php b/src/Psl/Str/Encoding.php index c0f27fd0..8d1776a2 100644 --- a/src/Psl/Str/Encoding.php +++ b/src/Psl/Str/Encoding.php @@ -15,83 +15,83 @@ */ enum Encoding: string implements DefaultInterface { - case BASE64 = 'BASE64'; - case UUENCODE = 'UUENCODE'; - case HTML_ENTITIES = 'HTML-ENTITIES'; - case QUOTED_PRINTABLE = 'Quoted-Printable'; - case ASCII_7BIT = '7bit'; - case ASCII_8BIT = '8bit'; - case UCS_4 = 'UCS-4'; - case UCS_4BE = 'UCS-4BE'; - case UCS_4LE = 'UCS-4LE'; - case UCS_2 = 'UCS-2'; - case UCS_2BE = 'UCS-2BE'; - case UCS_2LE = 'UCS-2LE'; - case UTF_32 = 'UTF-32'; - case UTF_32BE = 'UTF-32BE'; - case UTF_32LE = 'UTF-32LE'; - case UTF_16 = 'UTF-16'; - case UTF_16BE = 'UTF-16BE'; - case UTF_16LE = 'UTF-16LE'; - case UTF_8 = 'UTF-8'; - case UTF_7 = 'UTF-7'; - case UTF7_IMAP = 'UTF7-IMAP'; - case ASCII = 'ASCII'; - case EUC_JP = 'EUC-JP'; - case SJIS = 'SJIS'; - case EUCJP_WIN = 'eucJP-win'; - case EUC_JP_2004 = 'EUC-JP-2004'; - case SJIS_MOBILE_DOCOMO = 'SJIS-Mobile#DOCOMO'; - case SJIS_MOBILE_KDDI = 'SJIS-Mobile#KDDI'; - case SJIS_MOBILE_SOFTBANK = 'SJIS-Mobile#SOFTBANK'; - case SJIS_MAC = 'SJIS-mac'; - case SJIS_2004 = 'SJIS-2004'; - case UTF_8_MOBILE_DOCOMO = 'UTF-8-Mobile#DOCOMO'; - case UTF_8_MOBILE_KDDI_A = 'UTF-8-Mobile#KDDI-A'; - case UTF_8_MOBILE_KDDI_B = 'UTF-8-Mobile#KDDI-B'; - case UTF_8_MOBILE_SOFTBANK = 'UTF-8-Mobile#SOFTBANK'; - case CP932 = 'CP932'; - case CP51932 = 'CP51932'; - case JIS = 'JIS'; - case ISO_2022_JP = 'ISO-2022-JP'; - case ISO_2022_JP_MS = 'ISO-2022-JP-MS'; - case GB18030 = 'GB18030'; - case WINDOWS_1252 = 'Windows-1252'; - case WINDOWS_1254 = 'Windows-1254'; - case ISO_8859_1 = 'ISO-8859-1'; - case ISO_8859_2 = 'ISO-8859-2'; - case ISO_8859_3 = 'ISO-8859-3'; - case ISO_8859_4 = 'ISO-8859-4'; - case ISO_8859_5 = 'ISO-8859-5'; - case ISO_8859_6 = 'ISO-8859-6'; - case ISO_8859_7 = 'ISO-8859-7'; - case ISO_8859_8 = 'ISO-8859-8'; - case ISO_8859_9 = 'ISO-8859-9'; - case ISO_8859_10 = 'ISO-8859-10'; - case ISO_8859_13 = 'ISO-8859-13'; - case ISO_8859_14 = 'ISO-8859-14'; - case ISO_8859_15 = 'ISO-8859-15'; - case ISO_8859_16 = 'ISO-8859-16'; - case EUC_CN = 'EUC-CN'; - case CP936 = 'CP936'; - case HZ = 'HZ'; - case EUC_TW = 'EUC-TW'; - case BIG_5 = 'BIG-5'; - case CP950 = 'CP950'; - case EUC_KR = 'EUC-KR'; - case UHC = 'UHC'; - case ISO_2022_KR = 'ISO-2022-KR'; - case WINDOWS_1251 = 'Windows-1251'; - case CP866 = 'CP866'; - case KOI8_R = 'KOI8-R'; - case KOI8_U = 'KOI8-U'; - case ARMSCII_8 = 'ArmSCII-8'; - case CP850 = 'CP850'; - case ISO_2022_JP_2004 = 'ISO-2022-JP-2004'; - case ISO_2022_JP_MOBILE_KDDI = 'ISO-2022-JP-MOBILE#KDDI'; - case CP50220 = 'CP50220'; - case CP50221 = 'CP50221'; - case CP50222 = 'CP50222'; + case Base64 = 'BASE64'; + case Uuencode = 'UUENCODE'; + case HtmlEntities = 'HTML-ENTITIES'; + case QuotedPrintable = 'Quoted-Printable'; + case Ascii7bit = '7bit'; + case Ascii8bit = '8bit'; + case Ucs4 = 'UCS-4'; + case Ucs4be = 'UCS-4BE'; + case Ucs4le = 'UCS-4LE'; + case Ucs2 = 'UCS-2'; + case Ucs2be = 'UCS-2BE'; + case Ucs2le = 'UCS-2LE'; + case Utf32 = 'UTF-32'; + case Utf32be = 'UTF-32BE'; + case Utf32le = 'UTF-32LE'; + case Utf16 = 'UTF-16'; + case Utf16be = 'UTF-16BE'; + case Utf16le = 'UTF-16LE'; + case Utf8 = 'UTF-8'; + case Utf7 = 'UTF-7'; + case Utf7Imap = 'UTF7-IMAP'; + case Ascii = 'ASCII'; + case EucJp = 'EUC-JP'; + case Sjis = 'SJIS'; + case EucjpWin = 'eucJP-win'; + case EucJp2004 = 'EUC-JP-2004'; + case SjisMobileDocomo = 'SJIS-Mobile#DOCOMO'; + case SjisMobileKddi = 'SJIS-Mobile#KDDI'; + case SjisMobileSoftbank = 'SJIS-Mobile#SOFTBANK'; + case SjisMac = 'SJIS-mac'; + case Sjis2004 = 'SJIS-2004'; + case Utf8MobileDocomo = 'UTF-8-Mobile#DOCOMO'; + case Utf8MobileKddiA = 'UTF-8-Mobile#KDDI-A'; + case Utf8MobileKddiB = 'UTF-8-Mobile#KDDI-B'; + case Utf8MobileSoftbank = 'UTF-8-Mobile#SOFTBANK'; + case Cp932 = 'CP932'; + case Cp51932 = 'CP51932'; + case Jis = 'JIS'; + case Iso2022Jp = 'ISO-2022-JP'; + case Iso2022JpMs = 'ISO-2022-JP-MS'; + case Gb18030 = 'GB18030'; + case Windows1252 = 'Windows-1252'; + case Windows1254 = 'Windows-1254'; + case Iso88591 = 'ISO-8859-1'; + case Iso88592 = 'ISO-8859-2'; + case Iso88593 = 'ISO-8859-3'; + case Iso88594 = 'ISO-8859-4'; + case Iso88595 = 'ISO-8859-5'; + case Iso88596 = 'ISO-8859-6'; + case Iso88597 = 'ISO-8859-7'; + case Iso88598 = 'ISO-8859-8'; + case Iso88599 = 'ISO-8859-9'; + case Iso885910 = 'ISO-8859-10'; + case Iso885913 = 'ISO-8859-13'; + case Iso885914 = 'ISO-8859-14'; + case Iso885915 = 'ISO-8859-15'; + case Iso885916 = 'ISO-8859-16'; + case EucCn = 'EUC-CN'; + case Cp936 = 'CP936'; + case Hz = 'HZ'; + case EucTw = 'EUC-TW'; + case Big5 = 'BIG-5'; + case Cp950 = 'CP950'; + case EucKr = 'EUC-KR'; + case Uhc = 'UHC'; + case Iso2022Kr = 'ISO-2022-KR'; + case Windows1251 = 'Windows-1251'; + case Cp866 = 'CP866'; + case Koi8R = 'KOI8-R'; + case Koi8U = 'KOI8-U'; + case Armscii8 = 'ArmSCII-8'; + case Cp850 = 'CP850'; + case Iso2022Jp2004 = 'ISO-2022-JP-2004'; + case Iso2022JpMobileKodi = 'ISO-2022-JP-MOBILE#KDDI'; + case Cp50220 = 'CP50220'; + case Cp50221 = 'CP50221'; + case Cp50222 = 'CP50222'; /** * Provides the default character encoding. @@ -106,6 +106,6 @@ enum Encoding: string implements DefaultInterface */ public static function default(): static { - return self::UTF_8; + return self::Utf8; } } diff --git a/src/Psl/Str/after.php b/src/Psl/Str/after.php index c6bfa6dc..a019796a 100644 --- a/src/Psl/Str/after.php +++ b/src/Psl/Str/after.php @@ -9,7 +9,7 @@ * * @pure */ -function after(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function after(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $position = search($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_ci.php b/src/Psl/Str/after_ci.php index 70884f84..bec05b66 100644 --- a/src/Psl/Str/after_ci.php +++ b/src/Psl/Str/after_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function after_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function after_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $position = search_ci($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_last.php b/src/Psl/Str/after_last.php index 432e237b..d0f43749 100644 --- a/src/Psl/Str/after_last.php +++ b/src/Psl/Str/after_last.php @@ -9,7 +9,7 @@ * * @pure */ -function after_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function after_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $position = search_last($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_last_ci.php b/src/Psl/Str/after_last_ci.php index f56e2705..f1a6d795 100644 --- a/src/Psl/Str/after_last_ci.php +++ b/src/Psl/Str/after_last_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function after_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function after_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $position = search_last_ci($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/before.php b/src/Psl/Str/before.php index cb908154..447a2194 100644 --- a/src/Psl/Str/before.php +++ b/src/Psl/Str/before.php @@ -9,7 +9,7 @@ * * @pure */ -function before(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function before(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $length = search($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/before_ci.php b/src/Psl/Str/before_ci.php index cf56c8ee..304faea4 100644 --- a/src/Psl/Str/before_ci.php +++ b/src/Psl/Str/before_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function before_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function before_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $length = search_ci($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/before_last.php b/src/Psl/Str/before_last.php index 12ef414c..4133a049 100644 --- a/src/Psl/Str/before_last.php +++ b/src/Psl/Str/before_last.php @@ -9,7 +9,7 @@ * * @pure */ -function before_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function before_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $length = search_last($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/before_last_ci.php b/src/Psl/Str/before_last_ci.php index 44f763e4..cc1cd9c3 100644 --- a/src/Psl/Str/before_last_ci.php +++ b/src/Psl/Str/before_last_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function before_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?string +function before_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string { $length = search_last_ci($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/capitalize.php b/src/Psl/Str/capitalize.php index ad9aa781..5c4b7440 100644 --- a/src/Psl/Str/capitalize.php +++ b/src/Psl/Str/capitalize.php @@ -26,7 +26,7 @@ * * @pure */ -function capitalize(string $string, Encoding $encoding = Encoding::UTF_8): string +function capitalize(string $string, Encoding $encoding = Encoding::Utf8): string { if ('' === $string) { return ''; diff --git a/src/Psl/Str/capitalize_words.php b/src/Psl/Str/capitalize_words.php index 8dc4aad3..124ffe83 100644 --- a/src/Psl/Str/capitalize_words.php +++ b/src/Psl/Str/capitalize_words.php @@ -27,7 +27,7 @@ * * @pure */ -function capitalize_words(string $string, Encoding $encoding = Encoding::UTF_8): string +function capitalize_words(string $string, Encoding $encoding = Encoding::Utf8): string { return mb_convert_case($string, MB_CASE_TITLE, $encoding->value); } diff --git a/src/Psl/Str/chr.php b/src/Psl/Str/chr.php index e1028279..110bbd7f 100644 --- a/src/Psl/Str/chr.php +++ b/src/Psl/Str/chr.php @@ -19,7 +19,7 @@ * * @pure */ -function chr(int $codepoint, Encoding $encoding = Encoding::UTF_8): string +function chr(int $codepoint, Encoding $encoding = Encoding::Utf8): string { return (string) mb_chr($codepoint, $encoding->value); } diff --git a/src/Psl/Str/chunk.php b/src/Psl/Str/chunk.php index 0b4a43be..32e949aa 100644 --- a/src/Psl/Str/chunk.php +++ b/src/Psl/Str/chunk.php @@ -31,7 +31,7 @@ * * @pure */ -function chunk(string $string, int $chunk_length = 1, Encoding $encoding = Encoding::UTF_8): array +function chunk(string $string, int $chunk_length = 1, Encoding $encoding = Encoding::Utf8): array { if ('' === $string) { return []; diff --git a/src/Psl/Str/contains.php b/src/Psl/Str/contains.php index 635430fd..547d36b7 100644 --- a/src/Psl/Str/contains.php +++ b/src/Psl/Str/contains.php @@ -36,7 +36,7 @@ * * @throws Exception\OutOfBoundsException If the $offset is out-of-bounds. */ -function contains(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): bool +function contains(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): bool { if ('' === $needle) { return Internal\validate_offset($offset, length($haystack, $encoding), true); diff --git a/src/Psl/Str/contains_ci.php b/src/Psl/Str/contains_ci.php index f5df7faf..9cab7221 100644 --- a/src/Psl/Str/contains_ci.php +++ b/src/Psl/Str/contains_ci.php @@ -36,7 +36,7 @@ * * @throws Exception\OutOfBoundsException If the $offset is out-of-bounds. */ -function contains_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): bool +function contains_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): bool { if ('' === $needle) { return Internal\validate_offset($offset, length($haystack, $encoding), true); diff --git a/src/Psl/Str/ends_with.php b/src/Psl/Str/ends_with.php index 98343bc5..1597dc8e 100644 --- a/src/Psl/Str/ends_with.php +++ b/src/Psl/Str/ends_with.php @@ -32,7 +32,7 @@ * * @pure */ -function ends_with(string $string, string $suffix, Encoding $encoding = Encoding::UTF_8): bool +function ends_with(string $string, string $suffix, Encoding $encoding = Encoding::Utf8): bool { if ($suffix === $string) { return true; diff --git a/src/Psl/Str/ends_with_ci.php b/src/Psl/Str/ends_with_ci.php index d27c3b77..66303aee 100644 --- a/src/Psl/Str/ends_with_ci.php +++ b/src/Psl/Str/ends_with_ci.php @@ -32,7 +32,7 @@ * * @pure */ -function ends_with_ci(string $string, string $suffix, Encoding $encoding = Encoding::UTF_8): bool +function ends_with_ci(string $string, string $suffix, Encoding $encoding = Encoding::Utf8): bool { if ($suffix === $string) { return true; diff --git a/src/Psl/Str/fold.php b/src/Psl/Str/fold.php index 2004ba0a..10acba1d 100644 --- a/src/Psl/Str/fold.php +++ b/src/Psl/Str/fold.php @@ -16,7 +16,7 @@ * * @pure */ -function fold(string $string, Encoding $encoding = Encoding::UTF_8): string +function fold(string $string, Encoding $encoding = Encoding::Utf8): string { foreach (Internal\CASE_FOLD as $k => $v) { $string = replace($string, $k, $v, $encoding); diff --git a/src/Psl/Str/is_utf8.php b/src/Psl/Str/is_utf8.php index 4e7dfc69..8a306425 100644 --- a/src/Psl/Str/is_utf8.php +++ b/src/Psl/Str/is_utf8.php @@ -13,5 +13,5 @@ */ function is_utf8(string $string): bool { - return null !== detect_encoding($string, [Encoding::UTF_8]); + return null !== detect_encoding($string, [Encoding::Utf8]); } diff --git a/src/Psl/Str/length.php b/src/Psl/Str/length.php index 15284d1c..afc3f0a7 100644 --- a/src/Psl/Str/length.php +++ b/src/Psl/Str/length.php @@ -24,7 +24,7 @@ * * @return int<0, max> */ -function length(string $string, Encoding $encoding = Encoding::UTF_8): int +function length(string $string, Encoding $encoding = Encoding::Utf8): int { /** @var int<0, max> */ return mb_strlen($string, $encoding->value); diff --git a/src/Psl/Str/lowercase.php b/src/Psl/Str/lowercase.php index cce3a9e6..136687da 100644 --- a/src/Psl/Str/lowercase.php +++ b/src/Psl/Str/lowercase.php @@ -27,7 +27,7 @@ * * @pure */ -function lowercase(string $string, Encoding $encoding = Encoding::UTF_8): string +function lowercase(string $string, Encoding $encoding = Encoding::Utf8): string { return mb_strtolower($string, $encoding->value); } diff --git a/src/Psl/Str/ord.php b/src/Psl/Str/ord.php index 3830fd5c..dec9c354 100644 --- a/src/Psl/Str/ord.php +++ b/src/Psl/Str/ord.php @@ -19,7 +19,7 @@ * * @pure */ -function ord(string $character, Encoding $encoding = Encoding::UTF_8): int +function ord(string $character, Encoding $encoding = Encoding::Utf8): int { return mb_ord($character, $encoding->value); } diff --git a/src/Psl/Str/pad_left.php b/src/Psl/Str/pad_left.php index e7e7f792..670c41af 100644 --- a/src/Psl/Str/pad_left.php +++ b/src/Psl/Str/pad_left.php @@ -31,7 +31,7 @@ * * @pure */ -function pad_left(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::UTF_8): string +function pad_left(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::Utf8): string { while (($length = length($string, $encoding)) < $total_length) { /** @var int<0, max> $remaining */ diff --git a/src/Psl/Str/pad_right.php b/src/Psl/Str/pad_right.php index bbf32860..9afcf2c2 100644 --- a/src/Psl/Str/pad_right.php +++ b/src/Psl/Str/pad_right.php @@ -31,7 +31,7 @@ * * @pure */ -function pad_right(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::UTF_8): string +function pad_right(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::Utf8): string { while (($length = length($string, $encoding)) < $total_length) { /** @var int<0, max> $remaining */ diff --git a/src/Psl/Str/range.php b/src/Psl/Str/range.php index a14326bd..db0d4a54 100644 --- a/src/Psl/Str/range.php +++ b/src/Psl/Str/range.php @@ -38,7 +38,7 @@ * * @pure */ -function range(string $string, RangeInterface $range, Encoding $encoding = Encoding::UTF_8): string +function range(string $string, RangeInterface $range, Encoding $encoding = Encoding::Utf8): string { $offset = 0; $length = null; diff --git a/src/Psl/Str/replace.php b/src/Psl/Str/replace.php index 87687ed3..af590531 100644 --- a/src/Psl/Str/replace.php +++ b/src/Psl/Str/replace.php @@ -12,7 +12,7 @@ * * @pure */ -function replace(string $haystack, string $needle, string $replacement, Encoding $encoding = Encoding::UTF_8): string +function replace(string $haystack, string $needle, string $replacement, Encoding $encoding = Encoding::Utf8): string { if ('' === $needle || null === search($haystack, $needle, 0, $encoding)) { return $haystack; diff --git a/src/Psl/Str/replace_ci.php b/src/Psl/Str/replace_ci.php index 4b2c5137..473c8467 100644 --- a/src/Psl/Str/replace_ci.php +++ b/src/Psl/Str/replace_ci.php @@ -17,7 +17,7 @@ * * @throws Exception\InvalidArgumentException if $needle is not a valid UTF-8 string. */ -function replace_ci(string $haystack, string $needle, string $replacement, Encoding $encoding = Encoding::UTF_8): string +function replace_ci(string $haystack, string $needle, string $replacement, Encoding $encoding = Encoding::Utf8): string { if ('' === $needle || null === search_ci($haystack, $needle, 0, $encoding)) { return $haystack; diff --git a/src/Psl/Str/replace_every.php b/src/Psl/Str/replace_every.php index d00ca677..e23efe13 100644 --- a/src/Psl/Str/replace_every.php +++ b/src/Psl/Str/replace_every.php @@ -12,7 +12,7 @@ * * @pure */ -function replace_every(string $haystack, array $replacements, Encoding $encoding = Encoding::UTF_8): string +function replace_every(string $haystack, array $replacements, Encoding $encoding = Encoding::Utf8): string { foreach ($replacements as $needle => $replacement) { $haystack = replace($haystack, $needle, $replacement, $encoding); diff --git a/src/Psl/Str/replace_every_ci.php b/src/Psl/Str/replace_every_ci.php index f1b23e43..a14a9a68 100644 --- a/src/Psl/Str/replace_every_ci.php +++ b/src/Psl/Str/replace_every_ci.php @@ -12,7 +12,7 @@ * * @pure */ -function replace_every_ci(string $haystack, array $replacements, Encoding $encoding = Encoding::UTF_8): string +function replace_every_ci(string $haystack, array $replacements, Encoding $encoding = Encoding::Utf8): string { foreach ($replacements as $needle => $replacement) { if ('' === $needle || null === search_ci($haystack, $needle, 0, $encoding)) { diff --git a/src/Psl/Str/reverse.php b/src/Psl/Str/reverse.php index bbca1a9f..9200a9ef 100644 --- a/src/Psl/Str/reverse.php +++ b/src/Psl/Str/reverse.php @@ -11,7 +11,7 @@ * * @psalm-pure */ -function reverse(string $string, Encoding $encoding = Encoding::UTF_8): string +function reverse(string $string, Encoding $encoding = Encoding::Utf8): string { $chunks = chunk($string, encoding: $encoding); diff --git a/src/Psl/Str/search.php b/src/Psl/Str/search.php index 5c3cd50c..2f6892fa 100644 --- a/src/Psl/Str/search.php +++ b/src/Psl/Str/search.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?int +function search(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/search_ci.php b/src/Psl/Str/search_ci.php index 615c4e97..3889043c 100644 --- a/src/Psl/Str/search_ci.php +++ b/src/Psl/Str/search_ci.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?int +function search_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/search_last.php b/src/Psl/Str/search_last.php index 027f89c9..01e7f26f 100644 --- a/src/Psl/Str/search_last.php +++ b/src/Psl/Str/search_last.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?int +function search_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/search_last_ci.php b/src/Psl/Str/search_last_ci.php index 35bd1d9b..21048a47 100644 --- a/src/Psl/Str/search_last_ci.php +++ b/src/Psl/Str/search_last_ci.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::UTF_8): ?int +function search_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/slice.php b/src/Psl/Str/slice.php index 8145e564..cd59f657 100644 --- a/src/Psl/Str/slice.php +++ b/src/Psl/Str/slice.php @@ -20,7 +20,7 @@ * * @pure */ -function slice(string $string, int $offset, ?int $length = null, Encoding $encoding = Encoding::UTF_8): string +function slice(string $string, int $offset, ?int $length = null, Encoding $encoding = Encoding::Utf8): string { $string_length = length($string, $encoding); $offset = Internal\validate_offset($offset, $string_length); diff --git a/src/Psl/Str/splice.php b/src/Psl/Str/splice.php index 7fc0237c..09606313 100644 --- a/src/Psl/Str/splice.php +++ b/src/Psl/Str/splice.php @@ -23,7 +23,7 @@ function splice( string $replacement, int $offset = 0, ?int $length = null, - Encoding $encoding = Encoding::UTF_8 + Encoding $encoding = Encoding::Utf8 ): string { $total_length = length($string, $encoding); $offset = Internal\validate_offset($offset, $total_length); diff --git a/src/Psl/Str/split.php b/src/Psl/Str/split.php index 6c9eb14b..af586ec2 100644 --- a/src/Psl/Str/split.php +++ b/src/Psl/Str/split.php @@ -19,7 +19,7 @@ * * @pure */ -function split(string $string, string $delimiter, ?int $limit = null, Encoding $encoding = Encoding::UTF_8): array +function split(string $string, string $delimiter, ?int $limit = null, Encoding $encoding = Encoding::Utf8): array { if ('' === $delimiter) { if (null === $limit || $limit >= length($string, $encoding)) { diff --git a/src/Psl/Str/starts_with.php b/src/Psl/Str/starts_with.php index c0e80232..dce321e1 100644 --- a/src/Psl/Str/starts_with.php +++ b/src/Psl/Str/starts_with.php @@ -9,7 +9,7 @@ * * @pure */ -function starts_with(string $string, string $prefix, Encoding $encoding = Encoding::UTF_8): bool +function starts_with(string $string, string $prefix, Encoding $encoding = Encoding::Utf8): bool { /** @psalm-suppress MissingThrowsDocblock */ return 0 === search($string, $prefix, 0, $encoding); diff --git a/src/Psl/Str/starts_with_ci.php b/src/Psl/Str/starts_with_ci.php index ebf7e5f9..b9e2789c 100644 --- a/src/Psl/Str/starts_with_ci.php +++ b/src/Psl/Str/starts_with_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function starts_with_ci(string $string, string $prefix, Encoding $encoding = Encoding::UTF_8): bool +function starts_with_ci(string $string, string $prefix, Encoding $encoding = Encoding::Utf8): bool { /** @psalm-suppress MissingThrowsDocblock */ return 0 === search_ci($string, $prefix, 0, $encoding); diff --git a/src/Psl/Str/strip_prefix.php b/src/Psl/Str/strip_prefix.php index c07bf435..eb94c758 100644 --- a/src/Psl/Str/strip_prefix.php +++ b/src/Psl/Str/strip_prefix.php @@ -10,7 +10,7 @@ * * @pure */ -function strip_prefix(string $string, string $prefix, Encoding $encoding = Encoding::UTF_8): string +function strip_prefix(string $string, string $prefix, Encoding $encoding = Encoding::Utf8): string { if ($prefix === $string) { return ''; diff --git a/src/Psl/Str/strip_suffix.php b/src/Psl/Str/strip_suffix.php index aace7a30..7dbd74d3 100644 --- a/src/Psl/Str/strip_suffix.php +++ b/src/Psl/Str/strip_suffix.php @@ -10,7 +10,7 @@ * * @pure */ -function strip_suffix(string $string, string $suffix, Encoding $encoding = Encoding::UTF_8): string +function strip_suffix(string $string, string $suffix, Encoding $encoding = Encoding::Utf8): string { if ($string === '' || $suffix === '') { return $string; diff --git a/src/Psl/Str/truncate.php b/src/Psl/Str/truncate.php index e1810dd3..7f163163 100644 --- a/src/Psl/Str/truncate.php +++ b/src/Psl/Str/truncate.php @@ -27,7 +27,7 @@ function truncate( int $offset, int $width, ?string $trim_marker = null, - Encoding $encoding = Encoding::UTF_8 + Encoding $encoding = Encoding::Utf8 ): string { $offset = Internal\validate_offset($offset, length($string, $encoding)); diff --git a/src/Psl/Str/uppercase.php b/src/Psl/Str/uppercase.php index 81721a17..399118fa 100644 --- a/src/Psl/Str/uppercase.php +++ b/src/Psl/Str/uppercase.php @@ -11,7 +11,7 @@ * * @pure */ -function uppercase(string $string, Encoding $encoding = Encoding::UTF_8): string +function uppercase(string $string, Encoding $encoding = Encoding::Utf8): string { return mb_strtoupper($string, $encoding->value); } diff --git a/src/Psl/Str/width.php b/src/Psl/Str/width.php index d145db88..85ac6b71 100644 --- a/src/Psl/Str/width.php +++ b/src/Psl/Str/width.php @@ -11,7 +11,7 @@ * * @pure */ -function width(string $string, Encoding $encoding = Encoding::UTF_8): int +function width(string $string, Encoding $encoding = Encoding::Utf8): int { return mb_strwidth($string, $encoding->value); } diff --git a/src/Psl/Str/wrap.php b/src/Psl/Str/wrap.php index 36042d5d..52105db7 100644 --- a/src/Psl/Str/wrap.php +++ b/src/Psl/Str/wrap.php @@ -17,7 +17,7 @@ * * @pure */ -function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = false, Encoding $encoding = Encoding::UTF_8): string +function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = false, Encoding $encoding = Encoding::Utf8): string { if ('' === $string) { return ''; diff --git a/tests/unit/File/LockTest.php b/tests/unit/File/LockTest.php index f8149aa2..fb602ae8 100644 --- a/tests/unit/File/LockTest.php +++ b/tests/unit/File/LockTest.php @@ -16,15 +16,15 @@ public function testRelease(): void $file = Filesystem\create_temporary_file(); $handle = File\open_read_write($file); - $lock = $handle->lock(File\LockType::EXCLUSIVE); + $lock = $handle->lock(File\LockType::Exclusive); - static::assertSame(File\LockType::EXCLUSIVE, $lock->type); + static::assertSame(File\LockType::Exclusive, $lock->type); $lock->release(); - $lock = $handle->tryLock(File\LockType::SHARED); + $lock = $handle->tryLock(File\LockType::Shared); - static::assertSame(File\LockType::SHARED, $lock->type); + static::assertSame(File\LockType::Shared, $lock->type); $lock->release(); } @@ -38,7 +38,7 @@ public function testLockingClosedFile(): void $this->expectException(AlreadyClosedException::class); $this->expectExceptionMessage('Handle has already been closed.'); - $handle->lock(File\LockType::EXCLUSIVE); + $handle->lock(File\LockType::Exclusive); } public function testReleasingALockOnAClosedFile(): void @@ -46,9 +46,9 @@ public function testReleasingALockOnAClosedFile(): void $file = Filesystem\create_temporary_file(); $handle = File\open_read_write($file); - $lock = $handle->lock(File\LockType::EXCLUSIVE); + $lock = $handle->lock(File\LockType::Exclusive); - static::assertSame(File\LockType::EXCLUSIVE, $lock->type); + static::assertSame(File\LockType::Exclusive, $lock->type); $handle->close(); @@ -63,9 +63,9 @@ public function testReleasingALockOnAClosedFileUsingDestructor(): void $file = Filesystem\create_temporary_file(); $handle = File\open_read_write($file); - $lock = $handle->lock(File\LockType::EXCLUSIVE); + $lock = $handle->lock(File\LockType::Exclusive); - static::assertSame(File\LockType::EXCLUSIVE, $lock->type); + static::assertSame(File\LockType::Exclusive, $lock->type); $handle->close(); @@ -80,15 +80,15 @@ public function testReleasingASecondTimeAfterClosingTheFile(): void $file = Filesystem\create_temporary_file(); $handle = File\open_read_write($file); - $lock = $handle->lock(File\LockType::EXCLUSIVE); + $lock = $handle->lock(File\LockType::Exclusive); - static::assertSame(File\LockType::EXCLUSIVE, $lock->type); + static::assertSame(File\LockType::Exclusive, $lock->type); $lock->release(); - $lock = $handle->tryLock(File\LockType::SHARED); + $lock = $handle->tryLock(File\LockType::Shared); - static::assertSame(File\LockType::SHARED, $lock->type); + static::assertSame(File\LockType::Shared, $lock->type); $lock->release(); $handle->close(); diff --git a/tests/unit/File/ReadWriteHandleTest.php b/tests/unit/File/ReadWriteHandleTest.php index f85f50f2..7cd833ba 100644 --- a/tests/unit/File/ReadWriteHandleTest.php +++ b/tests/unit/File/ReadWriteHandleTest.php @@ -84,7 +84,7 @@ public function testMustCreateExistingFile(): void $this->expectException(File\Exception\AlreadyCreatedException::class); $this->expectExceptionMessage('is already created.'); - new File\ReadWriteHandle(__FILE__, File\WriteMode::MUST_CREATE); + new File\ReadWriteHandle(__FILE__, File\WriteMode::MustCreate); } public function testAppendToNonExistingFile(): void @@ -94,7 +94,7 @@ public function testAppendToNonExistingFile(): void static::assertFalse(Filesystem\is_file($temporary_file)); - $handle = File\open_read_write($temporary_file, File\WriteMode::APPEND); + $handle = File\open_read_write($temporary_file, File\WriteMode::Append); $handle->writeAll('hello'); $handle->seek(0); @@ -119,7 +119,7 @@ public function testAppendToANonWritableFile(): void $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('File "' . $temporary_file . '" is not writable.'); - new File\ReadWriteHandle($temporary_file, File\WriteMode::APPEND); + new File\ReadWriteHandle($temporary_file, File\WriteMode::Append); } public function testOpenNonReadableFile(): void @@ -134,7 +134,7 @@ public function testOpenNonReadableFile(): void $this->expectException(File\Exception\NotReadableException::class); $this->expectExceptionMessage('File "' . $temporary_file . '" is not readable.'); - new File\ReadWriteHandle($temporary_file, File\WriteMode::APPEND); + new File\ReadWriteHandle($temporary_file, File\WriteMode::Append); } public function testThrowsWhenCreatingFile(): void @@ -153,7 +153,7 @@ public function testThrowsWhenCreatingFile(): void $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('File "' . $file . '" is not writable.'); - new File\ReadWriteHandle($file, File\WriteMode::MUST_CREATE); + new File\ReadWriteHandle($file, File\WriteMode::MustCreate); } public function testOpenDirectory(): void @@ -161,7 +161,7 @@ public function testOpenDirectory(): void $this->expectException(File\Exception\NotFileException::class); $this->expectExceptionMessage('Path "' . Env\temp_dir() . '" does not point to a file.'); - new File\ReadWriteHandle(Env\temp_dir(), File\WriteMode::APPEND); + new File\ReadWriteHandle(Env\temp_dir(), File\WriteMode::Append); } public function testCreateNonExisting(): void @@ -171,7 +171,7 @@ public function testCreateNonExisting(): void static::assertFalse(Filesystem\is_file($temporary_file)); - $handle = File\open_read_write($temporary_file, File\WriteMode::MUST_CREATE); + $handle = File\open_read_write($temporary_file, File\WriteMode::MustCreate); $handle->tryWrite('hello'); $handle->seek(0); @@ -235,11 +235,11 @@ public function provideOperations(): iterable ]; yield [ - static fn(File\HandleInterface $handle) => $handle->lock(File\LockType::EXCLUSIVE), + static fn(File\HandleInterface $handle) => $handle->lock(File\LockType::Exclusive), ]; yield [ - static fn(File\HandleInterface $handle) => $handle->tryLock(File\LockType::EXCLUSIVE), + static fn(File\HandleInterface $handle) => $handle->tryLock(File\LockType::Exclusive), ]; yield [ diff --git a/tests/unit/File/ReadWriteTest.php b/tests/unit/File/ReadWriteTest.php index d62cdc74..f1a1b9db 100644 --- a/tests/unit/File/ReadWriteTest.php +++ b/tests/unit/File/ReadWriteTest.php @@ -27,11 +27,11 @@ public function testWriteFile(): void static::assertStringEqualsFile($file, 'Hello!'); - File\write($file, 'Hello', mode: File\WriteMode::TRUNCATE); + File\write($file, 'Hello', mode: File\WriteMode::Truncate); static::assertStringEqualsFile($file, 'Hello'); - File\write($file, ', World!', mode: File\WriteMode::APPEND); + File\write($file, ', World!', mode: File\WriteMode::Append); static::assertStringEqualsFile($file, 'Hello, World!'); @@ -44,7 +44,7 @@ public function testWriteFileWithTruncateWriteModeCreatesFile(): void static::assertFileDoesNotExist($file); - File\write($file, 'Hello!', File\WriteMode::TRUNCATE); + File\write($file, 'Hello!', File\WriteMode::Truncate); static::assertFileExists($file); @@ -61,7 +61,7 @@ public function testWriteFileClearsFileStat(): void static::assertSame(5, Filesystem\file_size($file)); - File\write($file, ', World!', mode: File\WriteMode::APPEND); + File\write($file, ', World!', mode: File\WriteMode::Append); static::assertSame(13, Filesystem\file_size($file)); @@ -81,7 +81,7 @@ public function testAppendFileThrowsForDirectories(): void $this->expectException(File\Exception\NotFileException::class); $this->expectExceptionMessage('Path "' . $this->directory . '" does not point to a file.'); - File\write($this->directory, 'hello', mode: File\WriteMode::APPEND); + File\write($this->directory, 'hello', mode: File\WriteMode::Append); } public function testReadFileThrowsForDirectories(): void @@ -113,8 +113,8 @@ public function testRead(): void { $file = Str\join([$this->directory, 'write.txt'], Filesystem\SEPARATOR); File\write($file, 'PHP Standard Library'); - File\write($file, ' - a modern, consistent, centralized', mode: File\WriteMode::APPEND); - File\write($file, ' well-typed set of APIs for PHP programmers.', mode: File\WriteMode::APPEND); + File\write($file, ' - a modern, consistent, centralized', mode: File\WriteMode::Append); + File\write($file, ' well-typed set of APIs for PHP programmers.', mode: File\WriteMode::Append); $content = File\read($file, 0, 20); @@ -139,6 +139,6 @@ public function testThrowsWhenDirectoryCreationFails(): void $this->expectException(File\Exception\RuntimeException::class); $this->expectExceptionMessage('Failed to create the directory for file "' . $target_file . '".'); - new File\ReadWriteHandle($target_file, File\WriteMode::MUST_CREATE); + new File\ReadWriteHandle($target_file, File\WriteMode::MustCreate); } } diff --git a/tests/unit/File/WriteHandleTest.php b/tests/unit/File/WriteHandleTest.php index bccf8c55..ef12c68d 100644 --- a/tests/unit/File/WriteHandleTest.php +++ b/tests/unit/File/WriteHandleTest.php @@ -17,7 +17,7 @@ public function testMustCreateExistingFile(): void $this->expectException(File\Exception\AlreadyCreatedException::class); $this->expectExceptionMessage('already created.'); - new File\WriteHandle(__FILE__, File\WriteMode::MUST_CREATE); + new File\WriteHandle(__FILE__, File\WriteMode::MustCreate); } public function testAppendToNonExistingFile(): void @@ -27,7 +27,7 @@ public function testAppendToNonExistingFile(): void static::assertFalse(Filesystem\is_file($temporary_file)); - $handle = new File\WriteHandle($temporary_file, File\WriteMode::APPEND); + $handle = new File\WriteHandle($temporary_file, File\WriteMode::Append); $handle->close(); static::assertTrue(Filesystem\is_file($temporary_file)); @@ -41,7 +41,7 @@ public function testAppendToANonWritableFile(): void $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('is not writable.'); - new File\WriteHandle($temporary_file, File\WriteMode::APPEND); + new File\WriteHandle($temporary_file, File\WriteMode::Append); } public function testWriting(): void @@ -77,7 +77,7 @@ public function testThrowsWhenCreatingFile(): void $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('File "' . $file . '" is not writable.'); - new File\WriteHandle($file, File\WriteMode::MUST_CREATE); + new File\WriteHandle($file, File\WriteMode::MustCreate); } public function testCreateNonExisting(): void @@ -87,7 +87,7 @@ public function testCreateNonExisting(): void static::assertFalse(Filesystem\is_file($temporary_file)); - $handle = new File\WriteHandle($temporary_file, File\WriteMode::MUST_CREATE); + $handle = new File\WriteHandle($temporary_file, File\WriteMode::MustCreate); $handle->close(); static::assertTrue(Filesystem\is_file($temporary_file)); @@ -107,6 +107,6 @@ public function testThrowsWhenDirectoryCreationFails(): void $this->expectException(File\Exception\RuntimeException::class); $this->expectExceptionMessage('Failed to create the directory for file "' . $target_file . '".'); - new File\WriteHandle($target_file, File\WriteMode::MUST_CREATE); + new File\WriteHandle($target_file, File\WriteMode::MustCreate); } } diff --git a/tests/unit/Fun/TapTest.php b/tests/unit/Fun/TapTest.php index 709f48d6..8e4046f0 100644 --- a/tests/unit/Fun/TapTest.php +++ b/tests/unit/Fun/TapTest.php @@ -32,14 +32,14 @@ public function testItCanBeCombinedInOtherFlowsForDebugging(): void { $log = new Ref(''); $result = Fun\pipe( - static fn (string $x) => Hash\hash($x, Hash\Algorithm::MD5), + static fn (string $x) => Hash\hash($x, Hash\Algorithm::Md5), Fun\tap(static function ($x) use ($log): void { $log->value = $x; }), static fn (string $x): string => Str\truncate($x, 0, 1), )('abc'); - $md5 = Hash\hash('abc', Hash\Algorithm::MD5); + $md5 = Hash\hash('abc', Hash\Algorithm::Md5); $firstChar = Str\truncate($md5, 0, 1); static::assertSame($firstChar, $result); diff --git a/tests/unit/Hash/ContextTest.php b/tests/unit/Hash/ContextTest.php index 52b6c4fc..5503d4c6 100644 --- a/tests/unit/Hash/ContextTest.php +++ b/tests/unit/Hash/ContextTest.php @@ -11,7 +11,7 @@ final class ContextTest extends TestCase { public function testForAlgorithm(): void { - $context = Hash\Context::forAlgorithm(Hash\Algorithm::MD5) + $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5) ->update('The quick brown fox ') ->update('jumped over the lazy dog.'); @@ -20,7 +20,7 @@ public function testForAlgorithm(): void public function testHmac(): void { - $context = Hash\Context::hmac(Hash\Hmac\Algorithm::MD5, 'secret') + $context = Hash\Context::hmac(Hash\Hmac\Algorithm::Md5, 'secret') ->update('The quick brown fox ') ->update('jumped over the lazy dog.'); @@ -29,7 +29,7 @@ public function testHmac(): void public function testContextIsImmutable(): void { - $first = Hash\Context::forAlgorithm(Hash\Algorithm::MD5); + $first = Hash\Context::forAlgorithm(Hash\Algorithm::Md5); $second = $first->update('The quick brown fox '); $third = $second->update('jumped over the lazy dog.'); @@ -44,7 +44,7 @@ public function testContextIsImmutable(): void public function testContextIsStillValidAfterFinalization(): void { - $context = Hash\Context::forAlgorithm(Hash\Algorithm::MD5) + $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5) ->update('The quick brown fox ') ->update('jumped over the lazy dog.'); diff --git a/tests/unit/Hash/HashTest.php b/tests/unit/Hash/HashTest.php index bf0af65b..0ec1f052 100644 --- a/tests/unit/Hash/HashTest.php +++ b/tests/unit/Hash/HashTest.php @@ -26,7 +26,7 @@ public function testHash(string $expected, string $data, Hash\Algorithm $algorit */ public function provideHashData(): Generator { - yield ['2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', 'hello world', Hash\Algorithm::SHA1]; - yield ['5eb63bbbe01eeed093cb22bb8f5acdc3', 'hello world', Hash\Algorithm::MD5]; + yield ['2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', 'hello world', Hash\Algorithm::Sha1]; + yield ['5eb63bbbe01eeed093cb22bb8f5acdc3', 'hello world', Hash\Algorithm::Md5]; } } diff --git a/tests/unit/Hash/Hmac/HashTest.php b/tests/unit/Hash/Hmac/HashTest.php index 417a68de..f66dc5ed 100644 --- a/tests/unit/Hash/Hmac/HashTest.php +++ b/tests/unit/Hash/Hmac/HashTest.php @@ -27,7 +27,7 @@ public function testHash(string $expected, string $data, Hmac\Algorithm $algorit */ public function provideHashData(): Generator { - yield ['03376ee7ad7bbfceee98660439a4d8b125122a5a', 'hello world', Hmac\Algorithm::SHA1, 'secret']; - yield ['78d6997b1230f38e59b6d1642dfaa3a4', 'hello world', Hmac\Algorithm::MD5, 'secret']; + yield ['03376ee7ad7bbfceee98660439a4d8b125122a5a', 'hello world', Hmac\Algorithm::Sha1, 'secret']; + yield ['78d6997b1230f38e59b6d1642dfaa3a4', 'hello world', Hmac\Algorithm::Md5, 'secret']; } } diff --git a/tests/unit/Html/DecodeTest.php b/tests/unit/Html/DecodeTest.php index 3b3b6708..b41ea388 100644 --- a/tests/unit/Html/DecodeTest.php +++ b/tests/unit/Html/DecodeTest.php @@ -19,16 +19,16 @@ public function testEncode(string $expected, string $html, Html\Encoding $encodi public function provideData(): iterable { - yield ['hello', 'hello', Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', Html\Encoding::UTF_8]; - yield ['', '<hello />', Html\Encoding::UTF_8]; - yield ['

Hello

', '<p>Hello</p>', Html\Encoding::UTF_8]; - yield ['

<

', '<p>&lt; </p>', Html\Encoding::UTF_8]; + yield ['hello', 'hello', Html\Encoding::Utf8]; + yield ['héllo', 'héllo', Html\Encoding::Utf8]; + yield ['', '<hello />', Html\Encoding::Utf8]; + yield ['

Hello

', '<p>Hello</p>', Html\Encoding::Utf8]; + yield ['

<

', '<p>&lt; </p>', Html\Encoding::Utf8]; - yield ['hello', 'hello', Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', Html\Encoding::UTF_8]; - yield ['', '<hello />', Html\Encoding::UTF_8]; - yield ['

Hello

', '<p>Hello</p>', Html\Encoding::UTF_8]; - yield ['

<

', '<p>< </p>', Html\Encoding::UTF_8]; + yield ['hello', 'hello', Html\Encoding::Utf8]; + yield ['héllo', 'héllo', Html\Encoding::Utf8]; + yield ['', '<hello />', Html\Encoding::Utf8]; + yield ['

Hello

', '<p>Hello</p>', Html\Encoding::Utf8]; + yield ['

<

', '<p>< </p>', Html\Encoding::Utf8]; } } diff --git a/tests/unit/Html/EncodeSpecialCharactersTest.php b/tests/unit/Html/EncodeSpecialCharactersTest.php index 7b16f209..94bf7114 100644 --- a/tests/unit/Html/EncodeSpecialCharactersTest.php +++ b/tests/unit/Html/EncodeSpecialCharactersTest.php @@ -19,16 +19,16 @@ public function testEncode(string $expected, string $html, bool $double_encoding public function provideData(): iterable { - yield ['hello', 'hello', true, Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', true, Html\Encoding::UTF_8]; - yield ['<hello />', '', true, Html\Encoding::UTF_8]; - yield ['<p>Hello</p>', '

Hello

', true, Html\Encoding::UTF_8]; - yield ['<p>&lt; </p>', '

<

', true, Html\Encoding::UTF_8]; + yield ['hello', 'hello', true, Html\Encoding::Utf8]; + yield ['héllo', 'héllo', true, Html\Encoding::Utf8]; + yield ['<hello />', '', true, Html\Encoding::Utf8]; + yield ['<p>Hello</p>', '

Hello

', true, Html\Encoding::Utf8]; + yield ['<p>&lt; </p>', '

<

', true, Html\Encoding::Utf8]; - yield ['hello', 'hello', false, Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', false, Html\Encoding::UTF_8]; - yield ['<hello />', '', false, Html\Encoding::UTF_8]; - yield ['<p>Hello</p>', '

Hello

', false, Html\Encoding::UTF_8]; - yield ['<p>< </p>', '

<

', false, Html\Encoding::UTF_8]; + yield ['hello', 'hello', false, Html\Encoding::Utf8]; + yield ['héllo', 'héllo', false, Html\Encoding::Utf8]; + yield ['<hello />', '', false, Html\Encoding::Utf8]; + yield ['<p>Hello</p>', '

Hello

', false, Html\Encoding::Utf8]; + yield ['<p>< </p>', '

<

', false, Html\Encoding::Utf8]; } } diff --git a/tests/unit/Html/EncodeTest.php b/tests/unit/Html/EncodeTest.php index 58d42e88..737f3bb5 100644 --- a/tests/unit/Html/EncodeTest.php +++ b/tests/unit/Html/EncodeTest.php @@ -19,16 +19,16 @@ public function testEncode(string $expected, string $html, bool $double_encoding public function provideData(): iterable { - yield ['hello', 'hello', true, Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', true, Html\Encoding::UTF_8]; - yield ['<hello />', '', true, Html\Encoding::UTF_8]; - yield ['<p>Hello</p>', '

Hello

', true, Html\Encoding::UTF_8]; - yield ['<p>&lt; </p>', '

<

', true, Html\Encoding::UTF_8]; + yield ['hello', 'hello', true, Html\Encoding::Utf8]; + yield ['héllo', 'héllo', true, Html\Encoding::Utf8]; + yield ['<hello />', '', true, Html\Encoding::Utf8]; + yield ['<p>Hello</p>', '

Hello

', true, Html\Encoding::Utf8]; + yield ['<p>&lt; </p>', '

<

', true, Html\Encoding::Utf8]; - yield ['hello', 'hello', false, Html\Encoding::UTF_8]; - yield ['héllo', 'héllo', false, Html\Encoding::UTF_8]; - yield ['<hello />', '', false, Html\Encoding::UTF_8]; - yield ['<p>Hello</p>', '

Hello

', false, Html\Encoding::UTF_8]; - yield ['<p>< </p>', '

<

', false, Html\Encoding::UTF_8]; + yield ['hello', 'hello', false, Html\Encoding::Utf8]; + yield ['héllo', 'héllo', false, Html\Encoding::Utf8]; + yield ['<hello />', '', false, Html\Encoding::Utf8]; + yield ['<p>Hello</p>', '

Hello

', false, Html\Encoding::Utf8]; + yield ['<p>< </p>', '

<

', false, Html\Encoding::Utf8]; } } diff --git a/tests/unit/Str/AfterCiTest.php b/tests/unit/Str/AfterCiTest.php index 83c31cac..44ee754e 100644 --- a/tests/unit/Str/AfterCiTest.php +++ b/tests/unit/Str/AfterCiTest.php @@ -25,22 +25,22 @@ public function testAfter( public function provideData(): array { return [ - [null, '', '', 0, Str\Encoding::UTF_8], - ['orld!', 'Hello, World!', 'W', 0, Str\Encoding::UTF_8], - ['!', '🤷!', '🤷', 0, Str\Encoding::UTF_8], - [null, 'مرحبا بكم', '', 0, Str\Encoding::UTF_8], - [null, 'مرحبا بكم', 'ß', 0, Str\Encoding::UTF_8], - [', wôrld!', 'héllö, wôrld!', 'héllö', 0, Str\Encoding::UTF_8], - [', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, Str\Encoding::UTF_8], - [', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0, Str\Encoding::UTF_8], - [', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, Str\Encoding::UTF_8], - [', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0, Str\Encoding::UTF_8], - ['好', '你好', '你', 0, Str\Encoding::UTF_8], - ['にちは世界', 'こんにちは世界', 'こん', 0, Str\Encoding::UTF_8], - ['สดี', 'สวัสดี', 'วั', 0, Str\Encoding::UTF_8], - [', world!', 'Hello, world!', 'o', 0, Str\Encoding::UTF_8], - ['rld!', 'Hello, world!', 'o', 7, Str\Encoding::UTF_8], - ['rld!', 'Hello, world!', 'o', 7, Str\Encoding::ASCII], + [null, '', '', 0, Str\Encoding::Utf8], + ['orld!', 'Hello, World!', 'W', 0, Str\Encoding::Utf8], + ['!', '🤷!', '🤷', 0, Str\Encoding::Utf8], + [null, 'مرحبا بكم', '', 0, Str\Encoding::Utf8], + [null, 'مرحبا بكم', 'ß', 0, Str\Encoding::Utf8], + [', wôrld!', 'héllö, wôrld!', 'héllö', 0, Str\Encoding::Utf8], + [', wôrld!', 'ḫéllö, wôrld!', 'ḫéllö', 0, Str\Encoding::Utf8], + [', wôrld!', 'ḫéllö, wôrld!', 'Ḫéllö', 0, Str\Encoding::Utf8], + [', wôrld!', 'Ḫéllö, wôrld!', 'Ḫéllö', 0, Str\Encoding::Utf8], + [', wôrld!', 'Ḫéllö, wôrld!', 'ḫéllö', 0, Str\Encoding::Utf8], + ['好', '你好', '你', 0, Str\Encoding::Utf8], + ['にちは世界', 'こんにちは世界', 'こん', 0, Str\Encoding::Utf8], + ['สดี', 'สวัสดี', 'วั', 0, Str\Encoding::Utf8], + [', world!', 'Hello, world!', 'o', 0, Str\Encoding::Utf8], + ['rld!', 'Hello, world!', 'o', 7, Str\Encoding::Utf8], + ['rld!', 'Hello, world!', 'o', 7, Str\Encoding::Ascii], ]; } } diff --git a/tests/unit/Str/ConvertEncodingTest.php b/tests/unit/Str/ConvertEncodingTest.php index 7ddcb8cd..9f2b3a62 100644 --- a/tests/unit/Str/ConvertEncodingTest.php +++ b/tests/unit/Str/ConvertEncodingTest.php @@ -24,7 +24,7 @@ public function testConvertEncoding( public function provideData(): array { return [ - ['åäö', 'åäö', Str\Encoding::ISO_8859_1, Str\Encoding::UTF_8], + ['åäö', 'åäö', Str\Encoding::Iso88591, Str\Encoding::Utf8], ]; } } diff --git a/tests/unit/Str/DetectEncodingTest.php b/tests/unit/Str/DetectEncodingTest.php index 16a4f001..49391a15 100644 --- a/tests/unit/Str/DetectEncodingTest.php +++ b/tests/unit/Str/DetectEncodingTest.php @@ -20,9 +20,9 @@ public function testDetectEncoding(?Str\Encoding $expected, string $string): voi public function provideData(): array { return [ - [Str\Encoding::ASCII, 'hello'], - [Str\Encoding::UTF_8, 'سيف'], - [Str\Encoding::UTF_8, '🐘'], + [Str\Encoding::Ascii, 'hello'], + [Str\Encoding::Utf8, 'سيف'], + [Str\Encoding::Utf8, '🐘'], [null, Str\Byte\chr(128)] ]; }