diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e9cc9e..759bdbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 1.4.0 + +### Removed + +The `final` keyword was replaced by `@final` annotation. + ## 1.3.2 ### Fixed diff --git a/doc/final.md b/doc/final.md new file mode 100644 index 0000000..b5b1942 --- /dev/null +++ b/doc/final.md @@ -0,0 +1,20 @@ +# Final classes + +The `final` keyword was removed in version 1.4.0. It was replaced by `@final` annotation. +This was done due popular demand, not because it is a good technical reason to +extend the classes. + +This document will show the correct way to work with PSR-7 classes. The "correct way" +refers to best practices and good software design. I strongly believe that one should +be aware of how a problem *should* be solved, however, it is not needed to always +implement that solution. + +## Extending classes + +You should never extend the classes, you should rather use composition or implement +the interface yourself. Please refer to the [decorator pattern](https://refactoring.guru/design-patterns/decorator). + +## Mocking classes + +The PSR-7 classes are all value objects and they can be used without mocking. If +one really needs to create a special scenario, one can mock the interface instead. diff --git a/src/Factory/HttplugFactory.php b/src/Factory/HttplugFactory.php index a296541..cc64780 100644 --- a/src/Factory/HttplugFactory.php +++ b/src/Factory/HttplugFactory.php @@ -11,8 +11,10 @@ /** * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory +class HttplugFactory implements MessageFactory, StreamFactory, UriFactory { public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1') { diff --git a/src/Factory/Psr17Factory.php b/src/Factory/Psr17Factory.php index 08caf85..0da5acd 100644 --- a/src/Factory/Psr17Factory.php +++ b/src/Factory/Psr17Factory.php @@ -10,8 +10,10 @@ /** * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface +class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface { public function createRequest(string $method, $uri): RequestInterface { diff --git a/src/Request.php b/src/Request.php index 84a9f2a..d50744e 100644 --- a/src/Request.php +++ b/src/Request.php @@ -9,8 +9,10 @@ /** * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class Request implements RequestInterface +class Request implements RequestInterface { use MessageTrait; use RequestTrait; diff --git a/src/Response.php b/src/Response.php index c2020f4..9a26d2c 100644 --- a/src/Response.php +++ b/src/Response.php @@ -10,8 +10,10 @@ * @author Michael Dowling and contributors to guzzlehttp/psr7 * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class Response implements ResponseInterface +class Response implements ResponseInterface { use MessageTrait; diff --git a/src/ServerRequest.php b/src/ServerRequest.php index aff8721..1ad8792 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -10,8 +10,10 @@ * @author Michael Dowling and contributors to guzzlehttp/psr7 * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class ServerRequest implements ServerRequestInterface +class ServerRequest implements ServerRequestInterface { use MessageTrait; use RequestTrait; diff --git a/src/Stream.php b/src/Stream.php index 151b4f6..bcc59ba 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -12,8 +12,10 @@ * @author Michael Dowling and contributors to guzzlehttp/psr7 * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class Stream implements StreamInterface +class Stream implements StreamInterface { /** @var resource|null A resource reference */ private $stream; diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 757e70e..415bf87 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -10,8 +10,10 @@ * @author Michael Dowling and contributors to guzzlehttp/psr7 * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class UploadedFile implements UploadedFileInterface +class UploadedFile implements UploadedFileInterface { /** @var array */ private const ERRORS = [ diff --git a/src/Uri.php b/src/Uri.php index 95027e1..eee304f 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -14,8 +14,10 @@ * @author Matthew Weier O'Phinney * @author Tobias Nyholm * @author Martijn van der Ven + * + * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md */ -final class Uri implements UriInterface +class Uri implements UriInterface { private const SCHEMES = ['http' => 80, 'https' => 443];