Skip to content

Commit

Permalink
Add typehints (#78)
Browse files Browse the repository at this point in the history
* Add typehints
  • Loading branch information
barryvdh authored Apr 20, 2020
1 parent 638b45a commit 1913589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src"
"check-style": "phpcs -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src",
"fix-style": "phpcbf -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src"
},
"extra": {
"branch-alias": {
Expand Down
22 changes: 11 additions & 11 deletions src/CorsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(array $options = array())
$this->options = $this->normalizeOptions($options);
}

private function normalizeOptions(array $options = array())
private function normalizeOptions(array $options = array()): array
{
$options += array(
'allowedOrigins' => array(),
Expand Down Expand Up @@ -57,22 +57,22 @@ private function normalizeOptions(array $options = array())
/**
* @deprecated use isOriginAllowed
*/
public function isActualRequestAllowed(Request $request)
public function isActualRequestAllowed(Request $request): bool
{
return $this->isOriginAllowed($request);
}

public function isCorsRequest(Request $request)
public function isCorsRequest(Request $request): bool
{
return $request->headers->has('Origin') && !$this->isSameHost($request);
}

public function isPreflightRequest(Request $request)
public function isPreflightRequest(Request $request): bool
{
return $request->getMethod() === 'OPTIONS' && $request->headers->has('Access-Control-Request-Method');
}

public function handlePreflightRequest(Request $request)
public function handlePreflightRequest(Request $request): Response
{
$response = new Response();

Expand All @@ -81,7 +81,7 @@ public function handlePreflightRequest(Request $request)
return $this->addPreflightRequestHeaders($response, $request);
}

public function addPreflightRequestHeaders(Response $response, Request $request)
public function addPreflightRequestHeaders(Response $response, Request $request): Response
{
$this->configureAllowedOrigin($response, $request);

Expand All @@ -98,7 +98,7 @@ public function addPreflightRequestHeaders(Response $response, Request $request)
return $response;
}

public function isOriginAllowed(Request $request)
public function isOriginAllowed(Request $request): bool
{
if ($this->options['allowedOrigins'] === true) {
return true;
Expand All @@ -123,7 +123,7 @@ public function isOriginAllowed(Request $request)
return false;
}

public function addActualRequestHeaders(Response $response, Request $request)
public function addActualRequestHeaders(Response $response, Request $request): Response
{
$this->configureAllowedOrigin($response, $request);

Expand Down Expand Up @@ -154,7 +154,7 @@ private function configureAllowedOrigin(Response $response, Request $request)
}
}

private function isSingleOriginAllowed()
private function isSingleOriginAllowed(): bool
{
if ($this->options['allowedOrigins'] === true || !empty($this->options['allowedOriginsPatterns'])) {
return false;
Expand Down Expand Up @@ -215,7 +215,7 @@ private function configureMaxAge(Response $response, Request $request)
}
}

public function varyHeader(Response $response, $header)
public function varyHeader(Response $response, $header): Response
{
if (!$response->headers->has('Vary')) {
$response->headers->set('Vary', $header);
Expand All @@ -226,7 +226,7 @@ public function varyHeader(Response $response, $header)
return $response;
}

private function isSameHost(Request $request)
private function isSameHost(Request $request): bool
{
return $request->headers->get('Origin') === $request->getSchemeAndHttpHost();
}
Expand Down

0 comments on commit 1913589

Please sign in to comment.