Skip to content

Commit

Permalink
feat: upgrade to PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien committed Jan 4, 2024
1 parent 3e6bc2c commit 993384d
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
tools: composer:v2
coverage: none
- name: Install PHP dependencies
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '8.1', '8.2', '8.3' ]
name: Tests on PHP ${{ matrix.php }}
steps:
- name: Checkout source code
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ bash: ## Start a bash process in a PHP 7.4 Docker container
docker run --rm -it \
-e PHP_EXTENSION_XDEBUG=1 \
-v $(PWD):/usr/src/app/ \
thecodingmachine/php:7.4-v4-cli \
thecodingmachine/php:8.1-v4-cli \
bash
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
],
"require": {
"php": "^7.4|^8.0|^8.1|^8.2|^8.3",
"php": "^8.1|^8.2|^8.3",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/psr7": "^1 || ^2.1",
Expand All @@ -42,9 +42,9 @@
"psr/http-message": "^1.0|^2.0"
},
"require-dev": {
"doctrine/coding-standard": "^9.0",
"pestphp/pest": "^1.21",
"phpstan/phpstan": "^1.2",
"doctrine/coding-standard": "^12.0",
"pestphp/pest": "^2.28",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
parameters:
ignoreErrors:
-
message: '#Call to an undefined method Pest\\Expectation\|Pest\\Support\\Extendable#'
message: '#Call to an undefined method Pest\\Expectation<string\|null>::toContainFormValue\(\).#'
path: tests/*
-
message: '#Call to an undefined method Pest\\Expectation<mixed>::toContainFormValue\(\).#'
message: '#Call to an undefined method Pest\\Expectation<string\|null>::toContainFormFile\(\).#'
path: tests/*
-
message: '#Undefined variable: \$this#'
Expand Down
2 changes: 1 addition & 1 deletion src/ApiModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function trace(string $trace, string $header = 'Gotenberg-Trace'): self
return $this;
}

protected function request(string $method, ?StreamInterface $body = null): RequestInterface
protected function request(string $method, StreamInterface|null $body = null): RequestInterface
{
$request = Psr17FactoryDiscovery::findRequestFactory()
->createRequest($method, $this->url . $this->endpoint);
Expand Down
4 changes: 2 additions & 2 deletions src/Gotenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function pdfEngines(string $baseUrl): PdfEngines
*
* @throws GotenbergApiErroed
*/
public static function send(RequestInterface $request, ?ClientInterface $client = null): ResponseInterface
public static function send(RequestInterface $request, ClientInterface|null $client = null): ResponseInterface
{
$client = $client ?: Psr18ClientDiscovery::find();
$response = $client->sendRequest($request);
Expand All @@ -66,7 +66,7 @@ public static function send(RequestInterface $request, ?ClientInterface $client
* @throws NoOutputFileInResponse
* @throws NativeFunctionErroed
*/
public static function save(RequestInterface $request, string $dirPath, ?ClientInterface $client = null): string
public static function save(RequestInterface $request, string $dirPath, ClientInterface|null $client = null): string
{
$response = self::send($request, $client);

Expand Down
4 changes: 2 additions & 2 deletions src/Modules/LibreOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class LibreOffice
{
use MultipartFormDataModule;

private ?Index $index = null;
private bool $merge = false;
private Index|null $index = null;
private bool $merge = false;

/**
* Overrides the default index generator for ordering
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/PdfEngines.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PdfEngines
{
use MultipartFormDataModule;

private ?Index $index = null;
private Index|null $index = null;

/**
* Overrides the default index generator for ordering
Expand Down
5 changes: 1 addition & 4 deletions src/MultipartFormDataModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ public function webhookExtraHttpHeaders(array $headers): self
return $this;
}

/**
* @param mixed $value
*/
public function formValue(string $name, $value): self
protected function formValue(string $name, mixed $value): self
{
$this->multipartFormData[] = [
'name' => $name,
Expand Down
9 changes: 2 additions & 7 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

class Stream
{
private string $filename;
private StreamInterface $stream;

public static function path(string $path, ?string $filename = null): self
public static function path(string $path, string|null $filename = null): self
{
$filename ??= basename($path);

Expand All @@ -40,10 +37,8 @@ public static function string(string $filename, string $str): self
return new self($filename, Utils::streamFor($inmemory));
}

public function __construct(string $filename, StreamInterface $stream)
public function __construct(private string $filename, private StreamInterface $stream)
{
$this->filename = $filename;
$this->stream = $stream;
}

public function getFilename(): string
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ function (): void {

expect($dummy->getUrl())->toBe('https://my.url');
expect($request->getHeader('Gotenberg-Trace'))->toMatchArray(['debug']);
}
},
);
5 changes: 1 addition & 4 deletions tests/DummyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

class DummyClient implements ClientInterface
{
private ResponseInterface $response;

public function __construct(ResponseInterface $response)
public function __construct(private readonly ResponseInterface $response)
{
$this->response = $response;
}

public function sendRequest(RequestInterface $request): ResponseInterface
Expand Down
18 changes: 9 additions & 9 deletions tests/GotenbergTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function (): void {
$response = Gotenberg::send(new Request('POST', 'https://my.url'), $client);

expect($response)->not()->toBeNull();
}
},
);

it(
Expand All @@ -37,10 +37,10 @@ function (bool $withTrace): void {

throw $e;
}
}
},
)->with([
true,
false,
'with trace' => [ true ],
'without trace' => [ false ],
])->throws(GotenbergApiErroed::class);

it(
Expand All @@ -53,18 +53,18 @@ function (): void {

expect(unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'my.pdf'))->toBeTrue();
expect($filename)->toEqual('my.pdf');
}
},
);

it(
'throws an exception if there is no attachment',
function (?string $contentDisposition): void {
function (string|null $contentDisposition): void {
$response = new Response(200, $contentDisposition === null ? [] : ['Content-Disposition' => $contentDisposition]);
$client = new DummyClient($response);

Gotenberg::save(new Request('POST', 'https://my.url'), sys_get_temp_dir(), $client);
}
},
)->with([
null,
'no attachment',
'without content disposition' => [ null ],
'with content disposition' => [ 'no attachment' ],
])->throws(NoOutputFileInResponse::class);
2 changes: 1 addition & 1 deletion tests/HrtimeIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ function (): void {
$result = $indexes[$i] > $indexes[$i - 1];
expect($result)->toBeTrue();
}
}
},
);

0 comments on commit 993384d

Please sign in to comment.