From 4409a42c45f16b180de6d559ea8beb2989be36bc Mon Sep 17 00:00:00 2001 From: Samantha Nguyen Date: Sun, 10 Dec 2023 20:22:45 -0600 Subject: [PATCH] chore: make classes readonly+final where applicable All classes are now final + readonly, except `MediaTypeParserException` which is only final since `Exception` is not readonly. --- src/MediaType.php | 8 ++++---- src/MediaTypeParser.php | 2 +- src/MediaTypeParserException.php | 2 +- src/Utf8Utils.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/MediaType.php b/src/MediaType.php index 681f769..60d187a 100644 --- a/src/MediaType.php +++ b/src/MediaType.php @@ -9,24 +9,24 @@ * @see https://mimesniff.spec.whatwg.org/ * @license MIT */ -class MediaType implements Stringable { +final readonly class MediaType implements Stringable { /** * @see https://mimesniff.spec.whatwg.org/#type * @var string */ - private $type; + private string $type; /** * @see https://mimesniff.spec.whatwg.org/#subtype * @var string */ - private $subType; + private string $subType; /** * @see https://mimesniff.spec.whatwg.org/#parameters * @var string[] */ - private $parameters; + private array $parameters; /** * @param string $type diff --git a/src/MediaTypeParser.php b/src/MediaTypeParser.php index 72221b3..6dc84b9 100644 --- a/src/MediaTypeParser.php +++ b/src/MediaTypeParser.php @@ -8,7 +8,7 @@ /** * @see https://mimesniff.spec.whatwg.org/#parsing-a-mime-type */ -class MediaTypeParser { +final readonly class MediaTypeParser { public function parseOrNull( string $s ): MediaType|null { try { return $this->parse( $s ); diff --git a/src/MediaTypeParserException.php b/src/MediaTypeParserException.php index b22c1a3..abb9c81 100644 --- a/src/MediaTypeParserException.php +++ b/src/MediaTypeParserException.php @@ -7,5 +7,5 @@ /** * @license MIT */ -class MediaTypeParserException extends Exception { +final class MediaTypeParserException extends Exception { } diff --git a/src/Utf8Utils.php b/src/Utf8Utils.php index 1653021..5e4d6fe 100644 --- a/src/Utf8Utils.php +++ b/src/Utf8Utils.php @@ -9,7 +9,7 @@ * @internal * @license MIT */ -class Utf8Utils { +final readonly class Utf8Utils { public static function onlyContains( string $input, callable $predicateFn ): bool { if ( $input === '' ) { return true;