Skip to content

Commit 3a435ad

Browse files
committed
Fix Code Style
1 parent e9aefd3 commit 3a435ad

13 files changed

+249
-116
lines changed

.php-cs-fixer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
declare(strict_types=1);
44

5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
516
use CoiSA\PhpCsFixer\PhpCsFixer;
617

718
$paths = [

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
}
4545
},
4646
"scripts": {
47-
"cs-check": "php-cs-fixer fix --dry-run --diff",
48-
"cs-fix": "php-cs-fixer fix",
47+
"cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff",
48+
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
4949
"mutation-testing": "infection --threads=4",
5050
"pre-commit": [
5151
"@cs-check",

src/JsonResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
316
namespace FastForward\Http\Message;
417

518
use Nyholm\Psr7\Response;

src/JsonResponseInterface.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
316
namespace FastForward\Http\Message;
417

518
use Psr\Http\Message\ResponseInterface;
619

7-
interface JsonResponseInterface extends ResponseInterface, PayloadAwareInterface
8-
{
9-
}
20+
interface JsonResponseInterface extends ResponseInterface, PayloadAwareInterface {}

src/JsonStream.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
316
namespace FastForward\Http\Message;
417

518
use Nyholm\Psr7\Stream;
619

720
/**
8-
* Class JsonStream
21+
* Class JsonStream.
922
*
1023
* Extends Nyholm's PSR-7 Stream implementation to provide JSON-specific stream functionality.
1124
* This class SHALL encapsulate a JSON-encoded payload within a PHP stream, while retaining the original
@@ -26,8 +39,8 @@ final class JsonStream extends Stream implements JsonStreamInterface
2639
* The payload SHALL be JSON-encoded and written to an in-memory PHP stream. The original payload is retained
2740
* in decoded form for later retrieval via {@see getPayload()}.
2841
*
29-
* @param mixed $payload The data to encode as JSON. MUST be JSON-encodable. Resources are explicitly prohibited.
30-
* @param int $encodingOptions Optional JSON encoding flags as defined by {@see json_encode()}. Defaults to 0.
42+
* @param mixed $payload The data to encode as JSON. MUST be JSON-encodable. Resources are explicitly prohibited.
43+
* @param int $encodingOptions Optional JSON encoding flags as defined by {@see json_encode()}. Defaults to 0.
3144
*/
3245
public function __construct(
3346
private mixed $payload = [],
@@ -39,22 +52,33 @@ public function __construct(
3952
$this->rewind();
4053
}
4154

55+
public function getPayload(): mixed
56+
{
57+
return $this->payload;
58+
}
59+
60+
public function withPayload(mixed $payload): self
61+
{
62+
return new self($payload);
63+
}
64+
4265
/**
4366
* Encodes the given data as JSON, enforcing proper error handling.
4467
*
4568
* If the provided data is a resource, this method SHALL throw an {@see \InvalidArgumentException} as resources
4669
* cannot be represented in JSON format.
4770
*
48-
* @param mixed $data The data to encode as JSON.
49-
* @param int $encodingOptions JSON encoding options, combined with JSON_THROW_ON_ERROR.
50-
* @return string The JSON-encoded string representation of the data.
71+
* @param mixed $data the data to encode as JSON
72+
* @param int $encodingOptions JSON encoding options, combined with JSON_THROW_ON_ERROR
5173
*
52-
* @throws \InvalidArgumentException If the data contains a resource.
53-
* @throws \JsonException If JSON encoding fails.
74+
* @return string the JSON-encoded string representation of the data
75+
*
76+
* @throws \InvalidArgumentException if the data contains a resource
77+
* @throws \JsonException if JSON encoding fails
5478
*/
5579
private function jsonEncode(mixed $data, int $encodingOptions): string
5680
{
57-
if (is_resource($data)) {
81+
if (\is_resource($data)) {
5882
throw new \InvalidArgumentException('Cannot JSON encode resources');
5983
}
6084

@@ -63,14 +87,4 @@ private function jsonEncode(mixed $data, int $encodingOptions): string
6387

6488
return json_encode($data, $encodingOptions | JSON_THROW_ON_ERROR);
6589
}
66-
67-
public function getPayload(): mixed
68-
{
69-
return $this->payload;
70-
}
71-
72-
public function withPayload(mixed $payload): self
73-
{
74-
return new self($payload);
75-
}
7690
}

src/JsonStreamInterface.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
316
namespace FastForward\Http\Message;
417

518
use Psr\Http\Message\StreamInterface;
619

720
/**
8-
* Interface JsonStreamInterface
21+
* Interface JsonStreamInterface.
922
*
1023
* Extends the PSR-7 StreamInterface to provide additional functionality for JSON payload handling.
1124
* Implementations of this interface MUST support both standard stream operations and structured JSON payload manipulation.
1225
*
1326
* @package FastForward\Http\Message
1427
*/
15-
interface JsonStreamInterface extends StreamInterface, PayloadAwareInterface
16-
{
17-
}
28+
interface JsonStreamInterface extends StreamInterface, PayloadAwareInterface {}

src/PayloadAwareInterface.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<?php
22

3-
namespace FastForward\Http\Message;
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
415

5-
use Psr\Http\Message\StreamInterface;
16+
namespace FastForward\Http\Message;
617

718
/**
8-
* Interface PayloadAwareInterface
19+
* Interface PayloadAwareInterface.
920
*
1021
* Provide functionality for JSON payload handling.
1122
*
@@ -19,7 +30,7 @@ interface PayloadAwareInterface
1930
* This method MUST return the decoded JSON payload as a native PHP type. The returned type MAY vary depending on
2031
* the structure of the JSON content (e.g., array, object, int, float, string, bool, or null).
2132
*
22-
* @return mixed The decoded JSON payload, which MAY be of any type, including array, object, scalar, or null.
33+
* @return mixed the decoded JSON payload, which MAY be of any type, including array, object, scalar, or null
2334
*/
2435
public function getPayload(): mixed;
2536

@@ -33,8 +44,9 @@ public function getPayload(): mixed;
3344
* by the implementation.
3445
*
3546
* @param mixed $payload The data to encode as JSON and set as the stream's payload. This MAY be of any type
36-
* supported by json_encode.
37-
* @return self A new instance with the updated JSON payload.
47+
* supported by json_encode.
48+
*
49+
* @return self a new instance with the updated JSON payload
3850
*/
3951
public function withPayload(mixed $payload): self;
4052
}

src/RequestMethod.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/http-message.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/http-message
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
316
namespace FastForward\Http\Message;
417

518
/**
6-
* Enum RequestMethod
19+
* Enum RequestMethod.
720
*
821
* Represents the set of valid HTTP request methods as defined by the IETF RFC 7231 and related specifications.
922
* This enum SHALL be used to strictly define supported request methods within HTTP client and server implementations.
@@ -48,31 +61,25 @@ enum RequestMethod: string
4861

4962
/**
5063
* Returns true if the method is considered safe (does not modify server state).
51-
*
52-
* @return bool
5364
*/
5465
public function isSafe(): bool
5566
{
56-
return in_array($this, [self::Get, self::Head, self::Options, self::Trace], true);
67+
return \in_array($this, [self::Get, self::Head, self::Options, self::Trace], true);
5768
}
5869

5970
/**
6071
* Returns true if the method is idempotent (multiple identical requests have the same effect as a single one).
61-
*
62-
* @return bool
6372
*/
6473
public function isIdempotent(): bool
6574
{
66-
return in_array($this, [self::Get, self::Head, self::Put, self::Delete, self::Options, self::Trace], true);
75+
return \in_array($this, [self::Get, self::Head, self::Put, self::Delete, self::Options, self::Trace], true);
6776
}
6877

6978
/**
7079
* Returns true if the method is considered cacheable by default.
71-
*
72-
* @return bool
7380
*/
7481
public function isCacheable(): bool
7582
{
76-
return in_array($this, [self::Get, self::Head], true);
83+
return \in_array($this, [self::Get, self::Head], true);
7784
}
7885
}

0 commit comments

Comments
 (0)