Skip to content

Commit

Permalink
Phpstan level8 (#3)
Browse files Browse the repository at this point in the history
* Bump to 8, fix cast for origin

* Check origin

* Explicit cast
  • Loading branch information
barryvdh authored Feb 19, 2022
1 parent 277ac8d commit ed3e621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"scripts": {
"test": "phpunit",
"analyse": "phpstan analyse src tests --level=7",
"analyse": "phpstan analyse src tests --level=8",
"check-style": "phpcs -p --standard=PSR12 --exclude=Generic.Files.LineLength --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR12 --exclude=Generic.Files.LineLength --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
},
Expand Down
9 changes: 6 additions & 3 deletions src/CorsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ public function isOriginAllowed(Request $request): bool

$origin = $request->headers->get('Origin');

if ($origin === null) {
return false;
}

if (in_array($origin, $this->options['allowedOrigins'])) {
return true;
}

/** @var string $pattern */
foreach ($this->options['allowedOriginsPatterns'] as $pattern) {
if (preg_match($pattern, $origin)) {
return true;
Expand Down Expand Up @@ -219,7 +222,7 @@ private function configureAllowedOrigin(Response $response, Request $request): v
} else {
// For dynamic headers, set the requested Origin header when set and allowed
if ($this->isCorsRequest($request) && $this->isOriginAllowed($request)) {
$response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin'));
$response->headers->set('Access-Control-Allow-Origin', (string) $request->headers->get('Origin'));
}

$this->varyHeader($response, 'Origin');
Expand Down Expand Up @@ -250,7 +253,7 @@ private function configureAllowedMethods(Response $response, Request $request):
private function configureAllowedHeaders(Response $response, Request $request): void
{
if ($this->options['allowAllHeaders'] === true) {
$allowHeaders = $request->headers->get('Access-Control-Request-Headers');
$allowHeaders = (string) $request->headers->get('Access-Control-Request-Headers');
$this->varyHeader($response, 'Access-Control-Request-Headers');
} else {
$allowHeaders = implode(', ', $this->options['allowedHeaders']);
Expand Down

0 comments on commit ed3e621

Please sign in to comment.