Skip to content

Commit

Permalink
Remove final keyword (#169)
Browse files Browse the repository at this point in the history
* Remove final keyword

* Added changelog

* Added docs to final

* Update doc/final.md

Co-authored-by: Martijn van der Ven <martijn@vanderven.se>

* Added link to decorator pattern

Co-authored-by: Martijn van der Ven <martijn@vanderven.se>
  • Loading branch information
Nyholm and Zegnat committed Feb 18, 2021
1 parent 87bc153 commit 23ae1f0
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions 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.
4 changes: 3 additions & 1 deletion src/Factory/HttplugFactory.php
Expand Up @@ -11,8 +11,10 @@
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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')
{
Expand Down
4 changes: 3 additions & 1 deletion src/Factory/Psr17Factory.php
Expand Up @@ -10,8 +10,10 @@
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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
{
Expand Down
4 changes: 3 additions & 1 deletion src/Request.php
Expand Up @@ -9,8 +9,10 @@
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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;
Expand Down
4 changes: 3 additions & 1 deletion src/Response.php
Expand Up @@ -10,8 +10,10 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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;

Expand Down
4 changes: 3 additions & 1 deletion src/ServerRequest.php
Expand Up @@ -10,8 +10,10 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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;
Expand Down
4 changes: 3 additions & 1 deletion src/Stream.php
Expand Up @@ -12,8 +12,10 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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;
Expand Down
4 changes: 3 additions & 1 deletion src/UploadedFile.php
Expand Up @@ -10,8 +10,10 @@
* @author Michael Dowling and contributors to guzzlehttp/psr7
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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 = [
Expand Down
4 changes: 3 additions & 1 deletion src/Uri.php
Expand Up @@ -14,8 +14,10 @@
* @author Matthew Weier O'Phinney
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
* @author Martijn van der Ven <martijn@vanderven.se>
*
* @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];

Expand Down

0 comments on commit 23ae1f0

Please sign in to comment.