Skip to content

Upgrades, min PHP 7.4 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 15, 2025
Merged
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
use nix
watch_file flake.nix flake.lock
14 changes: 7 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ env:

jobs:
tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
matrix:
php:
- '8.4'
- '8.3'
- '8.2'
- '8.1'
- '8.0'
- '7.4'
- '7.3'
- '7.2'
include:
- php: '7.4'
cs_fixer: true
- php: '8.0'
phpstan: true
name: 'Check with PHP ${{ matrix.php }}'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v20
uses: cachix/install-nix-action@v31

- name: Set up Nix cache
uses: cachix/cachix-action@v12
uses: cachix/cachix-action@v16
with:
# Use cache from https://github.com/fossar/nix-phps
name: fossar
Expand All @@ -46,7 +46,7 @@ jobs:
run: |
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/vendor/
.direnv/
.php-cs-fixer.cache
.phpunit.result.cache
phpstan.neon
17 changes: 12 additions & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
$rules = [
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'phpdoc_to_property_type' => true,
// 'phpdoc_to_param_type' => true,
'phpdoc_to_return_type' => true,
// 'phpdoc_to_return_type' => true,
'phpdoc_types_order' => false,

// overwrite some Symfony rules
'braces' => ['position_after_functions_and_oop_constructs' => 'same'],
'function_declaration' => ['closure_function_spacing' => 'none'],
'braces_position' => [
'functions_opening_brace' => 'same_line',
'classes_opening_brace' => 'same_line',
],
'function_declaration' => [
'closure_function_spacing' => 'none',
'closure_fn_spacing' => 'none',
],
'concat_space' => ['spacing' => 'one'],
'phpdoc_align' => false,
'yoda_style' => false,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# guzzle-transcoder changes

## 0.3.1 – 2025-03-15
- Raise minimum PHP version to 7.4.0.

## 0.3.0 – 2023-03-06
- Raise minimum PHP version to 7.2.5.
- Add support for fossar/transcoder 2.0.
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"description": "Guzzle plugin that converts responses to UTF-8",
"type": "library",
"require": {
"php": ">=7.2.5",
"php": ">=7.4.0",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"fossar/transcoder": "^1.0 || ^2.0",
"fossar/transcoder": "^1.0 || ^2.0 || ^3.0",
"guzzlehttp/psr7": "^1.7 || ^2.0"
},
"require-dev" : {
"friendsofphp/php-cs-fixer": "^3.0",
"php-parallel-lint/php-parallel-lint": "^1.0",
"symfony/phpunit-bridge": "^6.2"
"symfony/phpunit-bridge": "^6.2 || ^7.0",
"phpstan/phpstan": "^2.1"
},
"autoload": {
"psr-4": { "Fossar\\GuzzleTranscoder\\": "src/" }
Expand All @@ -28,7 +29,7 @@
],
"config": {
"platform": {
"php": "7.2.5"
"php": "7.4.0"
}
},
"scripts": {
Expand Down
42 changes: 30 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# Composer and PHP.
php
php.packages.composer
php.packages.phpstan
pkgs.phpactor
];
};
};
Expand Down
File renamed without changes.
23 changes: 9 additions & 14 deletions src/GuzzleTranscoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
use Psr\Http\Message\ResponseInterface;

class GuzzleTranscoder {
/** @var ?TranscoderInterface */
private $transcoder;
private ?TranscoderInterface $transcoder;

/** @var string */
private $targetEncoding;
private string $targetEncoding;

/** @var bool */
private $replaceHeaders;
private bool $replaceHeaders;

/** @var bool */
private $replaceContent;
private bool $replaceContent;

/**
* Constructs a class for transcoding Responses.
Expand Down Expand Up @@ -56,7 +52,7 @@ private function createTranscoder(): TranscoderInterface {
public function convert(ResponseInterface $response): ResponseInterface {
$stream = $response->getBody();

/** @var array<string, string[]> */
/** @var array<string, list<string>> */
$headers = $response->getHeaders();
$result = $this->convertResponse($headers, (string) $stream);
if ($result !== null) {
Expand All @@ -81,11 +77,10 @@ public function convert(ResponseInterface $response): ResponseInterface {
*/
public function __invoke(callable $handler): callable {
return function(RequestInterface $request, array $options) use ($handler): PromiseInterface {
/** @var array<string, mixed> $options */
$promise = $handler($request, $options);

return $promise->then(function(ResponseInterface $response): ResponseInterface {
return $this->convert($response);
});
return $promise->then(fn(ResponseInterface $response): ResponseInterface => $this->convert($response));
};
}

Expand All @@ -100,9 +95,9 @@ public function __invoke(callable $handler): callable {
*
* Otherwise an array containing the new headers and content is returned.
*
* @param array<string, string[]> $headers
* @param array<string, list<string>> $headers
*
* @return ?array{headers: array<string, string[]>, content: string}
* @return ?array{headers: array<string, list<string>>, content: string}
*/
public function convertResponse(array $headers, string $content): ?array {
$headerDeclaredEncoding = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Utils {
* [Basic=>null, realm=>'"foo\bar"']
* ["</TheBook/chapter,2>" => null, "rel" => "pre,vious", "title*" => "UTF-8'de'letztes%20Kapitel" ], ["</TheBook/chapter4>" => null, "rel" => "next", "title*" => "UTF-8'de'n%c3%a4chstes%20Kapitel" ]
*
* @param string[]|string $headerValues
* @param list<string>|string $headerValues
*
* @throws \Exception
*
Expand Down Expand Up @@ -174,7 +174,7 @@ public static function joinHttpHeaderWords(array $headerValues): string {
}
/** @var array<array<string, ?string>> $headerValues */
$spaces = '\\s';
$ctls = '\\x00-\\x1F\\x7F'; //@see http://stackoverflow.com/a/1497928/413531
$ctls = '\\x00-\\x1F\\x7F'; // @see http://stackoverflow.com/a/1497928/413531
$tspecials = '()<>@,;:<>/[\\]?.="\\\\';
$tokenPattern = "#^[^{$spaces}{$ctls}{$tspecials}]+$#";
$result = [];
Expand Down
Loading