Skip to content

Commit 427a3e8

Browse files
authored
Merge pull request #10 from fruitcake/feat-php74plus
Drop support for legacy versions
2 parents 507d1de + 4632212 commit 427a3e8

File tree

5 files changed

+24
-50
lines changed

5 files changed

+24
-50
lines changed

.github/workflows/run-coverage.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ jobs:
1010
php-tests:
1111
runs-on: ubuntu-latest
1212

13-
strategy:
14-
matrix:
15-
php: [8.1]
16-
1713
name: PHP Code Coverage
1814

1915
steps:

.github/workflows/run-tests.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php: [7.2, 7.3, 7.4, 8.0, 8.1]
16-
symfony: [4.x, 5.x, 6.x]
15+
php: [7.4, 8.0, 8.1]
16+
symfony: [^4.4, ^5.4, ^6]
1717
dependency-version: [prefer-lowest, prefer-stable]
1818
os: [ubuntu-latest]
1919
exclude:
20-
- symfony: 6.x
21-
php: 7.2
22-
- symfony: 6.x
23-
php: 7.3
24-
- symfony: 6.x
20+
- symfony: ^6
2521
php: 7.4
2622

2723
name: PHP${{ matrix.php }} Symfony${{ matrix.symfony }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
@@ -49,7 +45,7 @@ jobs:
4945

5046
- name: Analyse with PHPStan
5147
run: composer analyse
52-
if: matrix.os == 'ubuntu-latest' && matrix.symfony != '4.x'
48+
if: matrix.os == 'ubuntu-latest' && matrix.symfony != '^4.4'
5349

5450
- name: Check PSR-12 Codestyle
5551
run: composer test

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
"type": "library",
77
"license": "MIT",
88
"authors": [
9+
{
10+
"name": "Fruitcake",
11+
"homepage": "https://fruitcake.nl"
12+
},
913
{
1014
"name": "Barryvdh",
1115
"email": "barryvdh@gmail.com"
1216
}
1317
],
1418
"require": {
15-
"php": "^7.2|^8.0",
16-
"symfony/http-foundation": "^4|^5|^6"
19+
"php": "^7.4|^8.0",
20+
"symfony/http-foundation": "^4.4|^5.4|^6"
1721
},
1822
"require-dev": {
19-
"phpunit/phpunit": "^7|^9",
23+
"phpunit/phpunit": "^9",
2024
"squizlabs/php_codesniffer": "^3.5",
2125
"phpstan/phpstan": "^1.4"
2226
},

src/CorsService.php

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,21 @@
3838
class CorsService
3939
{
4040
/** @var string[] */
41-
private $allowedOrigins = [];
41+
private array $allowedOrigins = [];
4242
/** @var string[] */
43-
private $allowedOriginsPatterns = [];
43+
private array $allowedOriginsPatterns = [];
4444
/** @var string[] */
45-
private $allowedMethods = [];
45+
private array $allowedMethods = [];
4646
/** @var string[] */
47-
private $allowedHeaders = [];
47+
private array $allowedHeaders = [];
4848
/** @var string[] */
49-
private $exposedHeaders = [];
50-
/** @var bool */
51-
private $supportsCredentials = false;
52-
/** @var null|int */
53-
private $maxAge = 0;
54-
55-
/** @var bool */
56-
private $allowAllOrigins = false;
57-
/** @var bool */
58-
private $allowAllMethods = false;
59-
/** @var bool */
60-
private $allowAllHeaders = false;
49+
private array $exposedHeaders = [];
50+
private bool $supportsCredentials = false;
51+
private ?int $maxAge = 0;
52+
53+
private bool $allowAllOrigins = false;
54+
private bool $allowAllMethods = false;
55+
private bool $allowAllHeaders = false;
6156

6257
/**
6358
* @param CorsInputOptions $options
@@ -93,26 +88,9 @@ public function setOptions(array $options): void
9388
$exposedHeaders = $options['exposedHeaders'] ?? $options['exposed_headers'] ?? $this->exposedHeaders;
9489
$this->exposedHeaders = $exposedHeaders === false ? [] : $exposedHeaders;
9590

96-
$this->validateOptions();
9791
$this->normalizeOptions();
9892
}
9993

100-
private function validateOptions(): void
101-
{
102-
$arrayHeaders = [
103-
'allowedOrigins',
104-
'allowedOriginsPatterns',
105-
'allowedHeaders',
106-
'allowedMethods',
107-
'exposedHeaders',
108-
];
109-
foreach ($arrayHeaders as $key) {
110-
if (!is_array($this->{$key})) {
111-
throw new InvalidOptionException("CORS option `{$key}` should be an array");
112-
}
113-
}
114-
}
115-
11694
private function normalizeOptions(): void
11795
{
11896
// Normalize case

tests/CorsServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function itAllowsZeroMaxAge(): void
201201
*/
202202
public function itThrowsExceptionOnInvalidExposedHeaders(): void
203203
{
204-
$this->expectException(InvalidOptionException::class);
204+
$this->expectException(\TypeError::class);
205205

206206
/** @phpstan-ignore-next-line */
207207
$service = new CorsService(['exposedHeaders' => true]);
@@ -212,7 +212,7 @@ public function itThrowsExceptionOnInvalidExposedHeaders(): void
212212
*/
213213
public function itThrowsExceptionOnInvalidOriginsArray(): void
214214
{
215-
$this->expectException(InvalidOptionException::class);
215+
$this->expectException(\TypeError::class);
216216

217217
/** @phpstan-ignore-next-line */
218218
$service = new CorsService(['allowedOrigins' => 'string']);

0 commit comments

Comments
 (0)