From 3a81f970f71c2c9be274b27b9fc315b17e59c19c Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Thu, 2 Nov 2023 21:31:50 -0400 Subject: [PATCH] http-factory updates and cs fixes (#72) --- .php-cs-fixer.dist.php | 7 ++- Makefile | 3 ++ docs/components/http-factory/index.md | 19 +++++++ phpunit.xml.dist | 6 ++- .../Bard/src/Console/Command/CopyCommand.php | 1 - .../Filesystem/Adapter/ChainAdapter.php | 1 - .../Adapter/DirectoryAwareInterface.php | 1 - .../Filesystem/Adapter/InMemoryAdapter.php | 1 - .../Filesystem/Adapter/NativeAdapter.php | 1 - .../Component/Filesystem/Filesystem.php | 1 - .../Tests/Adapter/InMemoryAdapterTest.php | 1 - .../Filesystem/Tests/ContextTest.php | 1 - .../Filesystem/Tests/FilesystemTest.php | 2 - .../Component/HttpFactory/HttpFactory.php | 22 ++++++++ .../Component/HttpFactory/RequestFactory.php | 14 +----- .../HttpFactory/RequestFactoryTrait.php | 24 +++++++++ .../Component/HttpFactory/ResponseFactory.php | 12 +---- .../HttpFactory/ResponseFactoryTrait.php | 24 +++++++++ .../HttpFactory/ServerRequestFactory.php | 14 +----- .../HttpFactory/ServerRequestFactoryTrait.php | 24 +++++++++ .../Component/HttpFactory/StreamFactory.php | 38 +------------- .../HttpFactory/StreamFactoryTrait.php | 50 +++++++++++++++++++ ...ryTest.php => RequestFactoryTraitTest.php} | 21 +++----- .../HttpFactory/Tests/ResponseFactoryTest.php | 3 +- .../Tests/ServerRequestFactoryTest.php | 3 ++ .../HttpFactory/Tests/StreamFactoryTest.php | 3 ++ .../Tests/UploadedFileFactoryTest.php | 1 + .../HttpFactory/Tests/UriFactoryTest.php | 1 + .../HttpFactory/UploadedFileFactory.php | 13 +---- .../HttpFactory/UploadedFileFactoryTrait.php | 25 ++++++++++ .../Component/HttpFactory/UriFactory.php | 12 +---- .../Component/HttpFactory/UriFactoryTrait.php | 24 +++++++++ .../Component/HttpMessage/Response.php | 1 - 33 files changed, 252 insertions(+), 122 deletions(-) create mode 100644 src/SonsOfPHP/Component/HttpFactory/HttpFactory.php create mode 100644 src/SonsOfPHP/Component/HttpFactory/RequestFactoryTrait.php create mode 100644 src/SonsOfPHP/Component/HttpFactory/ResponseFactoryTrait.php create mode 100644 src/SonsOfPHP/Component/HttpFactory/ServerRequestFactoryTrait.php create mode 100644 src/SonsOfPHP/Component/HttpFactory/StreamFactoryTrait.php rename src/SonsOfPHP/Component/HttpFactory/Tests/{RequestFactoryTest.php => RequestFactoryTraitTest.php} (53%) create mode 100644 src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php create mode 100644 src/SonsOfPHP/Component/HttpFactory/UriFactoryTrait.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index bbd7bfbb..5adc73c1 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,11 +7,14 @@ ->exclude('vendor') ; -$config = new PhpCsFixer\Config(); -return $config->setRules([ +return (new PhpCsFixer\Config())->setRules([ // Rule sets '@PER-CS' => true, '@PHP80Migration:risky' => true, '@PHP81Migration' => true, '@PHPUnit100Migration:risky' => true, + + // Rules + 'no_unused_imports' => true, + 'php_unit_test_class_requires_covers' => true, ])->setFinder($finder); diff --git a/Makefile b/Makefile index d799a99b..24d83f24 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,9 @@ lint-php: # lint php files coverage: ## Build Code Coverage Report XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --coverage-html $(COVERAGE_DIR) +coverage-http-factory: + XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --testsuite http-factory --coverage-html $(COVERAGE_DIR) + psalm: ## Run psalm XDEBUG_MODE=off $(PHP) $(PSALM) diff --git a/docs/components/http-factory/index.md b/docs/components/http-factory/index.md index 3a744efd..9722df45 100644 --- a/docs/components/http-factory/index.md +++ b/docs/components/http-factory/index.md @@ -11,3 +11,22 @@ Simple PSR-17 Http Factory Component ```shell composer require sonsofphp/http-factory ``` + +## Usage + +```php +use SonsOfPHP\Component\HttpFactory\HttpFactory; + +$factory = new HttpFactory(); + +$request = $factory->createRequest($method, $uri); +$response = $factory->createResponse(); +$serverRequest = $factory->createServerRequest($method, $uri); +$stream = $factory->createStream(); +$stream = $factory->createStreamFromFile('/path/to/file.ext'); +$stream = $factory->createStreamFromResource($resource); +$uploadedFile = $factory->createUploadedFile($stream); +$uri = $factory->createUri('https://docs.sonsofphp.com'); +``` + +For more details, please see the source code or review the PSR-17 documentation. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ed568685..4ba99b9b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" requireCoverageMetadata="true" - beStrictAboutCoverageMetadata="false"> + beStrictAboutCoverageMetadata="true"> @@ -17,6 +17,10 @@ src/SonsOfPHP/Bundle/*/Tests src/SonsOfPHP/Component/*/Tests + + + src/SonsOfPHP/Component/HttpFactory/Tests + diff --git a/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php b/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php index 5e9c852b..26f9d90d 100644 --- a/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php +++ b/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php @@ -6,7 +6,6 @@ use SonsOfPHP\Bard\JsonFile; use Symfony\Component\Console\Input\InputArgument; -use SonsOfPHP\Component\Json\Json; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/ChainAdapter.php b/src/SonsOfPHP/Component/Filesystem/Adapter/ChainAdapter.php index 433de0af..fca2d1c8 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/ChainAdapter.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/ChainAdapter.php @@ -6,7 +6,6 @@ use SonsOfPHP\Component\Filesystem\ContextInterface; use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * Chain adapter allows you to use multiple adapters together. diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/DirectoryAwareInterface.php b/src/SonsOfPHP/Component/Filesystem/Adapter/DirectoryAwareInterface.php index 67c718a3..61a400a1 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/DirectoryAwareInterface.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/DirectoryAwareInterface.php @@ -6,7 +6,6 @@ use SonsOfPHP\Component\Filesystem\ContextInterface; use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; -use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; /** * If an adapter is able to manage directories, it should implement this diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/InMemoryAdapter.php b/src/SonsOfPHP/Component/Filesystem/Adapter/InMemoryAdapter.php index 684f3f1a..68518d62 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/InMemoryAdapter.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/InMemoryAdapter.php @@ -5,7 +5,6 @@ namespace SonsOfPHP\Component\Filesystem\Adapter; use SonsOfPHP\Component\Filesystem\ContextInterface; -use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; use SonsOfPHP\Component\Filesystem\Exception\UnableToReadFileException; /** diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/NativeAdapter.php b/src/SonsOfPHP/Component/Filesystem/Adapter/NativeAdapter.php index eeccacf0..9e20e5bc 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/NativeAdapter.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/NativeAdapter.php @@ -5,7 +5,6 @@ namespace SonsOfPHP\Component\Filesystem\Adapter; use SonsOfPHP\Component\Filesystem\ContextInterface; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * The native adapter will use the underlying filesystem to store files. diff --git a/src/SonsOfPHP/Component/Filesystem/Filesystem.php b/src/SonsOfPHP/Component/Filesystem/Filesystem.php index 88d9fd67..bd589823 100644 --- a/src/SonsOfPHP/Component/Filesystem/Filesystem.php +++ b/src/SonsOfPHP/Component/Filesystem/Filesystem.php @@ -7,7 +7,6 @@ use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Adapter\CopyAwareInterface; -use SonsOfPHP\Component\Filesystem\Adapter\DirectoryAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; /** diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php index 6437e868..7bf863c7 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/InMemoryAdapterTest.php @@ -5,7 +5,6 @@ namespace SonsOfPHP\Component\Filesystem\Tests; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\MockObject; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; use SonsOfPHP\Component\Filesystem\Exception\UnableToReadFileException; diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php index cc5e338e..11023a40 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php @@ -6,7 +6,6 @@ use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\MockObject; use SonsOfPHP\Component\Filesystem\ContextInterface; use SonsOfPHP\Component\Filesystem\Context; diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php index 8740ac9d..90f0f5b5 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php @@ -5,9 +5,7 @@ namespace SonsOfPHP\Component\Filesystem\Tests; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\MockObject; use SonsOfPHP\Component\Filesystem\FilesystemInterface; -use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Filesystem; use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; diff --git a/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php b/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php new file mode 100644 index 00000000..2a75de3a --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/HttpFactory.php @@ -0,0 +1,22 @@ + + */ +final class RequestFactory implements RequestFactoryInterface +{ + use RequestFactoryTrait; + use ResponseFactoryTrait; + use ServerResponseFactoryTrait; + use StreamFactoryTrait; + use UploadedFileFactoryTrait; + use UriFactoryTrait; +} diff --git a/src/SonsOfPHP/Component/HttpFactory/RequestFactory.php b/src/SonsOfPHP/Component/HttpFactory/RequestFactory.php index 681811de..7b179f6f 100644 --- a/src/SonsOfPHP/Component/HttpFactory/RequestFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/RequestFactory.php @@ -5,23 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\UriInterface; -use SonsOfPHP\Component\HttpMessage\Request; /** * {@inheritdoc} * * @author Joshua Estes */ -class RequestFactory implements RequestFactoryInterface +final class RequestFactory implements RequestFactoryInterface { - /** - * {@inheritdoc} - */ - public function createRequest(string $method, $uri): RequestInterface - { - return new Request($method, $uri); - } + use RequestFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/RequestFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/RequestFactoryTrait.php new file mode 100644 index 00000000..1c06a825 --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/RequestFactoryTrait.php @@ -0,0 +1,24 @@ + + */ +trait RequestFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createRequest(string $method, $uri): RequestInterface + { + return new Request($method, $uri); + } +} diff --git a/src/SonsOfPHP/Component/HttpFactory/ResponseFactory.php b/src/SonsOfPHP/Component/HttpFactory/ResponseFactory.php index 5360cf5b..45fe7b5c 100644 --- a/src/SonsOfPHP/Component/HttpFactory/ResponseFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/ResponseFactory.php @@ -5,21 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\ResponseFactoryInterface; -use Psr\Http\Message\ResponseInterface; -use SonsOfPHP\Component\HttpMessage\Response; /** * {@inheritdoc} * * @author Joshua Estes */ -class ResponseFactory implements ResponseFactoryInterface +final class ResponseFactory implements ResponseFactoryInterface { - /** - * {@inheritdoc} - */ - public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface - { - return (new Response())->withStatus($code, $reasonPhrase); - } + use ResponseFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/ResponseFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/ResponseFactoryTrait.php new file mode 100644 index 00000000..f5991d52 --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/ResponseFactoryTrait.php @@ -0,0 +1,24 @@ + + */ +trait ResponseFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface + { + return (new Response())->withStatus($code, $reasonPhrase); + } +} diff --git a/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactory.php b/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactory.php index aac26f08..43f0999d 100644 --- a/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactory.php @@ -5,23 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\ServerRequestFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\UriInterface; -use SonsOfPHP\Component\HttpMessage\ServerRequest; /** * {@inheritdoc} * * @author Joshua Estes */ -class ServerRequestFactory implements ServerRequestFactoryInterface +final class ServerRequestFactory implements ServerRequestFactoryInterface { - /** - * {@inheritdoc} - */ - public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface - { - return new ServerRequest($method, $uri, $serverParams); - } + use ServerRequestFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactoryTrait.php new file mode 100644 index 00000000..604b5cf4 --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/ServerRequestFactoryTrait.php @@ -0,0 +1,24 @@ + + */ +trait ServerRequestFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + return new ServerRequest($method, $uri, $serverParams); + } +} diff --git a/src/SonsOfPHP/Component/HttpFactory/StreamFactory.php b/src/SonsOfPHP/Component/HttpFactory/StreamFactory.php index 3f41579f..a3ed3a9c 100644 --- a/src/SonsOfPHP/Component/HttpFactory/StreamFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/StreamFactory.php @@ -5,47 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\StreamInterface; -use SonsOfPHP\Component\HttpMessage\Stream; /** * {@inheritdoc} * * @author Joshua Estes */ -class StreamFactory implements StreamFactoryInterface +final class StreamFactory implements StreamFactoryInterface { - /** - * {@inheritdoc} - */ - public function createStream(string $content = ''): StreamInterface - { - $resource = fopen('php://temp', 'r+'); - fwrite($resource, $content); - fseek($resource, 0); - - return new Stream($resource); - } - - /** - * {@inheritdoc} - */ - public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface - { - // #todo Error Handling, filename might be invalid or mode may be invalid - - return new Stream(fopen($filename, $mode)); - } - - /** - * {@inheritdoc} - */ - public function createStreamFromResource($resource): StreamInterface - { - if (!is_resource($resource)) { - throw new \InvalidArgumentException('resource is invalid'); - } - - return new Stream($resource); - } + use StreamFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/StreamFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/StreamFactoryTrait.php new file mode 100644 index 00000000..64b04aa3 --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/StreamFactoryTrait.php @@ -0,0 +1,50 @@ + + */ +trait StreamFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createStream(string $content = ''): StreamInterface + { + $resource = fopen('php://temp', 'r+'); + fwrite($resource, $content); + fseek($resource, 0); + + return new Stream($resource); + } + + /** + * {@inheritdoc} + */ + public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface + { + // #todo Error Handling, filename might be invalid or mode may be invalid + + return new Stream(fopen($filename, $mode)); + } + + /** + * {@inheritdoc} + */ + public function createStreamFromResource($resource): StreamInterface + { + if (!is_resource($resource)) { + throw new \InvalidArgumentException('resource is invalid'); + } + + return new Stream($resource); + } +} diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php similarity index 53% rename from src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTest.php rename to src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php index 12a049c3..f78e92a0 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php @@ -5,31 +5,22 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\RequestFactory; +use SonsOfPHP\Component\HttpFactory\RequestFactoryTrait; use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\RequestFactoryInterface; /** - * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\RequestFactory - * - * @internal + * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\RequestFactoryTrait */ -final class RequestFactoryTest extends TestCase +final class RequestFactoryTraitTest extends TestCase { - /** - * @coversNothing - */ - public function testItImplementsCorrectInterface(): void - { - $this->assertInstanceOf(RequestFactoryInterface::class, new RequestFactory()); - } - /** * @covers ::createRequest + * @uses SonsOfPHP\Component\HttpMessage\Request + * @uses SonsOfPHP\Component\HttpMessage\Uri */ public function testCreateRequestWorksAsExpected(): void { - $factory = new RequestFactory(); + $factory = $this->getMockForTrait(RequestFactoryTrait::class); $this->assertInstanceOf(RequestInterface::class, $factory->createRequest('GET', 'https://docs.sonsofphp.com')); } diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php index 86cfd5c0..cd669429 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php @@ -11,8 +11,6 @@ /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\ResponseFactory - * - * @internal */ final class ResponseFactoryTest extends TestCase { @@ -26,6 +24,7 @@ public function testItImplementsCorrectInterface(): void /** * @covers ::createResponse + * @uses \SonsOfPHP\Component\HttpMessage\Response */ public function testCreateResponseWorksAsExpected(): void { diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php index c811eba4..7a0208e0 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php @@ -26,6 +26,9 @@ public function testItImplementsCorrectInterface(): void /** * @covers ::createServerRequest + * @uses \SonsOfPHP\Component\HttpMessage\Request + * @uses \SonsOfPHP\Component\HttpMessage\ServerRequest + * @uses \SonsOfPHP\Component\HttpMessage\Uri */ public function testCreateServerRequestWorksAsExpected(): void { diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php index 49faab72..e41b82ed 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php @@ -26,6 +26,7 @@ public function testItImplementsCorrectInterface(): void /** * @covers ::createStream + * @uses \SonsOfPHP\Component\HttpMessage\Stream */ public function testCreateStreamWorksAsExpected(): void { @@ -36,6 +37,7 @@ public function testCreateStreamWorksAsExpected(): void /** * @covers ::createStreamFromResource + * @uses \SonsOfPHP\Component\HttpMessage\Stream */ public function testCreateStreamFromResourceWorksAsExpected(): void { @@ -46,6 +48,7 @@ public function testCreateStreamFromResourceWorksAsExpected(): void /** * @covers ::createStreamFromResource + * @uses \SonsOfPHP\Component\HttpMessage\Stream */ public function testCreateStreamFromResourceWillThrowExceptionWhenNotResource(): void { diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php index 9f8ee3c5..a92e83d7 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php @@ -35,6 +35,7 @@ public function testItImplementsCorrectInterface(): void /** * @covers ::createUploadedFile + * @uses \SonsOfPHP\Component\HttpMessage\UploadedFile */ public function testCreateUploadedFileWorksAsExpected(): void { diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php index 8492b1f6..e8a242a7 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php @@ -26,6 +26,7 @@ public function testItImplementsCorrectInterface(): void /** * @covers ::createUri + * @uses \SonsOfPHP\Component\HttpMessage\Uri */ public function testCreateUriWorksAsExpected(): void { diff --git a/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactory.php b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactory.php index 90a99732..d95f1a6e 100644 --- a/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactory.php @@ -5,22 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\UploadedFileFactoryInterface; -use Psr\Http\Message\UploadedFileInterface; -use Psr\Http\Message\StreamInterface; -use SonsOfPHP\Component\HttpMessage\UploadedFile; /** * {@inheritdoc} * * @author Joshua Estes */ -class UploadedFileFactory implements UploadedFileFactoryInterface +final class UploadedFileFactory implements UploadedFileFactoryInterface { - /** - * {@inheritdoc} - */ - public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface - { - return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); - } + use UploadedFileFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php new file mode 100644 index 00000000..23dc0f83 --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php @@ -0,0 +1,25 @@ + + */ +trait UploadedFileFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface + { + return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); + } +} diff --git a/src/SonsOfPHP/Component/HttpFactory/UriFactory.php b/src/SonsOfPHP/Component/HttpFactory/UriFactory.php index a0858227..c21a8851 100644 --- a/src/SonsOfPHP/Component/HttpFactory/UriFactory.php +++ b/src/SonsOfPHP/Component/HttpFactory/UriFactory.php @@ -5,21 +5,13 @@ namespace SonsOfPHP\Component\HttpFactory; use Psr\Http\Message\UriFactoryInterface; -use Psr\Http\Message\UriInterface; -use SonsOfPHP\Component\HttpMessage\Uri; /** * {@inheritdoc} * * @author Joshua Estes */ -class UriFactory implements UriFactoryInterface +final class UriFactory implements UriFactoryInterface { - /** - * {@inheritdoc} - */ - public function createUri(string $uri = ''): UriInterface - { - return new Uri($uri); - } + use UriFactoryTrait; } diff --git a/src/SonsOfPHP/Component/HttpFactory/UriFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/UriFactoryTrait.php new file mode 100644 index 00000000..30df4e6d --- /dev/null +++ b/src/SonsOfPHP/Component/HttpFactory/UriFactoryTrait.php @@ -0,0 +1,24 @@ + + */ +trait UriFactoryTrait +{ + /** + * {@inheritdoc} + */ + public function createUri(string $uri = ''): UriInterface + { + return new Uri($uri); + } +} diff --git a/src/SonsOfPHP/Component/HttpMessage/Response.php b/src/SonsOfPHP/Component/HttpMessage/Response.php index 885d0aa7..407f47ea 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Response.php +++ b/src/SonsOfPHP/Component/HttpMessage/Response.php @@ -5,7 +5,6 @@ namespace SonsOfPHP\Component\HttpMessage; use Psr\Http\Message\ResponseInterface; -use SonsOfPHP\Component\HttpMessage\HttpMessageException; /** * {@inheritdoc}