diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2f50731..5a786b1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: coverage: xdebug - name: Install dependencies with Composer - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 - name: Coding standards if: matrix.analysis diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5dcf836..ee50f9d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,9 +2,9 @@ ## Pull Requests -1. Fork this repository -2. Create a new branch for each feature or improvement -3. Send a pull request from each feature branch to the **master** branch +1. Fork this repository. +2. Create a new branch for each feature or improvement. +3. Send a pull request from each feature branch to the **master** branch. It is very important to separate new features or improvements into separate feature branches, and to send a pull request for each branch. This allows me to @@ -12,11 +12,11 @@ review and pull in new features or improvements individually. ## Style Guide -All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). +All pull requests must adhere to the [PSR-12 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md). ## Unit Testing All pull requests must be accompanied by passing unit tests and complete code -coverage. The Slim Framework uses phpunit for testing. +coverage. The Slim Framework uses PHPUnit for testing. -[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/) +[Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/). diff --git a/src/Factory/RequestFactory.php b/src/Factory/RequestFactory.php index 333af40..e825ee3 100644 --- a/src/Factory/RequestFactory.php +++ b/src/Factory/RequestFactory.php @@ -23,15 +23,9 @@ class RequestFactory implements RequestFactoryInterface { - /** - * @var StreamFactoryInterface|StreamFactory - */ - protected $streamFactory; + protected StreamFactoryInterface $streamFactory; - /** - * @var UriFactoryInterface|UriFactory - */ - protected $uriFactory; + protected UriFactoryInterface $uriFactory; /** * @param StreamFactoryInterface|null $streamFactory @@ -39,16 +33,8 @@ class RequestFactory implements RequestFactoryInterface */ public function __construct(?StreamFactoryInterface $streamFactory = null, ?UriFactoryInterface $uriFactory = null) { - if (!isset($streamFactory)) { - $streamFactory = new StreamFactory(); - } - - if (!isset($uriFactory)) { - $uriFactory = new UriFactory(); - } - - $this->streamFactory = $streamFactory; - $this->uriFactory = $uriFactory; + $this->streamFactory = $streamFactory ?? new StreamFactory(); + $this->uriFactory = $uriFactory ?? new UriFactory(); } /** diff --git a/src/Factory/ServerRequestFactory.php b/src/Factory/ServerRequestFactory.php index b6e0471..5bc2447 100644 --- a/src/Factory/ServerRequestFactory.php +++ b/src/Factory/ServerRequestFactory.php @@ -30,15 +30,9 @@ class ServerRequestFactory implements ServerRequestFactoryInterface { - /** - * @var StreamFactoryInterface|StreamFactory - */ - protected $streamFactory; + protected StreamFactoryInterface $streamFactory; - /** - * @var UriFactoryInterface|UriFactory - */ - protected $uriFactory; + protected UriFactoryInterface $uriFactory; /** * @param StreamFactoryInterface|null $streamFactory @@ -46,16 +40,8 @@ class ServerRequestFactory implements ServerRequestFactoryInterface */ public function __construct(?StreamFactoryInterface $streamFactory = null, ?UriFactoryInterface $uriFactory = null) { - if (!isset($streamFactory)) { - $streamFactory = new StreamFactory(); - } - - if (!isset($uriFactory)) { - $uriFactory = new UriFactory(); - } - - $this->streamFactory = $streamFactory; - $this->uriFactory = $uriFactory; + $this->streamFactory = $streamFactory ?? new StreamFactory(); + $this->uriFactory = $uriFactory ?? new UriFactory(); } /** diff --git a/src/Header.php b/src/Header.php index 70b3f04..ecdad32 100644 --- a/src/Header.php +++ b/src/Header.php @@ -18,20 +18,11 @@ class Header { - /** - * @var string - */ - private $originalName; + private string $originalName; - /** - * @var string - */ - private $normalizedName; + private string $normalizedName; - /** - * @var array - */ - private $values; + private array $values; /** * Header constructor. diff --git a/src/Headers.php b/src/Headers.php index 355c151..c024886 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -28,19 +28,16 @@ class Headers implements HeadersInterface { - /** - * @var array - */ - protected $globals; + protected array $globals; /** * @var Header[] */ - protected $headers; + protected array $headers; /** - * @param array $headers - * @param array $globals + * @param array $headers + * @param array|null $globals */ final public function __construct(array $headers = [], ?array $globals = null) { diff --git a/src/Request.php b/src/Request.php index 3dd3cd8..15a1cab 100644 --- a/src/Request.php +++ b/src/Request.php @@ -51,20 +51,11 @@ class Request extends Message implements ServerRequestInterface */ protected $queryParams; - /** - * @var array - */ - protected $cookies; + protected array $cookies; - /** - * @var array - */ - protected $serverParams; + protected array $serverParams; - /** - * @var array - */ - protected $attributes; + protected array $attributes; /** * @var null|array|object @@ -74,7 +65,7 @@ class Request extends Message implements ServerRequestInterface /** * @var UploadedFileInterface[] */ - protected $uploadedFiles; + protected array $uploadedFiles; /** * @param string $method The request method diff --git a/src/Stream.php b/src/Stream.php index cf071eb..1ce64d2 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -48,10 +48,7 @@ class Stream implements StreamInterface */ protected $stream; - /** - * @var array|null - */ - protected $meta; + protected ?array $meta; /** * @var bool|null @@ -80,18 +77,15 @@ class Stream implements StreamInterface protected bool $finished = false; - /** - * @var StreamInterface | null - */ - protected $cache; + protected ?StreamInterface $cache; /** - * @param resource $stream A PHP resource handle. - * @param StreamInterface $cache A stream to cache $stream (useful for non-seekable streams) + * @param resource $stream A PHP resource handle. + * @param ?StreamInterface $cache A stream to cache $stream (useful for non-seekable streams) * * @throws InvalidArgumentException If argument is not a resource. */ - public function __construct($stream, StreamInterface $cache = null) + public function __construct($stream, ?StreamInterface $cache = null) { $this->attach($stream); diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 773a07c..3326d79 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -34,29 +34,20 @@ class UploadedFile implements UploadedFileInterface { /** * The client-provided full path to the file - * - * @var string */ - protected $file; + protected string $file; /** * The client-provided file name. - * - * @var string|null */ - protected $name; + protected ?string $name; /** * The client-provided media type of the file. - * - * @var string|null */ - protected $type; + protected ?string $type; - /** - * @var int|null - */ - protected $size; + protected ?int $size; /** * A valid PHP UPLOAD_ERR_xxx code for the file upload. diff --git a/src/Uri.php b/src/Uri.php index 903f80d..9d9131c 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -47,10 +47,7 @@ class Uri implements UriInterface protected string $host = ''; - /** - * @var null|int - */ - protected $port; + protected ?int $port; protected string $path = ''; @@ -65,14 +62,14 @@ class Uri implements UriInterface protected string $fragment = ''; /** - * @param string $scheme Uri scheme. - * @param string $host Uri host. - * @param int $port Uri port number. - * @param string $path Uri path. - * @param string $query Uri query string. - * @param string $fragment Uri fragment. - * @param string $user Uri user. - * @param string $password Uri password. + * @param string $scheme Uri scheme. + * @param string $host Uri host. + * @param int|null $port Uri port number. + * @param string $path Uri path. + * @param string $query Uri query string. + * @param string $fragment Uri fragment. + * @param string $user Uri user. + * @param string $password Uri password. */ public function __construct( string $scheme, @@ -290,9 +287,9 @@ protected function hasStandardPort(): bool /** * Filter Uri port. * - * @param null|int $port The Uri port number. + * @param int|null $port The Uri port number. * - * @return null|int + * @return int|null * * @throws InvalidArgumentException If the port is invalid. */ diff --git a/tests/Assets/HeaderStack.php b/tests/Assets/HeaderStack.php index 56dce01..b07daea 100644 --- a/tests/Assets/HeaderStack.php +++ b/tests/Assets/HeaderStack.php @@ -56,7 +56,7 @@ public static function push(array $header) * * @return string[][] */ - public static function stack() + public static function stack(): array { return self::$data; } @@ -68,7 +68,7 @@ public static function stack() * * @return bool */ - public static function has($header) + public static function has($header): bool { foreach (self::$data as $item) { if ($item['header'] === $header) { @@ -84,7 +84,7 @@ public static function has($header) * * @param string $header */ - public static function remove($header) + public static function remove($header): void { foreach (self::$data as $key => $item) { if (false !== strpos($item['header'], "$header:")) { diff --git a/tests/BodyTest.php b/tests/BodyTest.php index 1062990..de1d8de 100644 --- a/tests/BodyTest.php +++ b/tests/BodyTest.php @@ -52,7 +52,7 @@ protected function tearDown(): void * * @return resource */ - public function resourceFactory($mode = 'r+') + public function resourceFactory(string $mode = 'r+') { $stream = fopen('php://temp', $mode); fwrite($stream, $this->text); diff --git a/tests/Factory/RequestFactoryTest.php b/tests/Factory/RequestFactoryTest.php index 9bddc2b..02f16e5 100644 --- a/tests/Factory/RequestFactoryTest.php +++ b/tests/Factory/RequestFactoryTest.php @@ -19,19 +19,12 @@ class RequestFactoryTest extends RequestFactoryTestCase { - /** - * @return RequestFactory - */ - protected function createRequestFactory() + protected function createRequestFactory(): RequestFactory { return new RequestFactory(); } - /** - * @param string $uri - * @return UriInterface - */ - protected function createUri($uri) + protected function createUri($uri): UriInterface { return (new UriFactory())->createUri($uri); } diff --git a/tests/Factory/ResponseFactoryTest.php b/tests/Factory/ResponseFactoryTest.php index 5e5c81c..7dc557a 100644 --- a/tests/Factory/ResponseFactoryTest.php +++ b/tests/Factory/ResponseFactoryTest.php @@ -16,20 +16,12 @@ class ResponseFactoryTest extends ResponseFactoryTestCase { - /** - * @return ResponseFactory - */ - protected function createResponseFactory() + protected function createResponseFactory(): ResponseFactory { return new ResponseFactory(); } - /** - * @param ResponseInterface $response - * @param int $code - * @param string $reasonPhrase - */ - protected function assertResponseCodeAndReasonPhrase($response, $code, $reasonPhrase) + protected function assertResponseCodeAndReasonPhrase(ResponseInterface $response, int $code, string $reasonPhrase) { $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertSame($code, $response->getStatusCode()); @@ -38,9 +30,10 @@ protected function assertResponseCodeAndReasonPhrase($response, $code, $reasonPh /** * @dataProvider dataCodes + * * @param int $code */ - public function testCreateResponseWithReasonPhrase($code) + public function testCreateResponseWithReasonPhrase(int $code) { $response = $this->factory->createResponse($code, 'Reason'); $this->assertResponse($response, $code); diff --git a/tests/Factory/ServerRequestFactoryTest.php b/tests/Factory/ServerRequestFactoryTest.php index dc2c765..d46be55 100644 --- a/tests/Factory/ServerRequestFactoryTest.php +++ b/tests/Factory/ServerRequestFactoryTest.php @@ -25,19 +25,12 @@ class ServerRequestFactoryTest extends ServerRequestFactoryTestCase { - /** - * @return ServerRequestFactory - */ - protected function createServerRequestFactory() + protected function createServerRequestFactory(): ServerRequestFactory { return new ServerRequestFactory(); } - /** - * @param string $uri - * @return UriInterface - */ - protected function createUri($uri) + protected function createUri($uri): UriInterface { return (new UriFactory())->createUri($uri); } diff --git a/tests/Factory/StreamFactoryTest.php b/tests/Factory/StreamFactoryTest.php index 9e3e66e..e10d38d 100644 --- a/tests/Factory/StreamFactoryTest.php +++ b/tests/Factory/StreamFactoryTest.php @@ -24,10 +24,7 @@ public function tearDown(): void } } - /** - * @return StreamFactory - */ - protected function createStreamFactory() + protected function createStreamFactory(): StreamFactory { return new StreamFactory(); } diff --git a/tests/Factory/UploadedFileFactoryTest.php b/tests/Factory/UploadedFileFactoryTest.php index 747f679..1f46b79 100644 --- a/tests/Factory/UploadedFileFactoryTest.php +++ b/tests/Factory/UploadedFileFactoryTest.php @@ -27,18 +27,12 @@ class UploadedFileFactoryTest extends UploadedFileFactoryTestCase { use ProphecyTrait; - /** - * @return UploadedFileFactory - */ - protected function createUploadedFileFactory() + protected function createUploadedFileFactory(): UploadedFileFactory { return new UploadedFileFactory(); } - /** - * @return StreamInterface - */ - protected function createStream($content) + protected function createStream($content): StreamInterface { $file = tempnam(sys_get_temp_dir(), 'Slim_Http_UploadedFileTest_'); $resource = fopen($file, 'r+'); diff --git a/tests/Factory/UriFactoryTest.php b/tests/Factory/UriFactoryTest.php index 2c539ec..95e54b3 100644 --- a/tests/Factory/UriFactoryTest.php +++ b/tests/Factory/UriFactoryTest.php @@ -16,10 +16,7 @@ class UriFactoryTest extends UriFactoryTestCase { - /** - * @return UriFactory - */ - protected function createUriFactory() + protected function createUriFactory(): UriFactory { return new UriFactory(); } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index f6f5ebc..2547220 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -26,7 +26,7 @@ class RequestTest extends TestCase { - public function requestFactory($envData = []) + public function requestFactory($envData = []): Request { $env = Environment::mock($envData); diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 1d5d559..0a97197 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -32,10 +32,7 @@ class StreamTest extends TestCase */ private $pipeFh; - /** - * @var Stream - */ - private $pipeStream; + private Stream $pipeStream; public function tearDown(): void { diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index a6643e6..9a8816c 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -80,10 +80,7 @@ public function tearDown(): void } } - /** - * @return UploadedFile - */ - protected function generateNewTmpFile() + protected function generateNewTmpFile(): UploadedFile { $filename = './php' . microtime(); @@ -132,10 +129,7 @@ public function testCreateFromGlobalsWithoutFile() $this->assertEquals([], $uploadedFile); } - /** - * @return UploadedFile - */ - public function testConstructor() + public function testConstructor(): UploadedFile { $attr = [ 'tmp_name' => self::$filename, @@ -163,10 +157,7 @@ public function testConstructor() return $uploadedFile; } - /** - * @return UploadedFile - */ - public function testConstructorSapi() + public function testConstructorSapi(): UploadedFile { $attr = [ 'tmp_name' => self::$filename, @@ -201,7 +192,7 @@ public function testConstructorSapi() * * @return UploadedFile */ - public function testGetStream(UploadedFile $uploadedFile) + public function testGetStream(UploadedFile $uploadedFile): UploadedFile { $stream = $uploadedFile->getStream(); $this->assertEquals(true, $uploadedFile->getStream() instanceof Stream); @@ -232,7 +223,7 @@ public function testMoveToNotWritable(UploadedFile $uploadedFile) * * @return UploadedFile */ - public function testMoveTo(UploadedFile $uploadedFile) + public function testMoveTo(UploadedFile $uploadedFile): UploadedFile { $tempName = uniqid('file-'); $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tempName; @@ -444,7 +435,7 @@ public function testCreateUploadedFileWithInvalidUri() new UploadedFile($stream); } - public function providerCreateFromGlobals() + public function providerCreateFromGlobals(): array { return [ // no nest: diff --git a/tests/UriTest.php b/tests/UriTest.php index ffbe767..a0c4d28 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -17,7 +17,7 @@ class UriTest extends TestCase { - public function uriFactory() + public function uriFactory(): Uri { $scheme = 'https'; $host = 'example.com';