Skip to content

Commit 11196f1

Browse files
chore: fix static analysis, test with PHP 8.5
1 parent 79cdb57 commit 11196f1

14 files changed

Lines changed: 416 additions & 426 deletions

File tree

.github/workflows/code-analysis.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
13+
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1414

1515
steps:
1616
- uses: actions/checkout@v4
1717

1818
- uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: ${{ matrix.php-versions }}
21-
tools: composer, php-cs-fixer, phpstan, phpunit
21+
tools: composer, php-cs-fixer, phpstan, phpunit:9.6
2222

2323
- run: composer install --prefer-dist --no-progress
2424

.php-cs-fixer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
;
66

77
return (new PhpCsFixer\Config())
8+
->setUnsupportedPhpVersionAllowed(true)
89
->setRules([
910
'@Symfony' => true,
11+
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']],
1012
])
1113
->setFinder($finder)
1214
;

examples/async-upload/index.php

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
<?php
22

3-
require_once __DIR__ . "/../../vendor/autoload.php";
3+
require_once __DIR__.'/../../vendor/autoload.php';
44

55
use Bunny\Storage\Client;
66
use Bunny\Storage\Region;
77
use GuzzleHttp\Promise\Utils;
88

9-
$apiKey = getenv("BUNNY_STORAGE_API_KEY");
10-
$storageZone = getenv("BUNNY_STORAGE_ZONE");
11-
$region = getenv("BUNNY_STORAGE_REGION") ?: "de";
9+
$apiKey = getenv('BUNNY_STORAGE_API_KEY');
10+
$storageZone = getenv('BUNNY_STORAGE_ZONE');
11+
$region = getenv('BUNNY_STORAGE_REGION') ?: 'de';
1212

1313
if (!$apiKey || !$storageZone) {
14-
header("Content-Type: application/json");
14+
header('Content-Type: application/json');
1515
echo json_encode(
1616
[
17-
"error" =>
18-
"BUNNY_STORAGE_API_KEY and BUNNY_STORAGE_ZONE environment variables are required.",
17+
'error' => 'BUNNY_STORAGE_API_KEY and BUNNY_STORAGE_ZONE environment variables are required.',
1918
],
2019
JSON_PRETTY_PRINT,
2120
);
2221
exit(1);
2322
}
2423

2524
$regionMap = [
26-
"de" => Region::FALKENSTEIN,
27-
"uk" => Region::LONDON,
28-
"se" => Region::STOCKHOLM,
29-
"ny" => Region::NEW_YORK,
30-
"la" => Region::LOS_ANGELES,
31-
"sg" => Region::SINGAPORE,
32-
"syd" => Region::SYDNEY,
33-
"br" => Region::SAO_PAULO,
34-
"jh" => Region::JOHANNESBURG,
25+
'de' => Region::FALKENSTEIN,
26+
'uk' => Region::LONDON,
27+
'se' => Region::STOCKHOLM,
28+
'ny' => Region::NEW_YORK,
29+
'la' => Region::LOS_ANGELES,
30+
'sg' => Region::SINGAPORE,
31+
'syd' => Region::SYDNEY,
32+
'br' => Region::SAO_PAULO,
33+
'jh' => Region::JOHANNESBURG,
3534
];
3635

3736
$regionConstant = $regionMap[$region] ?? Region::FALKENSTEIN;
3837

39-
$localDirectory = __DIR__ . "/files";
38+
$localDirectory = __DIR__.'/files';
4039

4140
if (!is_dir($localDirectory)) {
4241
mkdir($localDirectory, 0755, true);
4342

44-
for ($i = 1; $i <= 5; $i++) {
43+
for ($i = 1; $i <= 5; ++$i) {
4544
$content = str_repeat("This is sample file {$i}. ", 100 * $i);
4645
file_put_contents("{$localDirectory}/async-sample{$i}.txt", $content);
4746
}
@@ -51,13 +50,13 @@
5150
$client = new Client($apiKey, $storageZone, $regionConstant);
5251

5352
$files = glob("{$localDirectory}/*");
54-
$files = array_filter($files, "is_file");
53+
$files = array_filter($files, 'is_file');
5554

5655
if (empty($files)) {
57-
header("Content-Type: application/json");
56+
header('Content-Type: application/json');
5857
echo json_encode(
5958
[
60-
"error" => "No files found in '{$localDirectory}'. Add some files to the 'files/' directory and run again.",
59+
'error' => "No files found in '{$localDirectory}'. Add some files to the 'files/' directory and run again.",
6160
],
6261
JSON_PRETTY_PRINT,
6362
);
@@ -91,53 +90,53 @@
9190
$fileName = basename($remotePath);
9291
$localPath = array_search($remotePath, $uploadMap);
9392

94-
if ($result["state"] === "fulfilled") {
93+
if ('fulfilled' === $result['state']) {
9594
$results[] = [
96-
"file" => $fileName,
97-
"size" => filesize($localPath),
98-
"status" => "success",
95+
'file' => $fileName,
96+
'size' => filesize($localPath),
97+
'status' => 'success',
9998
];
100-
$successful++;
99+
++$successful;
101100
} else {
102101
$results[] = [
103-
"file" => $fileName,
104-
"size" => filesize($localPath),
105-
"status" => "failed",
106-
"error" => $result["reason"]->getMessage(),
102+
'file' => $fileName,
103+
'size' => filesize($localPath),
104+
'status' => 'failed',
105+
'error' => $result['reason']->getMessage(),
107106
];
108-
$failed++;
107+
++$failed;
109108
}
110109
}
111110

112-
$uploadedFiles = $client->listFiles("async/");
111+
$uploadedFiles = $client->listFiles('async/');
113112
$uploadedList = array_map(
114-
fn($file) => [
115-
"name" => $file->getName(),
116-
"size" => $file->getSize(),
117-
"isDirectory" => $file->isDirectory(),
118-
"dateModified" => $file->getDateModified()->format("c"),
113+
fn ($file) => [
114+
'name' => $file->getName(),
115+
'size' => $file->getSize(),
116+
'isDirectory' => $file->isDirectory(),
117+
'dateModified' => $file->getDateModified()->format('c'),
119118
],
120-
array_filter($uploadedFiles, fn($file) => !$file->isDirectory()),
119+
array_filter($uploadedFiles, fn ($file) => !$file->isDirectory()),
121120
);
122121

123-
header("Content-Type: application/json");
122+
header('Content-Type: application/json');
124123
echo json_encode(
125124
[
126-
"storageZone" => $storageZone,
127-
"region" => $region,
128-
"summary" => [
129-
"successful" => $successful,
130-
"failed" => $failed,
131-
"total" => count($files),
132-
"durationSeconds" => $asyncDuration,
125+
'storageZone' => $storageZone,
126+
'region' => $region,
127+
'summary' => [
128+
'successful' => $successful,
129+
'failed' => $failed,
130+
'total' => count($files),
131+
'durationSeconds' => $asyncDuration,
133132
],
134-
"results" => $results,
135-
"uploadedFiles" => array_values($uploadedList),
133+
'results' => $results,
134+
'uploadedFiles' => array_values($uploadedList),
136135
],
137136
JSON_PRETTY_PRINT,
138137
);
139138
} catch (Exception $e) {
140-
header("Content-Type: application/json");
141-
echo json_encode(["error" => $e->getMessage()], JSON_PRETTY_PRINT);
139+
header('Content-Type: application/json');
140+
echo json_encode(['error' => $e->getMessage()], JSON_PRETTY_PRINT);
142141
exit(1);
143142
}

examples/batch-upload/index.php

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,69 @@
11
<?php
22

3-
require_once __DIR__ . "/../../vendor/autoload.php";
3+
require_once __DIR__.'/../../vendor/autoload.php';
44

55
use Bunny\Storage\Client;
66
use Bunny\Storage\Region;
77

8-
$apiKey = getenv("BUNNY_STORAGE_API_KEY");
9-
$storageZone = getenv("BUNNY_STORAGE_ZONE");
10-
$region = getenv("BUNNY_STORAGE_REGION") ?: "de";
8+
$apiKey = getenv('BUNNY_STORAGE_API_KEY');
9+
$storageZone = getenv('BUNNY_STORAGE_ZONE');
10+
$region = getenv('BUNNY_STORAGE_REGION') ?: 'de';
1111

1212
if (!$apiKey || !$storageZone) {
13-
header("Content-Type: application/json");
13+
header('Content-Type: application/json');
1414
echo json_encode(
1515
[
16-
"error" =>
17-
"BUNNY_STORAGE_API_KEY and BUNNY_STORAGE_ZONE environment variables are required.",
16+
'error' => 'BUNNY_STORAGE_API_KEY and BUNNY_STORAGE_ZONE environment variables are required.',
1817
],
1918
JSON_PRETTY_PRINT,
2019
);
2120
exit(1);
2221
}
2322

2423
$regionMap = [
25-
"de" => Region::FALKENSTEIN,
26-
"uk" => Region::LONDON,
27-
"se" => Region::STOCKHOLM,
28-
"ny" => Region::NEW_YORK,
29-
"la" => Region::LOS_ANGELES,
30-
"sg" => Region::SINGAPORE,
31-
"syd" => Region::SYDNEY,
32-
"br" => Region::SAO_PAULO,
33-
"jh" => Region::JOHANNESBURG,
24+
'de' => Region::FALKENSTEIN,
25+
'uk' => Region::LONDON,
26+
'se' => Region::STOCKHOLM,
27+
'ny' => Region::NEW_YORK,
28+
'la' => Region::LOS_ANGELES,
29+
'sg' => Region::SINGAPORE,
30+
'syd' => Region::SYDNEY,
31+
'br' => Region::SAO_PAULO,
32+
'jh' => Region::JOHANNESBURG,
3433
];
3534

3635
$regionConstant = $regionMap[$region] ?? Region::FALKENSTEIN;
3736

38-
$localDirectory = __DIR__ . "/files";
37+
$localDirectory = __DIR__.'/files';
3938

4039
if (!is_dir($localDirectory)) {
4140
mkdir($localDirectory, 0755, true);
4241

4342
file_put_contents(
4443
"{$localDirectory}/sample1.txt",
45-
"This is sample file 1. Created at: " . date("Y-m-d H:i:s"),
44+
'This is sample file 1. Created at: '.date('Y-m-d H:i:s'),
4645
);
4746
file_put_contents(
4847
"{$localDirectory}/sample2.txt",
49-
"This is sample file 2. Created at: " . date("Y-m-d H:i:s"),
48+
'This is sample file 2. Created at: '.date('Y-m-d H:i:s'),
5049
);
5150
file_put_contents(
5251
"{$localDirectory}/sample3.txt",
53-
"This is sample file 3. Created at: " . date("Y-m-d H:i:s"),
52+
'This is sample file 3. Created at: '.date('Y-m-d H:i:s'),
5453
);
5554
}
5655

5756
try {
5857
$client = new Client($apiKey, $storageZone, $regionConstant);
5958

6059
$files = glob("{$localDirectory}/*");
61-
$files = array_filter($files, "is_file");
60+
$files = array_filter($files, 'is_file');
6261

6362
if (empty($files)) {
64-
header("Content-Type: application/json");
63+
header('Content-Type: application/json');
6564
echo json_encode(
6665
[
67-
"error" => "No files found in '{$localDirectory}'. Add some files to the 'files/' directory and run again.",
66+
'error' => "No files found in '{$localDirectory}'. Add some files to the 'files/' directory and run again.",
6867
],
6968
JSON_PRETTY_PRINT,
7069
);
@@ -82,50 +81,50 @@
8281
try {
8382
$client->upload($file, $remotePath);
8483
$results[] = [
85-
"file" => $fileName,
86-
"size" => filesize($file),
87-
"status" => "success",
84+
'file' => $fileName,
85+
'size' => filesize($file),
86+
'status' => 'success',
8887
];
89-
$successful++;
88+
++$successful;
9089
} catch (Exception $e) {
9190
$results[] = [
92-
"file" => $fileName,
93-
"size" => filesize($file),
94-
"status" => "failed",
95-
"error" => $e->getMessage(),
91+
'file' => $fileName,
92+
'size' => filesize($file),
93+
'status' => 'failed',
94+
'error' => $e->getMessage(),
9695
];
97-
$failed++;
96+
++$failed;
9897
}
9998
}
10099

101-
$uploadedFiles = $client->listFiles("batch/");
100+
$uploadedFiles = $client->listFiles('batch/');
102101
$uploadedList = array_map(
103-
fn($file) => [
104-
"name" => $file->getName(),
105-
"size" => $file->getSize(),
106-
"isDirectory" => $file->isDirectory(),
107-
"dateModified" => $file->getDateModified()->format("c"),
102+
fn ($file) => [
103+
'name' => $file->getName(),
104+
'size' => $file->getSize(),
105+
'isDirectory' => $file->isDirectory(),
106+
'dateModified' => $file->getDateModified()->format('c'),
108107
],
109-
array_filter($uploadedFiles, fn($file) => !$file->isDirectory()),
108+
array_filter($uploadedFiles, fn ($file) => !$file->isDirectory()),
110109
);
111110

112-
header("Content-Type: application/json");
111+
header('Content-Type: application/json');
113112
echo json_encode(
114113
[
115-
"storageZone" => $storageZone,
116-
"region" => $region,
117-
"summary" => [
118-
"successful" => $successful,
119-
"failed" => $failed,
120-
"total" => count($files),
114+
'storageZone' => $storageZone,
115+
'region' => $region,
116+
'summary' => [
117+
'successful' => $successful,
118+
'failed' => $failed,
119+
'total' => count($files),
121120
],
122-
"results" => $results,
123-
"uploadedFiles" => array_values($uploadedList),
121+
'results' => $results,
122+
'uploadedFiles' => array_values($uploadedList),
124123
],
125124
JSON_PRETTY_PRINT,
126125
);
127126
} catch (Exception $e) {
128-
header("Content-Type: application/json");
129-
echo json_encode(["error" => $e->getMessage()], JSON_PRETTY_PRINT);
127+
header('Content-Type: application/json');
128+
echo json_encode(['error' => $e->getMessage()], JSON_PRETTY_PRINT);
130129
exit(1);
131130
}

0 commit comments

Comments
 (0)