Skip to content

Commit 23ae1f0

Browse files
NyholmZegnat
andauthored
Remove final keyword (#169)
* Remove final keyword * Added changelog * Added docs to final * Update doc/final.md Co-authored-by: Martijn van der Ven <[email protected]> * Added link to decorator pattern Co-authored-by: Martijn van der Ven <[email protected]>
1 parent 87bc153 commit 23ae1f0

10 files changed

+50
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 1.4.0
6+
7+
### Removed
8+
9+
The `final` keyword was replaced by `@final` annotation.
10+
511
## 1.3.2
612

713
### Fixed

doc/final.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Final classes
2+
3+
The `final` keyword was removed in version 1.4.0. It was replaced by `@final` annotation.
4+
This was done due popular demand, not because it is a good technical reason to
5+
extend the classes.
6+
7+
This document will show the correct way to work with PSR-7 classes. The "correct way"
8+
refers to best practices and good software design. I strongly believe that one should
9+
be aware of how a problem *should* be solved, however, it is not needed to always
10+
implement that solution.
11+
12+
## Extending classes
13+
14+
You should never extend the classes, you should rather use composition or implement
15+
the interface yourself. Please refer to the [decorator pattern](https://refactoring.guru/design-patterns/decorator).
16+
17+
## Mocking classes
18+
19+
The PSR-7 classes are all value objects and they can be used without mocking. If
20+
one really needs to create a special scenario, one can mock the interface instead.

src/Factory/HttplugFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
/**
1212
* @author Tobias Nyholm <[email protected]>
1313
* @author Martijn van der Ven <[email protected]>
14+
*
15+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1416
*/
15-
final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
17+
class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
1618
{
1719
public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
1820
{

src/Factory/Psr17Factory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
/**
1111
* @author Tobias Nyholm <[email protected]>
1212
* @author Martijn van der Ven <[email protected]>
13+
*
14+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1315
*/
14-
final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
16+
class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
1517
{
1618
public function createRequest(string $method, $uri): RequestInterface
1719
{

src/Request.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
/**
1010
* @author Tobias Nyholm <[email protected]>
1111
* @author Martijn van der Ven <[email protected]>
12+
*
13+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1214
*/
13-
final class Request implements RequestInterface
15+
class Request implements RequestInterface
1416
{
1517
use MessageTrait;
1618
use RequestTrait;

src/Response.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
* @author Michael Dowling and contributors to guzzlehttp/psr7
1111
* @author Tobias Nyholm <[email protected]>
1212
* @author Martijn van der Ven <[email protected]>
13+
*
14+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1315
*/
14-
final class Response implements ResponseInterface
16+
class Response implements ResponseInterface
1517
{
1618
use MessageTrait;
1719

src/ServerRequest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
* @author Michael Dowling and contributors to guzzlehttp/psr7
1111
* @author Tobias Nyholm <[email protected]>
1212
* @author Martijn van der Ven <[email protected]>
13+
*
14+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1315
*/
14-
final class ServerRequest implements ServerRequestInterface
16+
class ServerRequest implements ServerRequestInterface
1517
{
1618
use MessageTrait;
1719
use RequestTrait;

src/Stream.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
* @author Michael Dowling and contributors to guzzlehttp/psr7
1313
* @author Tobias Nyholm <[email protected]>
1414
* @author Martijn van der Ven <[email protected]>
15+
*
16+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1517
*/
16-
final class Stream implements StreamInterface
18+
class Stream implements StreamInterface
1719
{
1820
/** @var resource|null A resource reference */
1921
private $stream;

src/UploadedFile.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
* @author Michael Dowling and contributors to guzzlehttp/psr7
1111
* @author Tobias Nyholm <[email protected]>
1212
* @author Martijn van der Ven <[email protected]>
13+
*
14+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1315
*/
14-
final class UploadedFile implements UploadedFileInterface
16+
class UploadedFile implements UploadedFileInterface
1517
{
1618
/** @var array */
1719
private const ERRORS = [

src/Uri.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
* @author Matthew Weier O'Phinney
1515
* @author Tobias Nyholm <[email protected]>
1616
* @author Martijn van der Ven <[email protected]>
17+
*
18+
* @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
1719
*/
18-
final class Uri implements UriInterface
20+
class Uri implements UriInterface
1921
{
2022
private const SCHEMES = ['http' => 80, 'https' => 443];
2123

0 commit comments

Comments
 (0)