CSP: Minor cleanup in ContentSecurityPolicy.php

Cleanups include;
- Remove elseif() path for cases where if has a return state
  and instead convert the elseif() into an if.
- Fix PHPDoc for non-existent parameter. Corrected parameter
  name.
- Add @throws phpdoc annotation for a method that could throw
  an exception.
- Remove unnecessary parentheses.
- Make sure line doesn't exceed 100 characters.

Change-Id: Ic2d882ae0c6f3859b5a268b1bfb50c8eafa294d9
This commit is contained in:
Derick Alangi 2019-03-20 22:51:56 +01:00
parent e552f30253
commit 2fbc97e375

View file

@ -98,11 +98,14 @@ class ContentSecurityPolicy {
*
* @param int $reportOnly Either self::REPORT_ONLY_MODE or self::FULL_MODE
* @return string Name of http header
* @throws UnexpectedValueException
*/
private function getHeaderName( $reportOnly ) {
if ( $reportOnly === self::REPORT_ONLY_MODE ) {
return 'Content-Security-Policy-Report-Only';
} elseif ( $reportOnly === self::FULL_MODE ) {
}
if ( $reportOnly === self::FULL_MODE ) {
return 'Content-Security-Policy';
}
throw new UnexpectedValueException( $reportOnly );
@ -111,7 +114,8 @@ class ContentSecurityPolicy {
/**
* Determine what CSP policies to set for this page
*
* @param array|bool $config Policy configuration (Either $wgCSPHeader or $wgCSPReportOnlyHeader)
* @param array|bool $policyConfig Policy configuration
* (Either $wgCSPHeader or $wgCSPReportOnlyHeader)
* @param int $mode self::REPORT_ONLY_MODE, self::FULL_MODE
* @return string Policy directives, or empty string for no policy.
*/
@ -152,8 +156,8 @@ class ContentSecurityPolicy {
}
}
// Note: default on if unspecified.
if ( ( !isset( $policyConfig['unsafeFallback'] )
|| $policyConfig['unsafeFallback'] )
if ( !isset( $policyConfig['unsafeFallback'] )
|| $policyConfig['unsafeFallback']
) {
// unsafe-inline should be ignored on browsers
// that support 'nonce-foo' sources.